Embeds a file, written to the file on save
File name of the attachment.
File content; it is copied.
Optionaldescription: string
Optional description.
Adds a listener for an event. Adding the same function twice for one event has no effect.
Event name.
Listener, called with the event arguments.
Optionaloptions: { once?: boolean }
Listener options.
Optionalonce?: booleanWhen true, the listener is removed after it runs once.
Adds a watermark to the file (text or image, leaving existing ones); use setWatermark / DocumentViewer.setWatermark for view watermarks
Watermark settings: text or image is required (rejects otherwise). Defaults: font Helvetica, size 48, color '#808080', opacity 0.5, rotation 45 degrees, scale 1, centered, drawn in front, on all pages.
Applies redaction annotations, removing the content under them; page content changes and pagesUpdated fires.
Ids of the redaction annotations to apply.
Page numbers (1-based) reported as changed in pagesUpdated.
OptionalerasureIds: string[]
Ids of additional annotations to erase. Defaults to none.
A Promise that resolves to the ids of the applied redactions and of the other annotations removed.
The page structure changed (added, removed, moved, rotated, cropped)
True once any page has been added, removed, moved, rotated or cropped since the document was opened.
Cancels a render started by loadCanvas or loadThumbnail. The shared render is aborted only when no other request is waiting for it.
The id returned by loadCanvas.
Cancels a thumbnail render; same as cancelLoadCanvas.
The id returned by loadThumbnail.
Whether it is the owner password; if so, the document gets owner permissions right away (an empty password counts for unencrypted documents)
The password to check.
A Promise that resolves to true when it is the owner password.
Closes the document: stops its rendering, frees its cached page images and releases it in the engine. Call it for documents made with Core.createDocument once they are no longer needed; the viewer closes the documents it loads itself.
Resolves once the document is released.
Content comparison: marks replacements / insertions / deletions on copies of both documents and produces a combined report; the two original documents are untouched. Pages correspond by index, compared up to the end of the shorter one
The document to compare with.
Optionaloptions: CompareContentOptions
What to compare (text and images, both by default), the colors of replacements, insertions and deletions, and the opacity (0.5 by default).
A Promise that resolves to the marked copies of both documents and the combined report document.
Overlay comparison: draws the graphics of both documents over each other in their own colors and opens the result as a new document. Neither original is changed.
The document to compare with.
Optionaloptions: CompareDrawingsOptions
Pages, colors, opacity and blending.
The new document holding the comparison.
Converts to PDF/A or PDF/UA-1 (changes this document in place; saving afterwards gives that standard). PDF/A: iccProfile is the output intent, by default the same as separations (CMYK/CoatedFOGRA39.icc). PDF/UA-1: adds structure tags automatically (Document → NonStruct → Span), writes the title (shown in the title bar) and language; title defaults to the title in the document info, and it errors when there is neither; language is a locale name like 'zh-CN' (the engine accepts only 25, see UA_LANGUAGES), not written when omitted. Note: PDF/A and PDF/UA cannot be converted together (the engine aborts); slow with many pages or much content (about 40 s for a few dozen pages of text and images)
The target standard, such as 'PDF/A-2b' or 'PDF/UA-1'. Rejects for other values.
Optionaloptions: { iccProfile?: string | ArrayBuffer; language?: string; title?: string }
Conversion options. Rejects for PDF/UA when there is no title or the language is not supported.
OptionaliccProfile?: string | ArrayBufferPDF/A only: output intent ICC profile as bytes or a URL. Defaults to CMYK/CoatedFOGRA39.icc in the Worker folder.
Optionallanguage?: stringPDF/UA only: document language as a locale name such as 'en-US'; not written when omitted.
Optionaltitle?: stringPDF/UA only: document title. Defaults to the title in the document information.
Copy each selected page immediately after itself, as one page edit and undo step. Input is 1-based, sorted and deduplicated without mutation.
Page numbers (1-based) or range strings such as '1-3'. Throws a RangeError when a page does not exist.
Crops this much from the top, bottom, left and right (pt, in the page's display orientation), written to /CropBox; not undoable, history is cleared
Page numbers (1-based) or range strings.
Points to remove from the top.
Points to remove from the bottom.
Points to remove from the left.
Points to remove from the right.
Turns off separations and restores normal rendering (the ink list and on/off states are kept)
Sets the view watermark back to not applied, so DocumentViewer draws it again.
Turns on separations: page bitmaps afterwards render by ink (inks turned off in getColorSeparations are not drawn), all by the main Worker; colorSeparationAdded fires once for each new ink. After toggling, call DocumentViewer.refreshAll to redraw. iccProfile is the CMYK output intent (bytes or address), CMYK/CoatedFOGRA39.icc in the Worker directory by default; with checkIfBaseColorsUsed inks carry isBaseColor / isBaseColorUsedInDocument (checked by rendering each page at a small size, taking longer with many pages)
Optionaloptions: { checkIfBaseColorsUsed?: boolean; iccProfile?: string | ArrayBuffer }
Separation options.
OptionalcheckIfBaseColorsUsed?: booleanAlso reports whether each ink is a CMYK base color and whether it is used; slower with many pages.
OptionaliccProfile?: string | ArrayBufferCMYK output intent ICC profile as bytes or a URL. Defaults to CMYK/CoatedFOGRA39.icc in the Worker folder.
Turns an ink on or off by name; call DocumentViewer.refreshAll afterwards to redraw
Ink name, as in getColorSeparations. Unknown names are ignored.
True to draw the ink, false to hide it.
The view watermark is already "applied" (for example already drawn into the page): DocumentViewer no longer draws it. disableWatermarkApplied sets it back to false
Exports the document's annotations as XFDF. Annotation changes not yet saved to the document (properties set directly on annotation objects) are committed first, as on save.
Optionalids: string[]
Ids of the annotations to export; all annotations when omitted.
OptionalpageIds: string[]
Internal page ids that limit the export to those pages; all pages when omitted.
A Promise that resolves to the XFDF string.
Exports a PDF containing only the content of these layers: objs are layer objs from getLayersArray; without them all layers visible by default are exported
Optionalobjs: string[]
Layer obj identifiers from getLayersArray; the layers visible by default when omitted.
A Promise that resolves to the bytes of the exported PDF.
XFDF of form widgets exported in the engine's native style (one element per widget under
A Promise that resolves to the XFDF string of the form widgets.
Saves these pages (with their committed annotations) as a new PDF. Pages are 1-based page numbers or range strings
such as '3-4' / '1,3-4'; they are taken in page order. When xfdfString is given, its annotations are merged in
(page numbers of this document; annotations already present are not duplicated).
With { separateFile: true } each page becomes its own PDF and an array of files (in page order) is returned.
Page numbers (1-based) or range strings. Throws a RangeError when a page does not exist.
OptionalxfdfString: string
Optional XFDF whose annotations are merged into the output.
Optionaloptions: ExtractPagesOptions & { separateFile?: false }
Extract options; without separateFile (or with false) one PDF is produced.
OptionalseparateFile?: falseOmit or false to get one PDF holding all pages.
A Promise that resolves to the bytes of one PDF holding the pages.
const { documentViewer } = instance.Core;
const doc = documentViewer.getDocument();
const pages1to3 = await doc.extractPages('1-3'); // one ArrayBuffer
const singlePages = await doc.extractPages([1, 2], undefined, { separateFile: true }); // one ArrayBuffer per page
const blob = new Blob([pages1to3], { type: 'application/pdf' });
Saves these pages as separate PDFs, one per page, in page order.
Page numbers (1-based) or range strings. Throws a RangeError when a page does not exist.
Optional XFDF whose annotations are merged into the output.
Extract options with separateFile: true.
true to get one PDF per page.
A Promise that resolves to one PDF per page, in page order.
Saves these pages as a new PDF, or as one PDF per page when options.separateFile is true.
Page numbers (1-based) or range strings. Throws a RangeError when a page does not exist.
OptionalxfdfString: string
Optional XFDF whose annotations are merged into the output.
Optionaloptions: ExtractPagesOptions
Extract options; separateFile: true produces one PDF per page.
A Promise that resolves to one PDF, or to an array of PDFs when separateFile is true.
XFDF of the document's annotations, only these pages when page numbers (1-based) are given. Annotation changes not yet saved to the document are committed first, as on save.
OptionalpageNumbers: number[]
Page numbers (1-based) to export; all pages when omitted.
A Promise that resolves to the exported page numbers and the XFDF string.
Lists the files embedded in the document.
The attachments, in document order.
Current background settings (image backgrounds do not read back pixels, and the engine cannot read back the page range); null when none
A Promise that resolves to the settings, or null when there is no background.
Returns the current Bates numbering settings.
The settings, or null when there is no Bates numbering.
Top level of the outline (bookmark) tree; read from the document again on each call.
A Promise that resolves to the top-level bookmarks.
const { documentViewer } = instance.Core;
const bookmarks = await documentViewer.getDocument().getBookmarks();
const print = (items, depth = 0) => items.forEach((bookmark) => {
console.log(`${' '.repeat(depth)}${bookmark.getName()} (page ${bookmark.getPageNumber()})`);
print(bookmark.getChildren(), depth + 1);
});
print(bookmarks);
Returns the inks found by enableColorSeparations.
The live list of inks; empty before enableColorSeparations.
Returns the density of each ink at a point; empty when separations are off.
Page number (1-based).
Horizontal position in page coordinates.
Vertical position in page coordinates.
A Promise that resolves to one entry per ink, in getColorSeparations order.
Named destinations (catalog /Dests and the /Names /Dests name tree): GoTo destinations with a name, 1-based page numbers, page coordinates
A Promise that resolves to the named destinations, each a Dest with its name.
The page table is fully read (only the first batch is read at open, the rest filled in in the background)
Returns the documentId passed to loadDocument, or the SDK-generated id when none was passed.
The document id.
Saves to bytes (after committing uncommitted annotation changes). With xfdfString the annotations in the exported file are replaced by it; with includeAnnotations false no annotations are included, flatten burns annotations (including forms) into page content, optimize takes the optimized saving path; these options run on a copy, leaving the open document unchanged
Optionaloptions: GetFileDataOptions
Save options: xfdfString replaces the annotations in the output, includeAnnotations: false leaves annotations out, flatten burns annotations into page content, flags are SaveOptions flags and optimize enables optimized saving. All optional.
A Promise that resolves to the bytes of the saved PDF.
// Download the document, including its annotations and form data
const { documentViewer } = instance.Core;
const data = await documentViewer.getDocument().getFileData();
const url = URL.createObjectURL(new Blob([data], { type: 'application/pdf' }));
const link = document.createElement('a');
link.href = url;
link.download = 'document.pdf';
link.click();
URL.revokeObjectURL(url);
// A copy with annotations burned into the page content
const flattened = await documentViewer.getDocument().getFileData({ flatten: true });
Second item of the PDF trailer /ID (without angle brackets), an empty string when missing; unrelated to getDocumentId used for loading.
A Promise that resolves to the identifier, or an empty string when the file has none.
Returns the file name.
The file name, including the extension.
Original file size in bytes
The size in bytes of the file as it was loaded.
Current headers / footers; null when none
A Promise that resolves to the settings, or null when there are none.
Layer (OCG) tree: name, visible, locked, child layers; obj is the identifier the Worker uses to find the layer. Only one stays on in a radio group (RBGroup)
A Promise that resolves to the top-level layers, or an empty array when layers are disabled.
Returns the document information entries read when the document was opened; only non-empty entries are present.
A Promise that resolves to a copy of the metadata.
The engine's optimization defaults: quality 0–1, PPI as [upper, target].
A Promise that resolves to the default optimization settings.
Undo / redo of page operations (insert, blank page, merge, delete, move, rotate), see PageHistoryManager
The page history manager of this document (the same instance on every call).
Size including the page's own /Rotate (PDF points)
Page number (1-based). Throws a RangeError when out of range.
The page width and height in PDF points, after applying the page's own /Rotate.
PDF coordinates (bottom-left origin, y upward) → page coordinates (top-left origin, y downward): flip y, then translate by the unrotated page height
Page number (1-based). Throws a RangeError when out of range.
A new matrix mapping PDF coordinates to page coordinates.
The page's own /Rotate in degrees (0 / 90 / 180 / 270)
Page number (1-based). Throws a RangeError when out of range.
The rotation in degrees: 0, 90, 180 or 270.
One Core.PageInfo per page: size including /Rotate, /Rotate (degrees), the getPageMatrix matrix, page id and page number (created anew each time)
A new array with one PageInfo per page, in page order.
By the writing direction of this page's text (RightToLeft when there is right-to-left text and no left-to-right text); the value set by setPageTextDirection if set
Page number (1-based).
A Promise that resolves to the text direction.
Page coordinates (unrotated page, top-left origin, y downward) → PDF coordinates (bottom-left origin, y upward). ponytail: assumes the page box origin is (0, 0); for annotations to land exactly in files with an offset MediaBox, PageData would need the box origin
Page number (1-based).
Horizontal position in page coordinates.
Vertical position in page coordinates.
The point in PDF coordinates.
Horizontal position.
Vertical position.
Current permissions (encrypted documents opened with the user password are restricted, others have all); securityLevel: 0 not encrypted, 1 user, 2 owner. Passwords and permissions set take effect only after saving; they do not change here
A Promise that resolves to the permission flags and the security level.
Intended for XOD documents; returns null for PDF documents
Always null.
The standard the document declares: 'PDF' (none) or a name like 'PDF/A-2b'
A Promise that resolves to the standard name.
Characters in the rectangle (page coordinates; the character center inside the rectangle), one \n between lines when spanning lines
Page number (1-based).
The rectangle in page coordinates (points, top-left origin).
A Promise that resolves to the text, or an empty string when no character is inside.
const { documentViewer, Math: CoreMath } = instance.Core;
// Text inside the top 100 pt of page 1 (PDF points, origin at the top-left of the page)
const doc = documentViewer.getDocument();
const { width } = doc.getPageInfo(1);
const header = await doc.getTextByPageAndRect(1, new CoreMath.Rect(0, 0, width, 100));
Quad of each character in [startIndex, endIndex) (indexes as in the text of loadPageText; page coordinates)
Page number (1-based).
Index of the first character (inclusive).
Index after the last character (exclusive). The range is clamped to the page text.
A Promise that resolves to one quad per character, in page coordinates.
// Highlight the first occurrence of a word on page 1
const { documentViewer, annotationManager, Annotations } = instance.Core;
const doc = documentViewer.getDocument();
const word = 'Agreement';
const start = (await doc.loadPageText(1)).indexOf(word);
if (start >= 0) {
const quads = await doc.getTextPosition(1, start, start + word.length); // one quad per character
const highlight = new Annotations.TextHighlightAnnotation({ PageNumber: 1 });
highlight.setQuads(quads);
await annotationManager.addAnnotation(highlight);
}
Returns the document type.
Always 'pdf'.
Converts PDF coordinates (bottom-left origin, y up) to page coordinates (unrotated page, top-left origin, y down).
Page number (1-based).
Horizontal position in PDF coordinates.
Vertical position in PDF coordinates.
The point in page coordinates.
Horizontal position.
Vertical position.
Returns the view watermark set with setWatermark.
The watermark options, or null when none is set.
Watermarks already in the file
A Promise that resolves to the watermarks; image pixels are not read back.
Imports plain or command XFDF into the document.
The XFDF text.
OptionalreplaceAll: boolean
When true, every annotation in the document is deleted before importing. Defaults to false.
A Promise that resolves to the data of the imported or changed annotations and the ids of deleted ones.
Inserts a width × height blank page before each of these pages (page numbers before the change; page count + 1 means at the end)
Page numbers (1-based) before which a blank page is inserted; the page count plus one appends at the end.
Page width in points.
Page height in points.
Inserts these pages (all by default) of doc (a document opened in the same Worker) before page insertBeforeThisPage (at the end by default), bringing the annotations on them along
The source document; it must be open in the same SDK instance.
OptionalpagesToInsert: PageList
Page numbers (1-based) or range strings such as '1-3' of the source document; all pages when omitted.
OptionalinsertBeforeThisPage: number
Page number (1-based) to insert before; at the end when omitted or greater than the page count.
Whether the engine considers it an image document (scanned PDF).
A Promise that resolves to true for an image-only document.
The file is linearized (checked from the linearization dictionary at the start of the file at open)
True when the loaded file is linearized.
Renders a page (or the renderRect part) to a new canvas, then calls drawComplete; on a page bitmap cache hit the callback comes in the next microtask. Older queued requests for the same region of the same page are replaced by the new one.
Render options: pageNumber (1-based), zoom or a width / height box in CSS pixels, pageRotation, renderRect, multiplier, renderAnnotations, layerUsage, and the drawComplete callback.
A request id that can be passed to cancelLoadCanvas, pauseLoadCanvas or resumeLoadCanvas.
Plain text of this page (one \n between lines)
Page number (1-based).
A Promise that resolves to the page text.
Renders a page thumbnail, including annotations and form widgets.
Page number (1-based).
Called with the rendered canvas.
Optionalsize: number
Length of the longer side in CSS pixels (the bitmap is multiplied by the canvas multiplier). Defaults to 150.
A request id that can be passed to cancelLoadThumbnail.
Inserts all pages of another document (address, bytes, File and so on, or an opened Document) before page insertBeforePage (at the end by default)
The document to merge: a URL, bytes, Blob or File, or an already opened Document. A source opened here is closed afterwards.
OptionalinsertBeforePage: number
Page number (1-based) to insert before; at the end when omitted or greater than the page count.
A Promise that resolves to the source file name and its inserted page numbers.
Moves these pages in page number order before page insertBeforeThisPage (to the end when beyond the page count)
Page numbers (1-based) or range strings of the pages to move.
Page number (1-based, counted before the move) to place the pages before; values below 1 mean the front.
Lowers a queued render to background priority; renders already started are not affected.
The id returned by loadCanvas. Unknown ids are ignored.
Reads the content of an embedded file.
Index in getAttachments.
The file bytes.
Drops the page text cache after page content changes (TextManager invalidates by text version)
Removes the background. Pages are redrawn afterwards.
Removes all Bates numbering. Pages are redrawn afterwards.
Removes every listener of every event.
Removes all headers and footers. Pages are redrawn afterwards.
Deletes all watermarks in the file
Removes an embedded file.
Index of the attachment in getAttachments.
Removes a listener, or every listener of the event when fn is omitted.
Event name.
Optionalfn: (...args: DocumentEvents[K]) => void
The function that was passed to addEventListener.
Deletes these pages (not all of them); annotations on them are deleted too
Page numbers (1-based) or range strings such as '5-7'. Throws a RangeError when a page does not exist; removing every page is rejected.
Waits for a page to be available. The whole document is loaded, so this resolves immediately.
Page number (1-based). Throws a RangeError when out of range.
Moves a queued render back to visible priority.
The id returned by loadCanvas.
Rotates clockwise by rotation (PageRotation, a multiple of 90°) on top of the existing rotation
Page numbers (1-based) or range strings.
Quarter turns clockwise to add, as a PageRotation value.
Sets the background (replacing the existing one): a solid color (color) or an image (image, RGBA pixels such as ImageData), placed under the page content
Either color ('#rrggbb') or image, plus optional opacity (1 by default), scale (1), rotation in degrees (0), alignment ('center'), offsets in points (0), page numbers (1-based, all pages when omitted), and whether it shows on screen and in print (both true by default).
Sets Bates numbering (replacing existing ones); <<#digits#start#prefix#suffix>> in the text, such as <<#6#1#ABC#>> giving ABC000001, ABC000002...
The texts by position, the margins in points (36 by default) and the page numbers (1-based) to apply to (all pages when omitted).
Sets the second item of the PDF trailer /ID; requires 32 hex characters, returns false when invalid, persisted on save when successful.
The new identifier: 32 hexadecimal characters.
A Promise that resolves to true when the identifier was set, or false when it is invalid.
Changes the file name reported by getFilename.
The new file name.
Sets headers / footers (replacing existing ones); <<1>> in the text is the page number from 1, <<1,3>> zero-padded to 3 digits
The texts by position, the margins in points (36 by default) and the page numbers (1-based) to apply to (all pages when omitted).
Writes back the tree given by getLayersArray (with visible / locked changed); when more than one is on in a radio group, the one just turned on compared with before is kept. Page bitmaps are invalidated and all rendered by the main Worker afterwards (render pool copies do not know this change); fires layersUpdated (DocumentViewer redraws pages from it)
The layer tree from getLayersArray with visible / locked changed.
Disables layers: the layer tree is not read (getLayersArray gives an empty array), pages and printing render by the engine default (layers hidden by default in the file stay hidden). Changing it invalidates page bitmaps and fires layersUpdated
False to disable layers, true to enable them again.
Overprint preview (OverprintPreviewMode), recorded in overprintMode of the rendering options; note: engine rendering does not simulate overprint
The overprint preview mode.
Sets this page's writing direction (ignored when not a TextDirection value); follows the page
Page number (1-based).
The text direction.
Sets passwords and permissions, written by getFileData (full rewrite). With only the user password, the owner password is the same; with neither, encryption is removed. Documents opened with the user password cannot change them (PERMISSION_DENIED)
Passwords and permissions.
OptionalownerPassword?: stringPassword required to change permissions; the user password is used when only that is given.
Optionalpermissions?: DocumentPermissionsPermissions granted to users who open the document with the user password.
OptionaluserPassword?: stringPassword required to open the document; empty for none.
const { documentViewer } = instance.Core;
const doc = documentViewer.getDocument();
await doc.setPassword({
userPassword: 'open-me',
ownerPassword: 'owner-secret',
permissions: {
printing: true,
highQualityPrinting: true,
copying: false,
documentChanges: false,
documentAssembly: false,
commenting: true,
formFilling: true,
},
});
const protectedFile = await doc.getFileData(); // passwords take effect in the saved file
Changes only permissions: reuses the passwords set by this setPassword (the engine writes permissions together with passwords; PERMISSION_DENIED when no password was set)
The permissions granted to users who open the document with the user password.
Text extraction processing options (an array of TextExtractorProcessingFlags, stored bitwise ORed). Note: engine text extraction (InitText) has no options, so they are only stored
TextExtractorProcessingFlags values to combine.
View watermark (set here by DocumentViewer.setWatermark, read when drawing); use addWatermark to write into the file
The view watermark, or null to remove it.
Watermark render quality. Watermarks are drawn as vectors, so only the value is stored.
A number greater than 0 and at most 10; throws otherwise.
Snaps a point to the nearest page geometry (see DocumentViewer.snapToNearest).
Page number (1-based).
Horizontal position in page coordinates.
Vertical position in page coordinates.
Snap modes to try, as SnapMode bit flags.
Search radius in page units (points).
A Promise that resolves to the snapped point; when nothing is in range the point is returned unchanged and mode is absent.
A listener that throws does not affect the others; the error is reported through logger.error.
Optionalargs: DocumentEvents[K]Like trigger, but awaits the Promise returned by each listener in turn; a failing listener does not affect the others.
Optionalargs: DocumentEvents[K]Releases the cached bitmaps of a page.
Page number (1-based).
Releases the cached bitmaps of every page.
Rendering options, merged with existing ones; note: engine rendering has no matching settings, so they are only stored. Returns true with a document
Options to merge into the stored rendering options.
Always true.
Verifies the digital signatures in the document: one result per signed signature field. Checks ByteRange and the signature container, digest and signature value, whether the certificate chain reaches trustedCertificates within validity, and whether changes after signing are allowed; unsaved modifications also count as changes after signing. Revocation is checked offline with OCSP responses and CRLs in the document DSS (enableLTVOfflineVerification, on by default); note: no online revocation checks (OCSP / CRL are not fetched over the network)
Optionaloptions: Core.VerificationOptions
Optional trustedCertificates, validationTime and enableLTVOfflineVerification.
A Promise that resolves to one result per signed signature field.
Static ReadonlyBlendBlend modes for the blendMode option of Document.compareDrawings.
Static ReadonlyEventsNames of the events this class triggers.
ReadonlyBOOKMARKS_UPDATED: "bookmarksUpdated"'bookmarksUpdated': bookmark page numbers may have changed.
ReadonlyCHANGE_PAGE_IDS: "changePageIds"'changePageIds': page numbers changed after pages were reordered.
ReadonlyCOLOR_SEPARATION_ADDED: "colorSeparationAdded"'colorSeparationAdded': color separation found a new ink.
ReadonlyDOCUMENT_COMPLETE: "documentComplete"'documentComplete': the page table has been fully read.
ReadonlyLAYERS_UPDATED: "layersUpdated"'layersUpdated': the layer tree or layer visibility changed.
ReadonlyPAGES_UPDATED: "pagesUpdated"'pagesUpdated': pages were added, removed, moved, rotated or changed.
Base class for objects that fire named events. Listener arguments are passed by position.