The sdk.IDocumentModel interface is the central hub for all document interactions. It combines state properties, core lifecycle operations, and a comprehensive set of editing commands.
When you open a document using PdfSdk.openDocument or PdfSdk.openBlankDocument, you receive an instance of IDocumentModel.
const document = await PdfSdk.openDocument({ file });
// document implements IDocumentModel
Optional open parameters include password, readOnly and path — the host-app file path of the document. The path is stored on the session (document.filePath) and is what the UI's Save writes back to, so the host can keep the document in its original location.
Retrieve basic metadata and status information.
console.log(`Title: ${document.title}`);
console.log(`Pages: ${document.getNumPages()}`);
console.log(`Modified: ${document.isModified}`);
| Method | Description |
|---|---|
| sdk.IDocumentModel.getNumPages | Returns the total number of pages. |
| sdk.IDocumentModel.getPage | Retrieves a specific PageModel by index. |
| sdk.IDocumentModel.getPages | Returns an array of all PageModel objects. |
| sdk.IDocumentModel.changeDocName | Renames the document instance in memory. |
| sdk.IDocumentModel.dispose | Releases resources associated with the document. |
Export the document to various formats.
// Export as a Blob
const blob = await document.exportDocument({ as: 'blob' });
// Export as a File
const file = await document.exportDocument({ as: 'file', name: 'output.pdf' });
After persisting an export yourself (headless save flow), you can mark the document as saved: sdk.IDocumentModel.clearDocumentHistory clears the undo/redo history so isModified/hasUndo reset, and document.filePath can be updated to the new location.
Manage the structure of the document by adding, removing, or modifying pages.
// Rotate the first page 90 degrees
await document.rotatePages({
range: [0],
rotation: 90,
});
// Delete the second page
await document.deletePages({
range: [1],
});
| Method | Description |
|---|---|
| sdk.IDocumentModel.deletePages | Removes specified pages from the document. |
| sdk.IDocumentModel.rotatePages | Rotates specified pages by 90, 180, or 270 degrees. |
| sdk.IDocumentModel.movePages | Moves pages to a new location within the document. |
| sdk.IDocumentModel.insertPagesFromFile | Inserts pages from another PDF file. |
| sdk.IDocumentModel.insertBlankPages | Inserts new blank pages. |
| sdk.IDocumentModel.insertDuplicatePages | Duplicates existing pages. |
| sdk.IDocumentModel.resizePages | Changes the dimensions of specified pages. |
| sdk.IDocumentModel.reversePage | Reverses the order of pages in a range. |
| sdk.IDocumentModel.replaceWithBlankPages | Replaces content of specified pages with blank pages. |
| sdk.IDocumentModel.replaceWithDuplicatePages | Replaces pages with duplicates of other pages. |
| sdk.IDocumentModel.replaceWithPagesFromFile | Replaces pages with content from another PDF. |
| sdk.IDocumentModel.changePagesBackground | Sets a background color or image for pages. |
| sdk.IDocumentModel.changePagesMargin | Adjusts the margins of specified pages. |
Create, modify, and remove annotations (comments, shapes, stamps).
// Add a sticky note
await document.createAnnotation({
type: 'StickyNote',
pageIndex: 0,
rect: [100, 100, 150, 150],
contents: 'Please review',
});
| Method | Description |
|---|---|
| sdk.IDocumentModel.createAnnotation | Creates a new annotation (StickyNote, Highlight, Shape, etc.). |
| sdk.IDocumentModel.deleteAnnotation | Removes an existing annotation. |
| sdk.IDocumentModel.changeAnnotationProperties | Updates properties like color, opacity, or content. |
| sdk.IDocumentModel.whiteoutPage | Redacts a region of the page (permanently removes content). |
| sdk.IDocumentModel.createWidgetAnnotation | Creates form fields or other widget annotations. |
| sdk.IDocumentModel.autoOrderAnnotation | Automatically reorders annotations based on position. |
| sdk.IDocumentModel.changeAnnotOrder | Changes the Z-order of an annotation. |
| sdk.IDocumentModel.orderAnnotation | Moves an annotation to a specific index in the order. |
| sdk.IDocumentModel.canChangeAnnotZOrder | Checks if annotation Z-order can be changed. |
Modify the actual content of the PDF, including text and images.
| Method | Description |
|---|---|
| sdk.IDocumentModel.replaceText | Finds and replaces text strings. |
| sdk.IDocumentModel.createTextBlock | Adds new text to the page. |
| sdk.IDocumentModel.deleteTextBlocks | Removes text blocks. |
| sdk.IDocumentModel.editPageText | Edits existing text content. |
| sdk.IDocumentModel.editTextParagraphs | Edits text at the paragraph level. |
| sdk.IDocumentModel.insertChar | Inserts a single character. |
| sdk.IDocumentModel.transformTextBlock | Moves, scales, or rotates a text block. |
| sdk.IDocumentModel.changeFontAttributes | Changes font family, size, or style. |
| sdk.IDocumentModel.changeHighlightColor | Changes the color of text highlighting. |
| sdk.IDocumentModel.changeStrikeoutColor | Changes the color of strikeout text. |
| sdk.IDocumentModel.changeUnderlineColor | Changes the color of underlined text. |
| sdk.IDocumentModel.changeListStyle | Modifies list formatting (bullets, numbering). |
| sdk.IDocumentModel.changeParaAttr | Modifies paragraph attributes (alignment, etc). |
| sdk.IDocumentModel.getTextAsTable | Extracts text content structured as a table. |
| sdk.IDocumentModel.canChangeTextBlockZOrder | Checks if text block Z-order can be changed. |
| Method | Description |
|---|---|
| sdk.IDocumentModel.insertImageContentElement | Inserts an image file onto a page. |
| sdk.IDocumentModel.cropImage | Crops an image element on the page. |
| sdk.IDocumentModel.deleteContentElements | Removes specific content objects (images, text). |
| sdk.IDocumentModel.copyContentElement | Copies an element to the clipboard. |
| sdk.IDocumentModel.pasteContentElement | Pastes an element from the clipboard. |
| sdk.IDocumentModel.copyTextBlock | Copies a text block to the clipboard. |
| sdk.IDocumentModel.pasteTextBlock | Pastes a text block from the clipboard. |
| sdk.IDocumentModel.changeElementMatrix | Applies a transformation matrix to an element. |
| sdk.IDocumentModel.changeElementOrder | Changes the Z-order of content elements. |
| sdk.IDocumentModel.createClip | Creates a clipping path. |
| sdk.IDocumentModel.deleteClip | Removes a clipping path. |
| sdk.IDocumentModel.transformClip | Transforms a clipping path. |
| sdk.IDocumentModel.transformContent | Transforms generic content elements. |
| sdk.IDocumentModel.canChangeElementZOrder | Checks if element Z-order can be changed. |
Handle interactive forms and digital signatures.
// Fill a form field
await document.changeAcroformValue({
fieldId: 'ClientName',
value: 'John Doe',
});
| Method | Description |
|---|---|
| sdk.IDocumentModel.fillSignCreate | Creates a Fill & Sign field. |
| sdk.IDocumentModel.fillSignDelete | Deletes a Fill & Sign field. |
| sdk.IDocumentModel.fillSignUpdate | Updates a Fill & Sign field. |
| sdk.IDocumentModel.importAcroformsFdfData | Imports form data from an FDF file. |
| sdk.IDocumentModel.changeAcroformValue | Sets the value of a form field. |
| sdk.IDocumentModel.resetAcroformsFdfData | Resets form fields to their default values. |
| sdk.IDocumentModel.exportAcroformsFdfData | Exports form data. |
| sdk.IDocumentModel.exportFillSignAsset | Exports a Fill & Sign asset (signature/initials). |
| sdk.IDocumentModel.isDocPermittedForESign | Checks if the document allows e-signing. |
Add headers, footers, watermarks, and page numbers.
// Add page numbers
await document.insertPageNumber({
format: 'Page %n of %N',
position: 'BottomCenter',
});
| Method | Description |
|---|---|
| sdk.IDocumentModel.insertHeader | Adds a header to specified pages. |
| sdk.IDocumentModel.deleteHeader | Removes headers. |
| sdk.IDocumentModel.insertPageNumber | Adds automatic page numbering. |
| sdk.IDocumentModel.deletePageNumber | Removes page numbering. |
| sdk.IDocumentModel.insertWatermark | Adds a text or image watermark. |
| sdk.IDocumentModel.deleteWatermark | Removes watermarks. |
| sdk.IDocumentModel.insertBatesNumbering | Applies Bates numbering for legal documents. |
| sdk.IDocumentModel.deleteBatesNumbering | Removes Bates numbering. |
Manage bookmarks, attachments, and layers.
// Add a bookmark
await document.addBookmark({
title: 'Section 1',
pageIndex: 0,
parentIndex: [],
});
| Method | Description |
|---|---|
| sdk.IDocumentModel.addBookmark | Adds a new bookmark to the outline. |
| sdk.IDocumentModel.bookmarkAddBefore | Adds a bookmark before a specific node. |
| sdk.IDocumentModel.bookmarkAddAfter | Adds a bookmark after a specific node. |
| sdk.IDocumentModel.bookmarkAddChild | Adds a child bookmark. |
| sdk.IDocumentModel.deleteBookmark | Removes a bookmark. |
| sdk.IDocumentModel.deleteAllBookmarks | Removes all bookmarks. |
| sdk.IDocumentModel.moveBookmark | Repositions a bookmark in the hierarchy. |
| sdk.IDocumentModel.patchBookmark | Updates bookmark properties. |
| sdk.IDocumentModel.addAttachment | Attaches a file to the PDF. |
| sdk.IDocumentModel.deleteAttachment | Removes an attachment. |
| sdk.IDocumentModel.saveAttachment | Saves an attachment to a file. |
| sdk.IDocumentModel.exportAttachment | Exports a specific attachment. |
| sdk.IDocumentModel.exportAllAttachments | Exports all attachments. |
| sdk.IDocumentModel.setOCGroupState | Controls the visibility of Optional Content Groups (Layers). |
| sdk.IDocumentModel.updateLayerStates | Updates the state of multiple layers. |
Manage document security, permissions, and claims.
// Check permissions
const claims = await document.listDocumentClaims();
console.log('Allowed operations:', claims);
// Unlock a password-protected document
await document.ownerAuthorization('password123');
| Method | Description |
|---|---|
| sdk.IDocumentModel.listDocumentClaims | Returns a list of permitted operations (claims). |
| sdk.IDocumentModel.ownerAuthorization | Unlocks the document with an owner password. |
| sdk.IDocumentModel.setSecurityPermissions | Sets security permissions (requires owner access). |
| sdk.IDocumentModel.isOperationPermitted | Checks if a specific operation is allowed. |
| sdk.IDocumentModel.applyRedactions | Permanently applies redaction annotations. |
| sdk.IDocumentModel.changeDocumentProperties | Updates document metadata (Title, Author, etc.). |
Extract content and data from the document.
| Method | Description |
|---|---|
| sdk.IDocumentModel.extractImages | Extracts all images from the document. |
| sdk.IDocumentModel.extractImage | Extracts a specific image. |
| sdk.IDocumentModel.extractPages | Extracts pages as a new document. |
| sdk.IDocumentModel.exportComments | Exports annotations/comments. |
| sdk.IDocumentModel.documentExportStampAppearance | Exports the appearance of a stamp. |
| sdk.IDocumentModel.getMeasurementViewports | Retrieves measurement viewports. |
| sdk.IDocumentModel.createMeasurementCalibration | Calibrates measurement tools. |
Optimize the document for storage or distribution.
| Method | Description |
|---|---|
| sdk.IDocumentModel.compress | Compresses the document to reduce file size. |
| sdk.IDocumentModel.sanitize | Removes sensitive information and metadata. |
| sdk.IDocumentModel.removeMetadata | Strips metadata from the document. |
Manage the history of changes.
if (document.hasUndo) {
await document.undo();
}
| Method | Description |
|---|---|
| sdk.IDocumentModel.undo | Reverts the last action. |
| sdk.IDocumentModel.redo | Reapplies the last undone action. |
| sdk.IDocumentModel.changeDocumentHistory | Modifies the history stack directly. |
| sdk.IDocumentModel.doTransactionAsync | Groups multiple operations into a single transaction. |
| Property | Type | Description |
|---|---|---|
id |
string |
Unique identifier for the document instance. |
title |
string |
The document title from metadata. |
author |
string |
The document author. |
isModified |
boolean |
true if the document has unsaved changes. |
isSigned |
boolean |
true if the document contains digital signatures. |
security |
sdk.IDocumentSecurity | Security settings and permissions. |
undoRedoHistory |
sdk.IDocumentHistory | Information about the undo/redo stack. |
permissions |
string |
Raw permissions string. |
bookmarks |
any |
Document bookmarks structure. |
layers |
any[] |
List of optional content groups (layers). |
attachments |
any[] |
List of file attachments. |
| Event | Type | Description |
|---|---|---|
onCommandExecuting |
Observable |
Emits before a command runs. |
onCommandExecuted |
Observable |
Emits after a command completes successfully. |
onCommandFailed |
Observable |
Emits if a command throws an error. |
onIsModifiedChanged |
Observable |
Emits when the modification state changes. |
onPagesChanged |
Observable |
Emits when pages are added, removed, or moved. |
onUndoRedoChanged |
Observable |
Emits when the history stack changes. |
onBookmarksChanged |
Observable |
Emits when bookmarks are modified. |