Search results

PdfDocument API in JavaScript PDF API control

Represents a PDF document and can be used to parse an existing PDF document.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data);
// Access first page
let page: PdfPage = document.getPage(0);
// Flatten annotations and form fields
document.flatten = true;
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();

Properties

bookmarks PdfBookmarkBase

Gets the bookmarks (Read only).

fileStructure PdfFileStructure

Gets the internal structure of the PDF document.

flatten boolean

Gets the boolean flag to flatten the annotations and form fields.

form PdfForm

Gets the PDF form fields included in the document (Read only).

isEncrypted boolean

Gets a value indicating whether the document is encrypted. (Read Only).

isUserPassword boolean

Gets a value indicating whether the document is decrypted using the user password. (Read only).

layers PdfLayerCollection

Gets the collection of PdfLayer from the document.

pageCount number

Gets the page count (Read only).

permissions PdfPermissionFlag

Gets the permission flag of the PDF document (Read only).

Methods

addPage

Creates a new page with default page settings and adds it to the collection.

Returns PdfPage

addPage

Creates a new page with default settings and inserts it into the collection at the specified page index.

Parameter Type Description
index number Page index.

Returns PdfPage

addPage

Creates a new page with specified page settings and adds it to the collection.

Parameter Type Description
pageSettings PdfPageSettings Page settings.

Returns PdfPage

addPage

Creates a new page with specified page settings and inserts it into the collection at the specified page index.

Parameter Type Description
index number Page index.
pageSettings PdfPageSettings Page settings.

Returns PdfPage

addSection

Creates a new section with default page settings.

Returns PdfSection

addSection

Creates a new section with custom page settings.

Parameter Type Description
settings PdfPageSettings Settings of the section.

Returns PdfSection

destroy

Disposes the current instance of PdfDocument class.

Returns void

exportAnnotations

Exports the annotations from the PDF document.

Returns Uint8Array

exportAnnotations

Exports the annotations from the PDF document.

Parameter Type Description
settings PdfAnnotationExportSettings Annotation export settings.

Returns Uint8Array

exportAnnotations

Exports the annotations from the PDF document.

Parameter Type Description
filename string Output file name.

Returns void

exportAnnotations

Exports the annotations from the PDF document.

Parameter Type Description
filename string Output file name.
settings PdfAnnotationExportSettings Annotation export settings.

Returns void

exportFormData

Exports the form data from the PDF document.

Returns Uint8Array

exportFormData

Exports the form data from the PDF document.

Parameter Type Description
settings PdfFormFieldExportSettings Form field export settings.

Returns Uint8Array

exportFormData

Exports the form data from the PDF document.

Parameter Type Description
filename string Output file name.

Returns void

exportFormData

Exports the form data from the PDF document.

Parameter Type Description
filename string Output file name.
settings PdfFormFieldExportSettings Form field export settings.

Returns void

getPage

Gets the PdfPage at the specified index.

Parameter Type Description
pageIndex number Page index.

Returns PdfPage

importAnnotations

Imports the annotations from the PDF document.

Parameter Type Description
data string annotations data as base64 string.
dataFormat DataFormat Data format of the input data.

Returns void

importAnnotations

Imports the annotations from the PDF document.

Parameter Type Description
data Uint8Array annotations data as byte array.
dataFormat DataFormat Data format of the input data.

Returns void

importFormData

Imports the form data from the PDF document.

Parameter Type Description
data string Form data as base64 string.
dataFormat DataFormat Data format of the input data.

Returns void

importFormData

Imports the form data from the PDF document.

Parameter Type Description
data Uint8Array Form data as byte array.
dataFormat DataFormat Data format of the input data.

Returns void

importPage

Copy the specific page and insert it as the next page

Returns void

importPage

Copy the specific page and insert it at the specified target page index and page rotation.

Returns void

importPage

Import the specified page into the current document pages collection as the last page

Parameter Type Description
page PdfPage Page to import.
sourceDocument PdfDocument PDF document to get pages to import.

Returns void

importPage

Create a new page with default settings and insert it into the collection at the specified page index.

Parameter Type Description
page PdfPage Page to import.
sourceDocument PdfDocument PDF document to get pages to import.
options (optional) PdfPageImportOptions Options to customize the support of import PDF pages.

Returns void

importPageRange

Import the pages specified by the start and end index into the current document’s pages collection.

Parameter Type Description
sourceDocument PdfDocument PDF document to get pages to import.
startIndex number Start page index. The default value is 0.
endIndex number End page index. The default value is the index of the last page in the source document.

Returns void

importPageRange

Import the pages specified by start and end index into the current document’s pages collection.

Parameter Type Description
sourceDocument PdfDocument PDF document to get pages to import.
startIndex number Start page index. The default value is 0.
endIndex number End page index. The default value is the index of the last page in the source document.
options (optional) PdfPageImportOptions Options to customize the support of import PDF pages.

Returns void

removePage

Removes the specified page.

Parameter Type Description
page PdfPage The page to remove.

typescript<br>// Load an existing PDF document<br>let document: PdfDocument = new PdfDocument(data, password);<br>// Access the first page<br>let page: PdfPage = document.getPage(0);<br>// Removes the specified page<br>document.removePage(page);<br>// Save the document<br>document.save('output.pdf');<br>// Destroy the document<br>document.destroy();<br>

Returns void

removePage

Removes the page from the specified index.

Parameter Type Description
index number The page index to remove.

typescript<br>// Load an existing PDF document<br>let document: PdfDocument = new PdfDocument(data, password);<br>// Removes the first page<br>document.removePage(0);<br>// Save the document<br>document.save('output.pdf');<br>// Destroy the document<br>document.destroy();<br>

Returns void

reorderPages

Reorders the pages in the PDF document.

Parameter Type Description
orderArray number[] The page sequence to arrange the pages.

Returns void

save

Saves the modified document.

Returns Uint8Array

save

Saves the modified document to the specified filename.

Parameter Type Description
filename string Specifies the filename to save the output pdf document.

typescript<br>// Load an existing PDF document<br>let document: PdfDocument = new PdfDocument(data, password);<br>// Save the document<br>document.save('Output.pdf');<br>// Destroy the document<br>document.destroy();<br>

Returns void

saveAsBlob

Saves the document to the specified output stream and return the stream as Blob.

Returns Promise

split

Splitting a PDF file into individual pages.

Returns void

splitByFixedNumber

Splits the PDF document into parts, each containing a maximum number of pages specified.

Parameter Type Description
fixedNumber number specifies the maximum number of pages in each split PDF. The default value is 1.

Returns void

splitByPageRanges

Splits the PDF document into multiple parts based on the specified page ranges.

Parameter Type Description
ranges number[][] The two dimensional number array specified for start and end page indexes to split PDF documents.

Returns void