Add an annotation into a specified page.
Specifies target page.
Annotation's json object.
window.addAnnot = async () => {
let result = [];
let tmp= '';
let tests = [
{
annotJson:{
type:'caret', title:"title", subject:"caret", contents:'contents', name:'name', intent:"testintent",
opacity:0.75, color:0xff0000, flags:0, rect:{left:50,right:100,top:800,bottom:750},
borderInfo:{
width:4, style:0, cloudIntensity:1, dashPhase:1, dashes:[2,7],
},
},
object:"caret",
},
{
annotJson:{
type:'highlight', title:"title", subject:"highlight", contents:'contents', name:'name',
opacity:0.75, color:0xff0000, flags:0, rect:{left:150,right:200,top:800,bottom:750},
},
object:"highlight",
},
{
annotJson:{
type:'squiggly', title:"title", subject:"squiggly", contents:'contents', name:'name',
opacity:0.75, color:0xff0000, flags:0, rect:{left:250,right:300,top:800,bottom:750},
},
object:"squiggly",
},
{
annotJson:{
type:'strikeout', title:"title", subject:"strikeout", contents:'contents', name:'name',
opacity:0.75, color:0xff0000, flags:0, rect:{left:350,right:400,top:800,bottom:750},
},
object:"strikeout",
},
{
annotJson:{
type:'underline', title:"title", subject:"underline", contents:'contents', name:'name',
opacity:0.75, color:0xff0000, flags:0, rect:{left:450,right:500,top:800,bottom:750},
},
object:"underline",
},
{
annotJson:{
type:'freetext', title:"title", subject:"Textbox", contents:'Textbox', name:'Textbox', alignment:0,
opacity:0.75, color:0x0000ff, fillColor:0x00ffff, flags:0,
rect:{left:50,right:100,top:700,bottom:650},
borderInfo:{
width:4, style:0, cloudIntensity:1, dashPhase:1, dashes:[2,7],
},
defaultAppearance:{
textColor:0xfff0f0,
textSize:10,
}
},
object:"freetext-Textbox",
},
{
annotJson:{
intent:"testintent", type:'freetext', title:"title", subject:"Typewriter", contents:'contents', name:'Typewriter',
opacity:0.75, color:0x00ffff, fillColor:0x00ffff, flags:0, rotation:90,
rect:{left:150,right:200,top:700,bottom:650}, alignment:1, intent:'FreeTextTypewriter',
borderInfo:{
width:4, style:0, cloudIntensity:1, dashPhase:1, dashes:[2,7],
},
defaultAppearance:{
textColor:0x0ff0f0,
textSize:10,
}
},
object:"freetext-Typewriter",
},
{
annotJson:{
intent:'FreeTextCallout', type:'freetext', title:"title", subject:"Callout", name:'Callout',
opacity:0.75, color:0xff00ff, fillColor:0x00ffff, flags:0, calloutLineEndingStyle:4,
rect:{left:275,right:300,top:675,bottom:650}, contents:'FreeTextCallout',
calloutLinePoints:[{x:250,y:700},{x:260,y:685},{x:275,y:675}], rotation:180, alignment:2,
borderInfo:{
width:4, style:0, cloudIntensity:1, dashPhase:1, dashes:[2,7],
},
defaultAppearance:{
textColor:0x00f0f0,
textSize:8,
}
},
object:"freetext-Callout",
},
{
annotJson:{
type:'line', title:"title", subject:"line", contents:'contents', name:'name', styleFillColor:0x00ffff,
opacity:1, color:0xffff00, flags:4, rect:{left:350,right:400,top:700,bottom:650},
startPoint:{x:350,y:700}, endPoint:{x:400,y:650}, startStyle:1, endStyle:2, intent:"LineArrow",
borderInfo:{
width:4, style:0, cloudIntensity:1, dashPhase:1, dashes:[2,7],
}
},
object:"line",
},
{
annotJson:{
type:'circle', title:"title", subject:"circle", name:'name', contents:'contents',
opacity:0.75, color:0xffff00, fillColor:0x00ffff, flags:4, rect:{left:450,right:500,top:700,bottom:650},
borderInfo:{
width:6, style:1, cloudIntensity:2, dashPhase:4, dashes:[3,7],
}
},
object:"circle",
},
{
annotJson:{
type:'square', title:"title", subject:"square", name:'name', contents:'contents',
opacity:0.75, color:0xff0000, fillColor:0xff00ff, flags:8, rect:{left:50,right:100,top:600,bottom:550},
borderInfo:{
width:5, style:1, cloudIntensity:2, dashPhase:4, dashes:[3,7],
}
},
object:"square",
},
{
annotJson:{
type:'polygon', title:"title", subject:"polygon", contents:'contents', name:'name', intent:"PolygonCloud",
opacity:1, color:0x00ffff, fillColor:0x00ffff, flags:4,
rect:{left:150,right:200,top:600,bottom:550}, vertexes:[{x:150,y:550},{x:150,y:600},{x:200,y:600}],
borderInfo:{
width:4, style:5, cloudIntensity:2, dashPhase:1, dashes:[2,7],
}
},
object:"polygon",
},
{
annotJson:{
type:'polyline', title:"title", subject:"polyline", contents:'contents', name:'name', intent:"PolyLineDimension",
opacity:1, color:0x00ffff, flags:4, rect:{left:250,right:300,top:600,bottom:550}, vertexes:[{x:250,y:550},{x:250,y:600},{x:300,y:600}],
borderInfo:{
width:4, style:0, cloudIntensity:1, dashPhase:1, dashes:[2,7],
}
},
object:"polyline",
},
{
annotJson:{
type:'screen', contents:'contents', name:'name', color:0x00ffff, flags:4, rect:{left:450,right:500,top:600,bottom:550},
borderInfo:{
width:4, style:1, cloudIntensity:1, dashPhase:1, dashes:[2,7],
}
},
object:"screen",
},
{
annotJson:{
type:'link', title:"title", subject:"link", contents:'contents', name:'name',
opacity:0.75, color:0xff0000, flags:0, rect:{left:350,right:400,top:500,bottom:450},
borderInfo:{
width:4, style:0, cloudIntensity:1, dashPhase:1, dashes:[2,7],
},
},
object:"link",
},
];
let doc = await Foxit.ReaderApp.getActiveDoc();
tests.forEach(async(test)=> {
await doc.addAnnot(0,test.annotJson).then(function (ret) {
if(typeof(ret) === 'object'){
result.push('addAnnot ' + test.object + ' success');
}
else{
result.push('addAnnot ' + test.object + ' fail');
}
});
});
await sleep(500);
for(let i=0;i<result.length;i++){
tmp += result[i] + '\n';
}
console.log(tmp);
};
add embeded file.
Attachment option
Add new header-footer.
A json object specify configuration of header footer
var headerFooter = {
contentFormats: {
TopLeft: 'abc <<1 of n>> <<mm.dd.yy>>',
TopRight: "20",
BottomCenter: "4",
},
margin: { left: 20, right: 20, top: 20, bottom: 20 },
textSize: 10,
textColor: 0x00ff00,
hasTextShrinked: true,
hasFixedSized: true,
startPageNumber: 10,
underline: true,
}
const doc = await Foxit.ReaderApp.getActiveDoc();
let ret = await doc.addHeaderFooter(headerFooter);
Object - Specifies params information.
Promise
Close the open document.
Create the root bookmark of the document.
Duplicate Pages
A two-dimensional array of page indices(starts from 0) which would be duplicate. Only positive integer in valid page range is available. For example, [[0],[2,4],[5,7]] means page 0, page 2 to page 3, and page 5 to page 6 will be duplicate.
Insert to this PageIndex
Export annotation data in a document to a file.
Specify data file type. xfdf or fdf. The default is fdf.
Specifies particular annots to be exported. If it's null, all annotations will be exported. only support annot type:Care, Circle, Fileattachment, Freetext,Ink,Line, Note, Polygon, PolyLine, Redact, Sound, Square, Stamp, TextMarkup
Export the document's annotation data to Json.
An array with annots that will be exported. All annots will be exported with "null" parameters.
Export document form data to file.
Specify data file type. Please refer to FileType.
Export the given page(s) from the current document.
A two-dimensional array of page indices(starts from 0) which woulb be extracted.
Only positive integer in valid page range is available. For example, [[0],[2,4],[5,7]] means page 0, page 2 to page 3, and page 5 to page6 will be extracted.
Flatten all annotations and interactive form fields in a PDF.
Specify which objects will be flattened.
Get the active DocView of this document.
Current active DocView object.
Get Current doc's Blob object.
Get the type of this document.
Get the count of DocView of this document.
Get fonts info.
Get form object of PDF Document.
Get HeaderFooter of document.
Get metadata of PDF document.
Get all annotations in a specified page by page index.
page index
Get the document page
Access 0 to this.getPageCount() - 1
Gets the number of document pages
Get the PageEditor of this document.
The PageEditor of this document.
Get the page labels of the pdf document.
Could be undefined or page number indexes array. If it's undefined, then all the page labels are returned.
Get the type of current used password.
Get user access permissions. If it is the owner of the document, then 4294967292 is put back to indicate full permissions.
User access permission.
Get the root bookmark of the document.
Get user access permissions.
If current user is the owner of the document, then 4294967292 is put back to indicate full permissions.
Call this function to determine whether the document contains pdf form.
true means the document contains form, false otherwise
Import data from an FDF file specified by array buffer.
Specify fdf file's stream
Skip annotationImportedEx event
Import data from Json.
Specify annots' json array.
Import form data from an FDF file specified by array buffer.
Specify fdf file's stream.
File format. Please refer to FileType.
File encoding. Available values are same as second parameter of FileReader.readAsText. default value:"UTF-8"
Insert a new blank PDF page to document, by index.
The page index for new page.
Width of new page.
Height of new page.
Insert a new blank PDF page to the specified pages, by indexes.
A two-dimensional array of page indices(starts from 0) which would be inserted.
Only positive integer in valid page range is available. For example, [[0],[2,4],[5,7]] means page 0, page 2 to page 3, and page 5 to page6 will be inserted.
Width of new page.
Height of new page.
Insert a new blank PDF page to document, by index.
The page index for new page.
Width of new page.
Height of new page.
Start to import pages from another PDF document.
Options for inserting pages.
Call this function to determine whether the document is modified if modified return true, false otherwise.
check embeded file is exist.
string - Attachment name
Call this function to determine whether the document is represented in linearized (fast web view) format.
true means linearized, false otherwise
Check document is a portfolio.
Check document is a static XFA.
Load form data of PDF document.
Move a specified page to a new index position.
Index of the specified page.
Index of the destination position.
Move the specified pages to a new index position.
A two-dimensional array of page indices(starts from 0) which would be moved. Only positive integer in valid page range is available. For example, [[0],[2,4],[5,7]] means page 0, page 2 to page 3, and page 5 to page6 will be moved.
A page index in current PDF document. Default value:0. If less than 0 or more than total page, will throw error.
protect Doc, all of the content will be encrypted when saving the document, depending on registerSecurityHandler functoin.
true: success false: fail
remove embeded file.
Revmove all headers and foonters of document.
Remove a PDF page by page index.
Index of the specified page.
Remove the specified pages by page indexes.
A two-dimensional array of page indices(starts from 0) which would be removed. Only positive integer in valid page range is available. For example, [[0],[2,4],[5,7]] means page 0, page 2 to page 3, and page 5 to page6 will be removed.
Promise
Using the new document, replace the specified page of the old document
Reverse Pages
Page indexs
Set the specified pages rotation.
A two-dimensional array of page indices(starts from 0) which would be rotated. Only positive integer in valid page range is available. For example, [[0],[2,4],[5,7]] means page 0, page 2 to page 3, and page 5 to page6 will be rotated.
Rotation to be set. the value is 0 | 80 | 180 | 270.
void
Call this function to notify that this document is modified.
update embeded file.
const reader = new FileReader();
reader.onload = async () => {
let attachOption = {
fileName: file.name,
buffer: new Uint8Array(reader.result),
modifiedDateTime: file.lastModifiedDate,
};
const doc = await Foxit.ReaderApp.getActiveDoc();
let ret = await doc.setEmbeddedFileByAttachments(attachOption);
Set metadata value.
Metadata key string. It should not be an empty string.
Currently it can be one of the following keys: "Title", "Author", "Subject", "Keywords", "Creator", "Producer", "Trapped", "CreationDate", "ModDate", "pdfaid".
It can also be some other custom information keys if they're supported by the PDF file.
An string value of metadata value.
void
Set document password and permission.
user password.
owner password.
User_Permissions 32bit numbers, Print PDF document with normal mode. (Bit 3 );
Modify PDF contents. (Bit 4);
Extract PDF contents. (Bit 5);
Operate text annotations and fill in interactive form fields. (Bit 6);
Fill PDF form. (Bit 9);
Disabilities support. (Bit 10);
Assemble PDF document. (Bit 11);
Print PDF document with higher qualities. (Bit 12);
Cipher type string. Available values: "rc4", "aes128", "aes256"
boolean - true means to encrypt metadata, and false means not to encrypt metadata
split doc by blank page. return array buffer if it's success, -1 otherwise.
split doc by max pages. return array buffer if it's success, -3 otherwise. -3: maspage > pagecount
max page
split doc by page range. return array buffer if it's success, -4 otherwise. -4: parse pageRange error.
the page range.
If you want to print pages 3,5 and 8 enter "3,5,8".
If you want to print pages from 3 to8, enter "3-8" in the text box.
split doc by top level bookmark. return array buffer if it's success, -2 otherwise. -2: no bookmarks.
swap page
Modify header or footer of documents. If there is no header or footer, this function will add one.
HeaderFooter object.
Object - Specifies params info.
Promise
Represents the PDF document object.
This class offers functions to retrieve different part of a PDF document.
This class also offers functions for modifying or getting information from a PDF document, and so on.
To get the active doc, please use: