Class: Document

Core. Document

Represents a document.

new Document(id, type)

Constructs a new empty Document, representing a document with individual pages (canvases) that can be displayed on screen and printed.
Parameters:
Name Type Description
id string Unique string identifier for the document
type string The type of document that should be instantiated. Values are 'xod' for XOD documents, 'pdf' for PDF, JPG or PNG documents, 'office' for MS Office documents and 'webviewerServer' for WebViewer Server documents

Extends

Methods


<static> registerDocumentType(type, source, exposedFuncs)

Register new document type with Document class
Parameters:
Name Type Description
type string Name of the new document type
source any Class of the new document
exposedFuncs Array.<string> An array containing strings of the function names to expose on the document object
Returns:
Type
boolean

<static> unregisterDocumentType(type)

Unregister existing document type from Document class
Parameters:
Name Type Description
type string Name of registered document type
Returns:
Type
boolean

addEventListener(type, fn [, options])

Add a handler to the given event name
Parameters:
Name Type Argument Description
type string | number The name of the event to listen to
fn function The handler to be called when the event is triggered
options object <optional>
Optional options object for addEventListener
Properties
Name Type Description
once boolean If true then the handler will be called only once
Inherited From:
Returns:
Returns the object that 'addEventListener' is being called on
Type
object
Example
myObject.addEventListener('eventName', (eventParameter1, eventParameter2) => {
  ...
});

applyTemplateValues(templateValues)

[Office Document only] Update a Document via binding template keys to content.
Parameters:
Name Type Description
templateValues Core.TemplateData The template replacement values
See:
Returns:
Resolves when template data has been applied to the document, or rejects with an error
Type
Promise.<void>

arePagesAltered()

[PDF Document only] Check if the PDF Document has been altered with page modifications (Additions, deletions, rotations, crops).
Returns:
A boolean value indicating whether the PDF Document has been altered
Type
boolean

cancelLoadCanvas(id)

Cancels the loadCanvasAsync call corresponding to the passed in id
Parameters:
Name Type Description
id number The id returned from the loadCanvasAsync call that will be cancelled.

cancelLoadThumbnail(id)

Cancels the request made for thumbnail with the specified request Id
Parameters:
Name Type Description
id number The id returned from loadThumbnailAsync

cancelOfflineModeDownload()

Cancels a download for offline mode in progress. If there is no current download then this does nothing.

cropPages(pageArray, topMargin, botMargin, leftMargin, rightMargin)

[PDF Document only] Crop the given pages by the given margins. Note that this method will need to wait for the entire file to be downloaded before the change is applied.
Parameters:
Name Type Description
pageArray Array.<number> An array of page numbers to crop
topMargin number How much to crop from the top
botMargin number How much to crop from the bottom
leftMargin number How much to crop from the left
rightMargin number How much to crop from the right
Returns:
A promise that resolves to an object describing the updated state of the pages in the document
Type
Promise.<Core.Document.PageUpdateResult>

disableColorSeparations()

[PDF Document only] Disable the color separations feature for rendering.

disableOfflineMode()

[XOD Document only] Disable offline mode.

enableColorSeparations(options)

[PDF Document only] Enables the color separations feature for rendering. the boolean parameter is deprecated since version 8.0
Parameters:
Name Type Description
options Object The options parameter for color separation
Properties
Name Type Description
checkIfBaseColorsUsed boolean Check if the base colors Cyan, Magenta, Yellow and Black are actually used in the document, and if not, prevents the Document.colorSeparationAdded event from firing for one or more of those colors

enableOfflineMode()

[XOD Document only] Enable offline mode.

enableSeparation(name, enabled)

[PDF Document only] Enables or disables the rendering of a particular color separation.
Parameters:
Name Type Description
name string The name of the separation
enabled boolean Whether to enable or disable the separation

extractPages(pageArray [, xfdfString])

[PDF Document only] Extract the given pages from the document. Note that this method will need to wait for the entire file to be downloaded before the change is applied.
Parameters:
Name Type Argument Description
pageArray Array.<number> An array of the page numbers to extract
xfdfString string <optional>
Optional XFDF string to merge into the document before extracting
Returns:
A promise that resolves with an ArrayBuffer containing the extracted PDF data
Type
Promise.<ArrayBuffer>

extractPDFNetLayersContext(layers)

[PDF Document only][PDFNetJS full only] Get the updated context of a document as a PDFNet object.
Parameters:
Name Type Description
layers layers
Returns:
A promise that resolves to an id of a PDFNet Context object representing the current layers/OCG state.
Type
Promise.<string>

extractXFDF( [pages])

Gets the XFDF data for the document's internal annotations.
Parameters:
Name Type Argument Description
pages Array.<number> <optional>
An array of page numbers to get the XFDF data for the document. Note: Only one page is supported by XOD documents. For PDF documents if no parameter is passed then the XFDF data for the entire document is returned.
Returns:
A promise that resolves to an object with an xfdfString property and a pages property where pages is the array of page numbers that annotations were extracted from
Type
Promise.<Core.Document.XFDFInfo>

getAuthId()

[Server Document only] Get auth Id for current server document.
Returns:
The auth Id as a string
Type
string

getBookmarks()

Returns an array containing the bookmarks in the document.
Returns:
A promise resolving to an array containing the bookmarks in the current document.
Type
Promise.<Array.<Core.Bookmark>>

getClientId()

[Server Document only] Get client Id for current server document.
Returns:
The client Id as a string
Type
string

getColorSeparations()

[PDF Document only] Gets the color separations available on this document.
Returns:
The color separations of the document
Type
Array.<Core.Document.ColorSeparation>

getDocumentCompletePromise()

Returns:
A promise that resolves when all of the page information is available for the document
Type
Promise.<void>

getDocumentId()

Returns:
returns user defined document id passed in WebViewer constructor or loadDocument API, e.g. WebViewer({ documentId: 'foo-11', initialDoc: 'url' }) or instance.loadDocument(url, { documentId: 'foo-11' })
Type
string

[WebViewer Server only] Provides a URL to a the PDF with annotations and watermarks merged.
Parameters:
Name Type Argument Description
options Object <optional>
An optional object containing download options and parameters
Properties
Name Type Argument Description
filename string <optional>
The preferred name for the downloaded file on the client side. This has no effect on the backend target of the returned link, only the filename used by the browser when the link is accessed
Returns:
Will be null if not supported. Otherwise a promise that resolves to an object with a `url` property pointing to the printable PDF
Type
Promise.<{url: string}> | null

getFileData( [options])

[PDF/Office Document only] Asynchronously saves the document and provides the result as an ArrayBuffer. To include annotations in the saved document, please provide an object with the xfdfString property.
Parameters:
Name Type Argument Description
options Object <optional>
An optional object containing save options and parameters.
Properties
Name Type Argument Description
xfdfString string <optional>
An xfdf string containing annotation data to be used when saving. This will usually be retrieved by calling exportAnnotations on a Core.AnnotationManager object.
xfdfCommand string <optional>
An xfdf string containing annotation change commands to be applied to the document before saving. This will usually be retrieved by calling exportAnnotationCommand or exportDocumentAnnotationCommand on a Core.AnnotationManager object.
flatten boolean <optional>
A flag that is only useful when the xfdfString option is used. If true all the annotations in the saved document will be flattened.
finishedWithDocument boolean <optional>
A flag specifying that the document data may be discarded by the worker after use. Only use this when completely finished with document processing. When handling larger documents this can be useful to avoid memory exhaustion as only one copy of the document needs to be kept.
printDocument boolean <optional>
If true the saved document data will have an open action specifying that it should be printed. This is mostly only used to trigger print actions in the browser's PDF Viewer.
downloadType string <optional>
The file type to download as, where the default is the source type. PDF and image files can only be downloaded as PDFs, but office files can be downloaded as "pdf" or as "office" if you want to get the original file without annotations.
flags number <optional>
The flags with which to save the document. Possible values include Core.SaveOptions.REMOVE_UNUSED (remove unused objects during save) and Core.SaveOptions.LINEARIZED (optimize the document for fast web view and remove unused objects). The default value is Core.SaveOptions.REMOVE_UNUSED.
password string <optional>
A string representing a password. If a non-empty password is used, the PDF document will be encrypted.
encryptionAlgorithmType number <optional>
PDFNet.SecurityHandler.AlgorithmType = {
e_RC4_40 : 1
e_RC4_128 : 2
e_AES : 3
e_AES_256 : 4
}
The encryption algorithm identifier. The default value is set to Use Crypt filters with 256-bit AES (Advanced Encryption Standard) algorithm: 4. 40-bit RC4 algorithm: 1, 128-bit RC4 algorithm: 2, Use Crypt filters with 128-bit AES (Advanced Encryption Standard) algorithm: 3, Use Crypt filters with 256-bit AES (Advanced Encryption Standard) algorithm: 4.
includeAnnotations boolean <optional>
If false, all annotations will be removed from PDF document.
Returns:
a promise that resolves to an array buffer containing PDF document bytes.
Type
Promise.<ArrayBuffer>

getFilename()

Get the document filename used for downloading.
Returns:
Filename of the document
Type
string

getFileSize( [aggressionLevel])

Get the size of the document in bytes. Throws if the size cannot be found.
Parameters:
Name Type Argument Default Description
aggressionLevel number <optional>
2 Set the number of failed attempts to allow before throwing. Each attempt calls a method that may take slighly longer than the previous. The order of attempts are as follows: 1) Return the size immediately if we already have the data 2) Make a HEAD request to the server and attempt to read the 'content-length' header 3) Download the full document and return the size For example, setting aggressionLevel to 1 only tries the first method, setting it to 3 tries all the methods. The default is 2
Returns:
The number of bytes
Type
Promise.<number>

getLayersArray()

[PDF Document only] Get an array describing the layers/OCG structure in the document.
Returns:
A promise that resolves to an array representing the layers in the PDF document
Type
Promise.<Array.<Core.Document.LayerContext>>

getMetadata()

Returns an object with metadata associated with the document.
Returns:
A promise that resolves to an object with document metadata
Type
Promise.<Core.Document.Metadata>

getOfficeEditor()

For Office Editor Document, returns the OfficeEditor object. Otherwise, an error will be thrown.
Returns:
Type
Core.Document.OfficeEditor

getOfflineModeEnabled()

Returns whether offline mode is currently enabled or not.

getPageCount()

Returns the number of pages in a document.
Returns:
The number of the pages in the current document.
Type
number

getPageInfo(pageNumber)

Returns an object containing the width and height of a page.
Parameters:
Name Type Description
pageNumber number The page number of the requested page
Returns:
An object representing the page info. Contains the properties "width" and "height"
Type
Core.Document.PageInfo

getPageMatrix(pageNumber)

Returns an object representing the transformation matrix for the page.
Parameters:
Name Type Description
pageNumber number The page number of the requested page
Returns:
An object representing the page matrix
Type
Core.Math.Matrix

getPageRotation(pageNumber)

Returns the internal degrees of rotation of a page.
Parameters:
Name Type Description
pageNumber number The page number of the requested page
Returns:
The internal degrees of rotation of a page (0, 90, 180 or 270)
Type
number

getPageTextDirection(pageNum)

Gets the text direction for a specific page. Call this method after the page text has been loaded. See Core.Document#pageTextLoaded event for when the text is loaded.
Parameters:
Name Type Description
pageNum number The page number to get the text direction for
Returns:
The text direction for the specified page
Type
Core.TextDirection
Example
instance.Core.documentViewer.getDocument().addEventListener('pageTextLoaded', (pageNumber, text) => {
  const textDirection = instance.Core.documentViewer.getDocument().getPageTextDirection(pageNumber);
  ...
});

getPDFCoordinates(pageNumber, x, y)

Returns an object with the original x and y coordinates converted to PDF coordinates for the page.
Parameters:
Name Type Description
pageNumber number The page number that the coordinates are on
x number The x coordinate
y number The y coordinate
Returns:
An object with the x and y PDF coordinates
Type
Object

getPDFDoc()

Returns the PDFNet.PDFDoc object associated with the document. Note that the full API is required to be enabled and WebViewer Server cannot be enabled.
Returns:
A promise that resolves to the PDFDoc object.
Type
Promise.<Core.PDFNet.PDFDoc>

getPrintablePDF()

[WebViewer Server only] Provides a URL to a the PDF with annotations and watermarks merged, and an open action specifying that it should be printed.
Returns:
Will be null if not supported. Otherwise a promise that resolves to an object with a `url` property pointing to the printable PDF
Type
Promise.<{url: string}> | null

getSpreadsheetEditorDocument()

For spreadsheet editor documents this returns the SpreadsheetEditorDocument instance. Otherwise undefined is returned.
Returns:
Type
Core.SpreadsheetEditorDocument

getTemplateKeys( [format])

[Office Document only] Provides information about the template keys present in the document. Must have loaded the document with officeOptions.doTemplatePrep, officeOptions.templateOptions, officeOptions.templateValues, or called setTemplateValues before calling this function.
Parameters:
Name Type Argument Description
format 'flat' | 'schema' | 'locations' <optional>
Specifies what type of information to return. Defaults to 'flat'. 'flat' returns a list of all top-level keys used in the document. Keys used in loop bodies are not included in this list, however, this may change in the future. 'schema' returns a detailed schema of the keys used in the document, containing information such as the inferred type of key data. 'locations' returns a collection of the bounding boxes of template content in the document. If the template document has been prepped but not filled (doTemplatePrep or templateOptions option has been set), it will return bounding boxes for the template tag text. If the template document has been filled (applyTemplateValues has been called), it will return bounding boxes for the inserted content
Returns:
A promise that resolves to the requested data
Type
Promise.<(Array.<string>|Core.TemplateSchema|Core.TemplateBoundingBoxes)>

getTextByPageAndRect(pageNumber, rect)

It returns the text that is within the Rect on the given page
Parameters:
Name Type Description
pageNumber number The page number that the rect is on
rect Core.Math.Rect A Rect with x1,y1 representing the top-left and x2,y2 representing the bottom-right
Returns:
A promise that resolves to the extracted text
Type
Promise.<string>

getTextPosition(pageNumber, textStartIndex, textEndIndex)

Gets quads for each of the characters from start to end index.
Parameters:
Name Type Description
pageNumber number The page number that the text is on
textStartIndex number The position where to start getting character quads from
textEndIndex number The position (up to, but not including) where to finish getting characters
Returns:
Resolves with quads, which is an array of quad objects with properties x1, y1, x2, y2, x3, y3, x4, y4
Type
Promise.<Array.<Core.Math.Quad>>

getType()

Gets the type of the document.
Returns:
The type of the document (xod, pdf, office, webviewerServer)
Type
string

getViewerCoordinates(pageNumber, x, y)

Returns an object with the original x and y PDF coordinates converted to Viewer coordinates for the page.
Parameters:
Name Type Description
pageNumber number The page number that the coordinates are on
x number The x coordinate
y number The y coordinate
Returns:
An object with the x and y Viewer coordinates
Type
Object

getXODCoordinates(pageNumber, x, y)

Returns an object with the original x and y PDF coordinates converted to XOD coordinates for the page.
Parameters:
Name Type Description
pageNumber number The page number that the coordinates are on
x number The x coordinate
y number The y coordinate
Returns:
An object with the x and y XOD coordinates
Type
Object

includesThumbnails()

Used to know if a document contains thumbnails.
Returns:
True if the document contains thumbnails.
Type
boolean

initOfflineDB()

[XOD Document only] Initializes the offline database for use. Must be called before any other offline mode functions are used.
Returns:
Resolves when offline database is ready for use.
Type
Promise.<void>

insertBlankPages(insertBeforeThesePages, width, height)

[PDF Document only] Inserts blank pages before the given list of pages. Both width and height are in units of PDF points.
Parameters:
Name Type Description
insertBeforeThesePages Array.<number> Array of page numbers before which to insert blanks
width number Width of the blank pages to insert. By default the width is 612 PDF points
height number Height of the blank pages to insert. By default the height is 792 PDF points
Returns:
A promise that resolves to an object with info for any pages inserted
Type
Promise.<Core.Document.PageUpdateResult>

insertPages(sourceDocument [, pageArray] [, insertBeforeThisPage])

[PDF Document only] Inserts a set of pages from the provided Document before a given page number. Note that this method will need to wait for the entire file to be downloaded before the change is applied.
Parameters:
Name Type Argument Description
sourceDocument Core.Document Other document from which to take pages (cannot be the same document)
pageArray Array.<number> <optional>
An optional array of page numbers to extract from the given document. If not passed in, will insert all pages
insertBeforeThisPage number <optional>
An optional page number before which to insert the pages. If not passed in, will append to the end
Returns:
A promise that resolves to an object describing the updated state of the pages in the document
Type
Promise.<Core.Document.PageUpdateResult>

isDownloaded()

[XOD Document only] Whether the document has already been downloaded for offline mode or not.

isLinearized()

[PDF Document only] Returns whether the document is linearized or not. Note that this only works for documents that are loaded by URL and if useDownloader is not set to false.
Returns:
Whether the document is linearized or not
Type
boolean

isWebViewerServerDocument()

Gets whether the document will be interacted with as a WebViewer Server document This will return false if the document was loaded from WebViewer Server but forceClientSideInit is set to true
Returns:
Returns whether the document will be interacted with as a WebViewer Server document.
Type
boolean

loadAsync(partRetriever, callback, options)

Initialize a Document so that it can be used to load page canvases.
Parameters:
Name Type Description
partRetriever Core.PartRetrievers.PartRetriever An instance of PartRetriever
callback Core.Document.LoadAsyncCallback
options Object An object that can contain the following optional parameters
Properties
Name Type Argument Description
workerTransportPromise Promise.<any> <optional>
Required to load a PDF or Office file. A promise that will be resolved when a worker transport has been initialized. This can be created by calling Core.initPDFWorkerTransports or Core.initOfficeWorkerTransports as appropriate
getPassword Core.Document.GetPasswordCallback <optional>
A method that will be called when a password is required to load a PDF document. It receives a callback that should be called with the retrieved password
extension string <optional>
A field used to specify the type of file being read. This is only relevant for PDF viewing and at the moment only works for certain image formats and .pdf
customHandlerId number <optional>
A field used to specify PDFTron custom security handler. Its value needs to be an integer in [0, 0xFFFFFFFF]
Returns:
Resolves when document is initialized, or rejects with error
Type
Promise.<void>

loadCanvas(options)

Loads a canvas for a particular page number.
Parameters:
Name Type Description
options Object An object specifying the options for loading the canvas. The following parameters should be properties on this object. The only non-optional parameter is pageNumber
Properties
Name Type Argument Description
pageNumber number The page number of the requested canvas
zoom number <optional>
The zoom value to render the page at
getZoom Core.Document.GetZoomCallback <optional>
A function that returns the zoom value to render the page at. Use this instead of "zoom" if the value might change in the process of setting up the canvas
pageRotation Core.PageRotation <optional>
The rotation of the page. Valid values are Core.PageRotation.E_0, Core.PageRotation.E_90, Core.PageRotation.E_180, Core.PageRotation.E_270
getPageRotation Core.Document.GetPageRotationCallback <optional>
A function that returns the rotation of the page. Use this instead of "pageRotation" if the value might change in the process of setting up the canvas
finishedLoading Core.Document.FinishedLoadingCallback <optional>
A callback called after the list of page resources is retrieved. Return true if rendering should continue, false otherwise
acquireResources Core.Document.AcquireResourcesCallback <optional>
A function that returns whether resources need to be acquired or not, defaults to true
resourcesLoaded Core.Document.ResourcesLoadedCallback <optional>
A callback called after the page's resources have been loaded. Return true if rendering should continue, false otherwise
getPageTransform Core.Document.GetPageTransformCallback <optional>
A function that returns the x and y values of the page's translation
drawComplete Core.Document.DrawCompleteCallback <optional>
The callback to call when the canvas has been completely rendered. The first parameter is a canvas object, but if an image document is loaded this will return an image. The second parameter is the page number
drawProgressive Core.Document.DrawProgressiveCallback <optional>
The callback to call when the canvas has been partially rendered
renderRect Object <optional>
An object with x1, y1, x2, y2 properties which is the partial rectangle to render of the entire page. The top left of the page is (0, 0)
useProgress boolean <optional>
Whether progressive rendering should be used or not
height number <optional>
Used to calculate the zoom level if zoom level is not provided. If it's passed the zoom level will be set so the document fits this height. If both width and height are passed the zoom level will be set so the document fits the box delimited by them
width number <optional>
Used to calculate the zoom level if zoom level is not provided. If it's passed the zoom level will be set so the document fits this width. If both width and height are passed the zoom level will be set so the document fits the box delimited by them
multiplier number <optional>
The quality of the loaded canvas. Must be a positive number. Higher values are higher quality but take longer to complete and use more memory
source string <optional>
Indicate the origin of the call. This may be used by the Document's implementation of loadCanvasAsync
allowUseOfOptimizedThumbnail boolean <optional>
Whether to allow the use of optimized thumbnails
Returns:
An id that can be passed to the corresponding Pause, Resume or Cancel functions
Type
string

loadPageText(pageNumber)

Gets all the text on the requested page.
Parameters:
Name Type Description
pageNumber number The page number that the text is on
Returns:
A promise that resolves with the page's text
Type
Promise.<string>

loadThumbnail(pageNumber, onLoadThumbnail)

Loads a thumbnail image for a particular page.
Parameters:
Name Type Description
pageNumber number The page number of the requested thumbnail (1-indexed)
onLoadThumbnail Core.Document.LoadThumbnailCallback The callback to call when the thumbnail has been retrieved. Accepts an HTMLImageElement or HTMLCanvasElement as a parameter. It is passed an image element if the .xod file contains thumbnails and a canvas element otherwise
Returns:
The id of the request that can later be used for cancelling the request
Type
string

mergeDocument(source [, position])

[PDF Document only] Merge a file into the currently opened document
Parameters:
Name Type Argument Description
source string | File | ArrayBuffer | Blob Source parameter, path/url to document or File.
position number <optional>
Optional position for where to merge the document, default to end of file if nothing entered
Returns:
A promise that resolves on completion
Type
Promise.<Core.Document.PageUpdateResult>

movePages(pageArray, insertBeforeThisPage)

[PDF Document only] Moves the pages given in an array so they appear in sequence before a given page number. Note that this method will need to wait for the entire file to be downloaded before the change is applied.
Parameters:
Name Type Description
pageArray Array.<number> The page numbers to move
insertBeforeThisPage number Page number before which to insert the other pages
Returns:
A promise that resolves to an object describing the updated state of the pages in the document
Type
Promise.<Core.Document.PageUpdateResult>

pauseLoadCanvas(id)

Pauses the loadCanvasAsync call corresponding to the passed in id
Parameters:
Name Type Description
id number The id returned from the loadCanvasAsync call that will be paused.

refreshTextData()

Refresh the text data stored by the viewer. Useful if the text content of the document has changed, e.g. after a redaction.

removeEventListener( [type] [, fn])

Remove a handler of the given event name and namespace (if given) or with a function reference
Parameters:
Name Type Argument Description
type string | number <optional>
The name of the event to remove the handler of with an optional namespace.
fn function <optional>
The handler associated with this event to be removed. If fn is undefined, all the handlers of the given event namespace will be removed. If you are not passing in this parameter then a namespace must be used with the event name.
Inherited From:
Returns:
Returns the object that 'removeEventListener' is being called on
Type
object
Example
myObject.removeEventListener('eventName.namespace');
myObject.removeEventListener('eventName', fn);

removePages(pageArray)

[PDF Document only] Removes the given page numbers. Note that this method will need to wait for the entire file to be downloaded before the change is applied.
Parameters:
Name Type Description
pageArray Array.<number> The page numbers to remove
Returns:
A promise that resolves to an object describing the updated state of the pages in the document
Type
Promise.<Core.Document.PageUpdateResult>

requirePage(pageNumber)

[PDF Document only] Ensures that a particular page of the pdf document is finished loading before reading, writing or rendering it.
Parameters:
Name Type Description
pageNumber number The page number to ensure completion of loading
Returns:
A promise that resolves when the page has been loaded
Type
Promise.<void>

resumeLoadCanvas(id)

Resumes the loadCanvasAsync call corresponding to the passed in id
Parameters:
Name Type Description
id number The id returned from the loadCanvasAsync call that will be resumed.

rotatePages(pageArray, rotation)

[PDF Document only] Adds the given rotation to the given pages. Note that this method will need to wait for the entire file to be downloaded before the change is applied.
Parameters:
Name Type Description
pageArray Array.<number> An array of the numbers of pages to rotate
rotation Core.PageRotation The page rotation to add
Returns:
A promise that resolves to an object describing the updated state of the pages in the document
Type
Promise.<Core.Document.PageUpdateResult>

setFilename(filename)

Set the document filename used for downloading.
Parameters:
Name Type Description
filename string Filename of the document

setLayersArray(layersArray)

[PDF Document only] Update the array describing the layers/OCG structure in order to adjust which layers should be enabled or disabled. The layers updated event is triggered as a side effect
Parameters:
Name Type Description
layersArray Array.<Core.Document.LayerContext> The OCG layers to set

setOverprintPreviewMode(mode)

[PDF Document only] Set the overprint preview mode to be used when rendering this document.
Parameters:
Name Type Description
mode The mode to use. Possible values are Core.OverprintPreviewMode.OFF, Core.OverprintPreviewMode.ON and Core.OverprintPreviewMode.PDFX_ON

setPageTextDirection(pageNum, textDirection)

Sets the text direction for a specific page.
Parameters:
Name Type Description
pageNum number The page number to set the text direction for
textDirection Core.TextDirection The text direction to set (e.g., left-to-right or right-to-left)

setTextExtractorProcessingFlags(flags)

Sets the flags with which to extract the text from a PDF document.
Parameters:
Name Type Description
flags Array.<number> The flags with which to extract the text from a PDF document. See Core.TextExtractorProcessingFlags

setWatermark(options)

Sets watermark to be added to the document
Parameters:
Name Type Description
options Core.Document.WatermarkOptions Object that contains style/content of the watermark
Example
doc.setWatermark({
  diagonal: {
    fontSize: (number),
    fontFamily: (string),
    color: (string),
    opacity: (number (between 0 and 100)),
    text: (string)
  },
  header: {
    fontSize: (number),
    fontFamily: (string),
    color: (string),
    opacity: (number (between 0 and 100)),
    left: (string),
    center: (string),
    right: (string)
  },
  footer: {
    fontSize: (number),
    fontFamily: (string),
    color: (string),
    opacity: (number (between 0 and 100)),
    left: (string),
    center: (string),
    right: (string)
  }
  custom: (function(ctx, pageIndex, pageWidth, pageHeight))
});

To allow more customization of the header/footer, the following can be done:

doc.setWatermark({
diagonal: {
  fontSize: (number),
  fontFamily: (string),
  color: (string),
  opacity: (number (between 0 and 100)),
  text: (string)
},
headerLeft: {
  fontSize: (number),
  fontFamily: (string),
  color: (string),
  opacity: (number (between 0 and 100)),
  text: (string)
},
headerCenter: {
  fontSize: (number),
  fontFamily: (string),
  color: (string),
  opacity: (number (between 0 and 100)),
  text: (string)
},
headerRight: {
  fontSize: (number),
  fontFamily: (string),
  color: (string),
  opacity: (number (between 0 and 100)),
  text: (string)
},
footerLeft: {
  fontSize: (number),
  fontFamily: (string),
  color: (string),
  opacity: (number (between 0 and 100)),
  text: (string)
},
footerCenter: {
  fontSize: (number),
  fontFamily: (string),
  color: (string),
  opacity: (number (between 0 and 100)),
  text: (string)
},
footerRight: {
  fontSize: (number),
  fontFamily: (string),
  color: (string),
  opacity: (number (between 0 and 100)),
  text: (string)
},
custom: (function(ctx, pageIndex, pageWidth, pageHeight))
});

setWatermarkRenderQuality(multiplier)

Sets the render quality multiplier for watermark rasterization when embedded printing or downloading. This setting does not affect how the watermark appears in the viewer — it only applies to printed or downloaded output.
Parameters:
Name Type Description
multiplier number A scaling factor for the internal canvas used in watermark rendering. For example, 2 doubles the resolution. Must be between 1 and 10. The default value is 1, which means no scaling.

storeOffline(onComplete, onProgress)

[XOD Document only] Downloads the document for offline viewing.
Parameters:
Name Type Description
onComplete Core.Document.DownloadCompleteCallback The function that's called when the document has finished being downloaded or the download has been cancelled
onProgress Core.Document.DownloadProgressCallback The function that's called on each update in progress of the download. The fraction downloaded is passed as a parameter (eg 50% downloaded passes 0.5)

submitRedactions(annotations, docViewer)

[WebViewer Server only] Apply redaction using WebViewer Server and return a promise when finished
Parameters:
Name Type Description
annotations Annotations.Annotation | Array.<Annotations.Annotation> An array of redaction annotations or a single redaction annotation to apply
docViewer Core.DocumentViewer
Returns:
Will be null if not supported. Otherwise a promise that resolves to an object with a `url` property pointing to the redacted PDF
Type
Promise.<{url: string}> | null

trigger(type [, data])

Calls the handlers of the event name with given data
Parameters:
Name Type Argument Description
type string | number event name of which the handlers will be called.
data * <optional>
data that will be passed to the handlers. If data is an array, it will be spread and then passed to the handlers
Inherited From:
Returns:
Returns the object that 'trigger' is being called on
Type
object
Example
myObject.trigger('eventName');
myObject.trigger('eventName', [eventParameter1, eventParameter2]);

triggerAsync(type [, data])

Calls the handlers of the event name with given data *asynchronously*. It's different from Core.EventHandler#trigger in that it can be awaited to ensure all async handlers have finished executing code
Parameters:
Name Type Argument Description
type string | number event name of which the handlers will be called.
data * <optional>
data that will be passed to the handlers. If data is an array, it will be spread and then passed to the handlers
Inherited From:
Returns:
Returns the object that 'triggerAsync' is being called on
Type
Promise.<Object>
Example
myObject.triggerAsync('eventName');
myObject.triggerAsync('eventName', [eventParameter1, eventParameter2]);

unloadCanvasResources(id)

Unloads resources for the page associated with the loadCanvasAsync call corresponding to the passed in id. So if the loadCanvasAsync call had requested page 2 then page 2's resources will be cleaned up (as long as nothing else requires those resources). Note that the canvas element itself is not touched.
Parameters:
Name Type Description
id number The id returned from the loadCanvasAsync call that will have it's page resources unloaded

unloadResources()

Cleans up the resources associated with the document.

updateCustomHeaders(headers)

Updates the custom headers for the document requests. These headers can be updated even after the document has been loaded.
Parameters:
Name Type Description
headers Object.<string, string> The headers to update or add to the document requests

updateRasterizerOptions(options)

Update rasterizer options of the document
Parameters:
Name Type Description
options Object Options for this function
Properties
Name Type Argument Default Description
pageTransparent boolean <optional>
false Page background transparency
overprintMode number <optional>
Core.OverprintPreviewMode.PDFX_ON Enable or disable support for overprint and overprint simulation
antiAliasing boolean <optional>
true Enable or disable anti-aliasing
pathHinting boolean <optional>
true Enable or disable path hinting
thinLinePixelGridFit boolean <optional>
false If true (horizontal/vertical) thin lines will be snapped to integer pixel positions
thinLineStrokeAdjust boolean <optional>
true Enable or disable auto stroke adjustment
thinLineScaling number <optional>
1.0 Controls the thickness of zero-width lines when rendered. Default is 1.0
nightModeTuningContrast number <optional>
Controls the contrast for night mode rendering. Values range from 0.0 to 1.0. By default, night mode tuning is off. If contrast is specified, saturation defaults to 0.8, flipness to 1.0
nightModeTuningSaturation number <optional>
Controls the saturation for night mode rendering. Values range from 0.0 to 1.0. By default, night mode tuning is off. If saturation is specified, contrast defaults to 0.9, flipness to 1.0
nightModeTuningFlipness number <optional>
Controls the inversion of colors for night mode rendering. Values range from 0.0 to 1.0. By default, night mode tuning is off. If flipness is specified, contrast defaults to 0.9, saturation to 0.8
imageSmoothing boolean <optional>
true Enable or disable image smoothing
hqImageResampling boolean <optional>
false Whether use a higher quality (but slower) smoothing algorithm
caching boolean <optional>
true Enables or disables caching. Caching can improve the rendering performance in cases where the same page will be drawn multiple times
expGamma number <optional>
-1.0 The gamma factor used for anti-aliased rendering. It is the exponent value of gamma function. Typical values are in the range from 0.1 to 3
colorPostProcessMode number <optional>
Core.ColorPostProcessMode.NONE Set the color post processing transformation. This transform is applied to the rasterized bitmap as the final step in the rasterization process, and is applied directly to the resulting bitmap (disregarding any color space information). Note that this option has no effect when using Core.OverprintPreviewMode.SEPARATION_RENDER
renderAnnots boolean <optional>
false Enable or disable annotation and forms rendering (In the viewer, annotation rendering is done separately)
highlightFields boolean <optional>
false Enable or disable highlighting form fields. This option only has an effect when renderAnnots is true
isPrinting boolean <optional>
false Tells the rasterizer to render the page 'print' mode. Certain page elements (such as annotations or OCG-s) are meant to be visible either on the screen or on the printed paper but not both. A common example, is the "Submit" button on electronic forms
Returns:
Returns true if document can update rasterizer options
Type
boolean

Type Definitions


AcquireResourcesCallback()

Callback function that returns whether resources need to be acquired
Returns:
Whether resources need to be acquired or not
Type
boolean

AppearanceReferencesType

An object describing appearance data
Type:
  • Object
Properties:
Name Type Argument Description
id string <optional>
The ID of the appearance
objnum string The object number of the appearance
gennum string The generation number from the appearance document
annotationState string The state of the annotation associated with the appearance
appearanceState string The state of the appearance itself
blendMode string The blend mode of the appearance
appearanceString Core.Document.AppearanceStringType <optional>

AppearanceStringType

An object describing the appearance string data for an annotation or page element
Type:
  • Object
Properties:
Name Type Description
dataString string The data string associated with an appearance
w number The width of the appearance
h number The height of the appearance

ColorSeparation

Type:
  • Object
Properties:
Name Type Description
color Array.<number> An array containing the CMYK color values (4 numbers: Cyan, Magenta, Yellow, Black)
name string The name of the color separation
rgb Array.<number> An array containing the R, G and B values for the separation
enabled boolean Whether the separation is enabled for rendering

DownloadCompleteCallback()

Callback function called when download is complete

DownloadProgressCallback(fractionDownloaded)

Callback function called on download progress
Parameters:
Name Type Description
fractionDownloaded number The fraction of the document downloaded (e.g., 0.5 for 50%)

DrawCompleteCallback(canvas, pageNumber)

Callback function called when canvas rendering is complete
Parameters:
Name Type Description
canvas HTMLCanvasElement | HTMLImageElement The rendered canvas or image element
pageNumber number The page number that was rendered

DrawProgressiveCallback(canvas)

Callback function called when canvas is partially rendered
Parameters:
Name Type Description
canvas HTMLCanvasElement The partially rendered canvas

FinishedLoadingCallback()

Callback function called after page resources are retrieved
Returns:
Return true if rendering should continue, false otherwise
Type
boolean

GetPageRotationCallback()

Callback function that returns the page rotation
Returns:
The rotation of the page
Type
Core.PageRotation

GetPageTransformCallback()

Callback function that returns the page transform values
Returns:
The x and y values of the page's translation
Type
Object

GetPasswordCallback(passwordCallback)

Callback function to retrieve password for encrypted documents
Parameters:
Name Type Description
passwordCallback Core.Document.PasswordCallback Callback to call with the retrieved password

GetZoomCallback()

Callback function that returns the zoom value
Returns:
The zoom value
Type
number

LayerContext

Type:
  • object
Properties:
Name Type Description
obj string the unique identifier of the layer. This is not defined if the layer is a label
name string the name of the layer. It does not have not be unique
locked boolean boolean to denote if the layer is locked for viewing. This state cannot be toggled by the user through the user interface
visible boolean boolean to denote if the layer is visible
children Array.<Core.Document.LayerContext> the layer's children (if any). This is not defined if the layer is a label.

LoadAsyncCallback( [error])

The callback to call when the Document has been initialized. If there is an error then an error object will be passed to the callback function.
Parameters:
Name Type Argument Description
error Error <optional>
The error that occurs when initializing the document

LoadThumbnailCallback(thumbnail)

Callback function called when thumbnail is loaded
Parameters:
Name Type Description
thumbnail HTMLImageElement | HTMLCanvasElement The thumbnail image or canvas element

Metadata

Type:
  • Object
Properties:
Name Type Argument Description
title string <optional>
The document title
creator string <optional>
The application that created the document
subject string <optional>
The document subject
keywords string <optional>
The document keywords
description string <optional>
The document description
application string <optional>
The application name
producer string <optional>
The application that produced the document
header string <optional>
The PDF header version
created string <optional>
The creation date
modified string <optional>
The modification date

OfficeEditorCursorStyle

Type:
  • Object
Properties:
Name Type Argument Description
paragraphProperties Object <optional>
The properties of the paragraph
Deprecated:
  • This object is deprecated. Use `Core.Document.OfficeEditor.SelectionStyle` instead.

OfficeEditorParagraphStyle

Type:
  • Object
Properties:
Name Type Argument Description
paragraphTextStyle any <optional>
The text style of the paragraph.
justification Object <optional>
The justification of the paragraph.
lineHeight number <optional>
The line height of the paragraph.
listType Object <optional>
The list type of the paragraph.
lineHeightMultiplier number <optional>
The line height multiplier of the paragraph.
Deprecated:
  • This object is deprecated. Use `Core.Document.OfficeEditor.SelectionStyle` instead.

OfficeEditorSelectionStyle

Type:
  • Object
Properties:
Name Type Argument Description
paragraphProperties Object <optional>
The properties of the paragraph
Deprecated:
  • This object is deprecated. Use `Core.Document.OfficeEditor.SelectionStyle` instead.

PageData

Type:
  • Object
Properties:
Name Type Argument Description
rotation number The rotation of the page (0, 1, 2, or 3 representing 0°, 90°, 180°, 270°)
width number | null The width of the page in points, or null if not available
height number | null The height of the page in points, or null if not available
matrix Array.<number> The transformation matrix for the page [a, b, c, d, e, f]
linkAnnotCount number The number of link annotations on the page
otherExceptPopupAnnotCount number The number of non-link, non-popup annotations on the page
id string The unique identifier for the page
contentChanged boolean <optional>
Whether the page content has changed
annotationsUnchanged boolean <optional>
Whether the annotations remain unchanged

PageInfo

Type:
  • Object
Properties:
Name Type Description
width number The width of the page
height number The height of the page

PageUpdateResult

Type:
  • Object
Properties:
Name Type Description
pageDimensions Object.<string, Core.Document.PageData> An object mapping page numbers (as strings) to their page data properties

PasswordCallback(password)

Callback for submitting a password
Parameters:
Name Type Description
password string The password to try

ResourcesLoadedCallback()

Callback function called after page resources have been loaded
Returns:
Return true if rendering should continue, false otherwise
Type
boolean

WatermarkHeaderFooterStyle

Type:
  • Object
Properties:
Name Type Argument Description
fontSize number <optional>
Font size for the header/footer text
fontFamily string <optional>
Font family for the header/footer text
color string <optional>
Color for the header/footer text
opacity number <optional>
Opacity for the header/footer text (between 0 and 100)
left string <optional>
Text for the left section
center string <optional>
Text for the center section
right string <optional>
Text for the right section

WatermarkOptions

Type:
  • Object
Properties:
Name Type Argument Description
diagonal Core.Document.WatermarkTextStyle <optional>
Diagonal watermark settings
header Core.Document.WatermarkHeaderFooterStyle <optional>
Header watermark settings
footer Core.Document.WatermarkHeaderFooterStyle <optional>
Footer watermark settings
headerLeft Core.Document.WatermarkTextStyle <optional>
Header left section watermark settings
headerCenter Core.Document.WatermarkTextStyle <optional>
Header center section watermark settings
headerRight Core.Document.WatermarkTextStyle <optional>
Header right section watermark settings
footerLeft Core.Document.WatermarkTextStyle <optional>
Footer left section watermark settings
footerCenter Core.Document.WatermarkTextStyle <optional>
Footer center section watermark settings
footerRight Core.Document.WatermarkTextStyle <optional>
Footer right section watermark settings
custom Core.Document.WatermarkRenderCallback <optional>
Custom watermark rendering function

WatermarkRenderCallback(ctx, pageIndex, pageWidth, pageHeight)

Custom watermark rendering function
Parameters:
Name Type Description
ctx CanvasRenderingContext2D The canvas rendering context
pageIndex number The page index (0-based)
pageWidth number The width of the page
pageHeight number The height of the page

WatermarkTextStyle

Type:
  • Object
Properties:
Name Type Argument Description
fontSize number <optional>
Font size for the watermark text
fontFamily string <optional>
Font family for the watermark text
color string <optional>
Color for the watermark text
opacity number <optional>
Opacity for the watermark text (between 0 and 100)
text string <optional>
The text content for the watermark

XFDFInfo

Type:
  • Object
Properties:
Name Type Description
xfdfString string The XFDF string
pages Array.<number> Array of page numbers that annotations were extracted from

Events


colorSeparationAdded

Triggered when a color separation is loaded and available on the document.
Parameters:
Name Type Description
colorData Core.Document.ColorSeparation An object with properties of the color separation

layersUpdated

Triggered when a document's layers/OCG structures change visibility.
Parameters:
Name Type Description
layerContext Array.<Core.Document.LayerContext> array of page layers

pageTextLoaded

Triggered when the text of a page is loaded for the first time.
Parameters:
Name Type Description
pageNumber number The page number of the page whose text was loaded.
text string The text of the page that was loaded.