PDFDocument()
new PDFDocument()
The current document object loaded in the PSPDFKitView.
- Source:
Methods
(static) addAnnotations(instantJSON) → {Promise.<boolean>}
Adds all the specified annotations in the document.
Parameters:
Name | Type | Description |
---|---|---|
instantJSON |
Record | The annotations to add to the document in InstantJSON format. Ensure that the "annotations" key is included with an array of all the annotations as value. |
- Source:
Returns:
A promise containing the result of the operation.
true
if the annotations were added, false
otherwise.
- Type
- Promise.<boolean>
Example
const result = await this.pdfRef.current?.getDocument().addAnnotations(annotations);
(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>>}
Gets all the unsaved changes to annotations in the document.
- Source:
Returns:
A promise containing the unsaved annotations as an array, wrapped in a Map with the mandatory 'annotations' key.
- Type
- Promise.<Record.<string, any>>
Example
const result = await this.pdfRef.current?.getDocument().getAllUnsavedAnnotations();
(static) getAnnotations(typeopt) → {Promise.<Array.<any>>}
Gets all the annotations in the document for a specified type.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
type |
string |
<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.
- Type
- Promise.<Array.<any>>
Example
const result = await this.pdfRef.current?.getDocument().getAnnotations("pspdfkit/ink");
(static) getAnnotationsForPage(pageIndex, typeopt) → {Promise.<Array.<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 |
<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.<any>>
Example
const result = await this.pdfRef.current?.getDocument().getAnnotationsForPage(0, "pspdfkit/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) 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) removeAnnotations(instantJSON) → {Promise.<boolean>}
Removes all the specified annotations from the document.
Parameters:
Name | Type | Description |
---|---|---|
instantJSON |
Array | 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.
true
if the annotations were removed, false
otherwise.
- 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();