PDFDocument()

new PDFDocument()

The current document object loaded in the PSPDFKitView.
Source:

Methods

(static) addAnnotations(annotations) → {Promise.<boolean>}

Adds all the specified annotations to the document. For complex annotations or annotations with attachments, use the applyInstantJSON API.
Parameters:
Name Type Description
annotations Array.<any> | Array.<AnnotationType> | Record.<string, any> Array of annotations in Instant JSON format to add to the document.
Source:
Returns:
A promise containing the result of the operation. true if the annotations were added, and false if an error occurred.
Type
Promise.<boolean>
Example
const result = await this.pdfRef.current?.getDocument().addAnnotations(annotations);

(static) applyInstantJSON(documentJSON) → {Promise.<boolean>}

Adds the specified Document JSON data to the document.
Parameters:
Name Type Description
documentJSON Annotation.DocumentJSON The full Instant JSON object to add to the document as a DocumentJSON object.
Source:
Returns:
A promise containing the result of the operation. true if the document JSON was applied, and false if an error occurred.
Type
Promise.<boolean>
Example
const result = await this.pdfRef.current?.getDocument().applyInstantJSON(documentJSON);

(static) exportXFDF(filePath) → {Promise.<any>}

Exports the annotations from the current document to a XFDF file.
Parameters:
Name Type Description
filePath string The path where the XFDF file should be exported to.
Source:
Returns:
A promise containing an object with the exported file path and result. true if the xfdf file was exported successfully, and false if an error occurred.
Type
Promise.<any>
Example
const result = await this.pdfRef.current?.getDocument().exportXFDF('path/to/XFDF.xfdf');

(static) getAllUnsavedAnnotations() → {Promise.<(Record.<string, any>|DocumentJSON)>}

Gets all the unsaved changes to annotations in the document.
Source:
Returns:
A promise containing the unsaved annotations as an array, wrapped in a DocumentJSON object.
Type
Promise.<(Record.<string, any>|DocumentJSON)>
Example
const result = await this.pdfRef.current?.getDocument().getAllUnsavedAnnotations();

(static) getAnnotations(typeopt) → {Promise.<Array.<(AnnotationType|any)>>}

Gets all the annotations in the document for a specified type.
Parameters:
Name Type Attributes Description
type string | Annotation.Type <optional>
The type of annotation to get. If not specified, all annotation types are returned.
Source:
Returns:
A promise containing the annotations of the document as an array of Annotation objects.
Type
Promise.<Array.<(AnnotationType|any)>>
Example
const result = await this.pdfRef.current?.getDocument().getAnnotations(Annotation.Type.INK);

(static) getAnnotationsForPage(pageIndex, typeopt) → {Promise.<Array.<(AnnotationType|any)>>}

Gets all the annotations in the document for a specified type.
Parameters:
Name Type Attributes Description
pageIndex number The page index to get annotations for. Starts at 0.
type string | Annotation.Type <optional>
The type of annotation to get. If not specified, all annotation types are returned.
Source:
Returns:
A promise containing the annotations for the specified page of the document as an array.
Type
Promise.<Array.<(AnnotationType|any)>>
Example
const result = await this.pdfRef.current?.getDocument().getAnnotationsForPage(0, Annotation.Type.INK);

(static) getDocumentId() → {Promise.<string>}

Returns a document identifier (inferred from a document provider if possible). A permanent identifier based on the contents of the file at the time it was originally created. If a document identifier is not available, a generated UID value is returned.
Source:
Returns:
A promise containing the document identifier.
Type
Promise.<string>
Example
const documentId = await this.pdfRef.current?.getDocument().getDocumentId();

(static) getPageCount() → {Promise.<string>}

Returns the number of pages in the document.
Source:
Returns:
A promise containing the document page count.
Type
Promise.<string>
Example
const documentId = await this.pdfRef.current?.getDocument().getPageCount();

(static) importXFDF(filePath) → {Promise.<any>}

Imports the supplied XFDF file into the current document.
Parameters:
Name Type Description
filePath string The path to the XFDF file to import.
Source:
Returns:
A promise containing an object with the result. true if the xfdf file was imported successfully, and false if an error occurred.
Type
Promise.<any>
Example
const result = await this.pdfRef.current?.getDocument().importXFDF('path/to/XFDF.xfdf');

(static) invalidateCache() → {Promise.<boolean>}

Invalidates the rendered cache of all the pages for this document. Use this method if the document is not updated after a change, or changed externally, and needs to be re-rendered.
Source:
Returns:
A promise containing the result of the operation. true if the cache was invalidated, false otherwise.
Type
Promise.<boolean>
Example
const result = await this.pdfRef.current?.getDocument().invalidateCache();

(static) invalidateCacheForPage(pageIndex) → {Promise.<boolean>}

Invalidates the rendered cache of the given pageIndex for this document. Use this method if a single page of the document is not updated after a change, or changed externally, and needs to be re-rendered.
Parameters:
Name Type Description
pageIndex number Zero-based page index of the page to refresh.
Source:
Returns:
A promise containing the result of the operation. true if the cache was invalidated, false otherwise.
Type
Promise.<boolean>
Example
const result = await this.pdfRef.current?.getDocument().invalidateCacheForPage(0);

(static) isEncrypted() → {Promise.<string>}

Indicates if the PDF document is encrypted (password protected).
Source:
Returns:
A promise containing whether the document is encrypted.
Type
Promise.<string>
Example
const documentId = await this.pdfRef.current?.getDocument().isEncrypted();

(static) removeAnnotations(annotations) → {Promise.<boolean>}

Removes all the specified annotations from the document.
Parameters:
Name Type Description
annotations Array.<any> | Array.<AnnotationType> An array of the annotations to remove in InstantJSON format. Should not include the "annotations" key as used in the addAnnotations API.
Source:
Returns:
A promise containing the result of the operation.
Type
Promise.<boolean>
Example
const result = await this.pdfRef.current?.getDocument().removeAnnotations(annotations);

(static) save() → {Promise.<boolean>}

Saves the document asynchronously.
Source:
Returns:
A promise containing the result of the operation. true if the document was saved, false otherwise.
Type
Promise.<boolean>
Example
const result = await this.pdfRef.current?.getDocument().save();