Namespace: PSPDFKit

PSPDFKit

The main PSPDFKit namespace is exported in the global PSPDFKit.

Classes

Namespaces

Members

Methods

Type Definitions




Members

(static, readonly) AnnotationsWillChangeReason

Indicates the reason why PSPDFKit.AnnotationsWillChangeEvent was emitted.

Properties:
Name Type Description
DRAW_START PSPDFKit.AnnotationsWillChangeReason

The user starts drawing an annotation.

DRAW_END PSPDFKit.AnnotationsWillChangeReason

The user stops drawing an annotation.

TEXT_EDIT_START PSPDFKit.AnnotationsWillChangeReason

The user starts typing text into an annotation.

TEXT_EDIT_END PSPDFKit.AnnotationsWillChangeReason

The user stops typing text into an annotation.

SELECT_START PSPDFKit.AnnotationsWillChangeReason

The user starts choosing an item from the picker presented.

Used for image annotations, stamp annotations and ink signature annotations.

Note that the annotation included in this event will not have any matching field values (including ID) compared to the annotation in a PSPDFKit.AnnotationsWillChangeReason.SELECT_END event. This is because the actual annotation hasn't been created yet. As a result, this annotation is used only to identify the type of annotation being selected. The only exception to this is the inkSignature field in a PSPDFKit.Annotations.InkAnnotation, which is set to true to distiguish it from a regular ink annotation.

SELECT_END PSPDFKit.AnnotationsWillChangeReason

The user stops choosing an item from the picker presented.

Used for image annotations, stamp annotations and ink signature annotations.

Note: An empty PSPDFKit.AnnotationsWillChangeEvent#annotations list indicates that the selection was cancelled.

Note that this will not be fired when cancelling the system dialog for selecting an image, because there is no way to detect when this occurs.

MOVE_START PSPDFKit.AnnotationsWillChangeReason

The user starts moving an annotation around.

MOVE_END PSPDFKit.AnnotationsWillChangeReason

The user stops moving an annotation around.

RESIZE_START PSPDFKit.AnnotationsWillChangeReason

The user starts resizing an annotation.

RESIZE_END PSPDFKit.AnnotationsWillChangeReason

The user stops resizing an annotation.

DELETE_START PSPDFKit.AnnotationsWillChangeReason

The user initiates the delete process. This will be emitted when the deletion confirmation dialog appears.

DELETE_END PSPDFKit.AnnotationsWillChangeReason

The user ends the delete process. This will be emitted when the user confirms or cancels the intention to delete an annotation.

An empty PSPDFKit.AnnotationsWillChangeEvent#annotations list indicates that the deletion was cancelled.

PROPERTY_CHANGE PSPDFKit.AnnotationsWillChangeReason

The value of one of the properties of the annotation is changed by the user. e.g. the color or the stroke width.

(static, readonly) AutoSaveMode

When working with annotations and form field values, there are multiple options when the data can get saved. The AutoSaveMode controls this behavior.

Properties:
Name Type Description
IMMEDIATE PSPDFKit.AutoSaveMode

Saves immediately whenever an attribute of the annotation changed, or whenever a form field value got updated.

INTELLIGENT PSPDFKit.AutoSaveMode

Saves annotations automatically, when the user finishes editing an annotation. For form fields, this behaves like PSPDFKit.AutoSaveMode.IMMEDIATE.

DISABLED PSPDFKit.AutoSaveMode

Never saves annotations or form field values automatically. Annotations and form field values can still be saved via PSPDFKit.Instance#saveAnnotations or PSPDFKit.Instance#saveFormFieldValues

In this mode, document signatures validation information will not be automatically updated if the document is modified, until changes are saved.

(static, readonly) CertificateChainValidationStatus

The different possible validation states of the certificate chain.

Properties:
Name Type Description
ok PSPDFKit.CertificateChainValidationStatus

The certificate chain validates correctly.

ok_but_self_signed PSPDFKit.CertificateChainValidationStatus

The certificate chain contains a self-signed certificate.

untrusted PSPDFKit.CertificateChainValidationStatus

The certificate chain contains a certificate that has been classified as "untrusted".

The certificate date is correct, but the identity is unknown because it has not been included in the list of trusted certificates and none of its parents are trusted certificates.

expired PSPDFKit.CertificateChainValidationStatus

The certificate used to sign the document has expired now. Note that the certificate may be valid at the time the document was signed, which is not checked.

not_yet_valid PSPDFKit.CertificateChainValidationStatus

The certificate used to sign the document is not valid yet.

invalid PSPDFKit.CertificateChainValidationStatus

The certificate is not valid.

revoked PSPDFKit.CertificateChainValidationStatus

The certificate has been revoked.

failed_to_retrieve_signature_contents PSPDFKit.CertificateChainValidationStatus

Could not fetch the contents of the signature.

general_validation_problem PSPDFKit.CertificateChainValidationStatus

An unknown problem happened when the certificate trust chain was validated.

Between the possible reasons for this could be that the signature is malformed, the certificate chain is too long and other unknown conditions.

(static, readonly) defaultAnnotationPresets: Object.<PSPDFKit.AnnotationPreset>

Returns a deep copy of an object containing the default annotation presets.

The default annotation presets for annotations include the default values for the annotation models, and can be retrieved before loading the instance.

The default annotation presets for annotation variants also include the modified properties corresponding to each annotation variant.

Used by toolbar buttons like line or arrow.

  1. arrow
  2. highlighter
  3. line
  4. rectangle
  5. ellipse
  6. polygon
  7. polyline
  8. text-highlighter
  9. ink
  10. ink-signature
  11. note
  12. text
  13. stamp
  14. image
  15. widget
  16. strikeout
  17. underline
  18. squiggle
  19. highlight
Type:

(static, readonly) defaultEditableAnnotationTypes: Array.<PSPDFKit.Annotations.Annotation>

Returns a deep copy of an array containing the default editable annotation types.

Type:

(static, readonly) defaultStampAnnotationTemplates: Array.<(PSPDFKit.Annotations.StampAnnotation|PSPDFKit.Annotations.ImageAnnotation)>

Returns a deep copy of an array containing the default stamp and image annotation templates, which are stamp annotation instances. However, image annotation templates can also be added to this Array using PSPDFKit.setStampAnnotationTemplates. Used by the stamp picker UI. Initially it contains only the following stamp annotations:

  1. Approved
  2. NotApproved
  3. Draft
  4. Final
  5. Completed
  6. Confidential
  7. ForPublicRelease
  8. NotForPublicRelease
  9. ForComment
  10. Void
  11. PreliminaryResults
  12. InformationOnly
  13. Rejected
  14. Accepted
  15. InitialHere
  16. SignHere
  17. Witness
  18. AsIs
  19. Departmental
  20. Experimental
  21. Expired
  22. Sold
  23. TopSecret
  24. Revised
  25. RejectedWithText
Type:

(static, readonly) defaultToolbarItems: Array.<PSPDFKit.ToolbarItem>

Returns a deep copy of an array containing the default toolbar items ordered by PSPDFKit.ToolbarItem#type in the following way:

  1. sidebar-thumbnails
  2. sidebar-document-outline
  3. sidebar-annotations
  4. sidebar-bookmarks
  5. pager
  6. pan
  7. zoom-out
  8. zoom-in
  9. zoom-mode
  10. spacer
  11. annotate
  12. ink
  13. highlighter
  14. text-highlighter
  15. ink-eraser
  16. ink-signature
  17. image
  18. stamp
  19. note
  20. text
  21. line
  22. arrow
  23. rectangle
  24. ellipse
  25. polygon
  26. polyline
  27. print
  28. document-editor
  29. search
  30. debug

Please keep in mind that under some circumstances some items may be removed from the final list.

Items hidden for touch devices:

  • pan

Items hidden for touch devices when the media query (max-width: 992px) for medium devices matches:

  • zoom-out
  • zoom-in
  • zoom-mode

Please keep in mind that the media query is only added for touch devices. You can change this behavior by defining your own mediaQueries and replacing the original item. To learn more about how to do so please refer to our guide.

Items hidden for small screens (max-width: 992px)

  • text
  • ink
  • highlighter
  • text-highlighter
  • ink-eraser
  • line
  • arrow
  • rectangle
  • ellipse
  • polygon
  • polyline
  • ink-signature
  • image
  • stamp
  • note

Items shown on small screens (max-width: 992px)

  • annotate

Items hidden when in read-only mode:

  • text
  • ink
  • highlighter
  • text-highlighter
  • ink-eraser
  • line
  • arrow
  • rectangle
  • ellipse
  • polygon
  • polyline
  • ink-signature
  • image
  • stamp
  • note

Hidden when not in debug mode (See this guide article):

  • debug

Hidden by default and only available when explicitly set via the API:

  • layout-config
  • marquee-zoom
  • comment
Type:

(static, readonly) DocumentIntegrityStatus

The different signature validation states the document can be in.

Properties:
Name Type Description
ok PSPDFKit.DocumentIntegrityStatus

The part of the document covered by the signature has not been modified.

tampered_document PSPDFKit.DocumentIntegrityStatus

The part of the document covered by the signature has been modified.

failed_to_retrieve_signature_contents PSPDFKit.DocumentIntegrityStatus

The signature /Contents couldn't be parsed.

failed_to_retrieve_byterange PSPDFKit.DocumentIntegrityStatus

The signature /ByteRange couldn't be parsed.

failed_to_compute_digest PSPDFKit.DocumentIntegrityStatus

The digest of the document couldn't be calculated.

failed_retrieve_signing_certificate PSPDFKit.DocumentIntegrityStatus

The signing certificate from the signature contents couldn't be extracted.

failed_retrieve_public_key PSPDFKit.DocumentIntegrityStatus

The public key from the signature contents couldn't be extracted.

failed_encryption_padding PSPDFKit.DocumentIntegrityStatus

The encryption padding from the signature contents couldn't be extracted.

general_failure PSPDFKit.DocumentIntegrityStatus

An unspecific error.

(static, readonly) DocumentValidationStatus

The different possible validation states of the document. Based on the validation of the digital signatures it contains.

Properties:
Name Type Description
valid PSPDFKit.DocumentValidationStatus

All of the signatures of the document are valid, that is, it should be shown with a green checkmark or similar in the UI.

warning PSPDFKit.DocumentValidationStatus

All of the signatures of the document are valid with concerns, that is, it should be shown with a yellow warning or similar in the UI.

error PSPDFKit.DocumentValidationStatus

At least one signature of the document is invalid, that is, it should be shown with a red cross of similar in the UI.

not_signed PSPDFKit.DocumentValidationStatus

The document does not contain digital signatures.

(static, readonly) InteractionMode

Controls the current interaction mode in the viewer.

Properties:
Name Type Description
TEXT_HIGHLIGHTER PSPDFKit.InteractionMode

When this mode is activated, the creation of new highlight annotations will be enabled and the text will be highlighted as it's selected.

INK PSPDFKit.InteractionMode

When this mode is activated, the creation of new ink annotations will be enabled. This transforms the page to a drawable canvas and an annotation is created while drawing on it. If properties (e.g. color) or the page index changes, a new annotation is created.

INK_SIGNATURE PSPDFKit.InteractionMode

When this mode is activated, the creation of new ink signatures will be enabled. This this shows a dialog where it is possible to select an existing ink signature or create a new one and store it.

STAMP_PICKER PSPDFKit.InteractionMode

When this mode is activated, the stamp annotation templates picker modal UI will be shown. Once a template is selected, the new annotation is configured and created\ in the document.

STAMP_CUSTOM PSPDFKit.InteractionMode

When this mode is activated, the custom stamp annotation template editor modal UI will be shown. Once a the custom template is edited, the new custom stamp annotation will be created in the document.

SHAPE_LINE PSPDFKit.InteractionMode

When this mode is activated, the creation of new line annotations will be enabled. This transforms the page to a drawable canvas and an annotation is created while drawing on it.

SHAPE_RECTANGLE PSPDFKit.InteractionMode

When this mode is activated, the creation of new rectangle annotations will be enabled. This transforms the page to a drawable canvas and an annotation is created while drawing on it.

SHAPE_ELLIPSE PSPDFKit.InteractionMode

When this mode is activated, the creation of new ellipse annotations will be enabled. This transforms the page to a drawable canvas and an annotation is created while drawing on it. If properties (e.g. color) or the page index changes, a new annotation is created.

SHAPE_POLYGON PSPDFKit.InteractionMode

When this mode is activated, the creation of new polygon annotations will be enabled. This transforms the page to a drawable canvas and an annotation is created while drawing on it. If properties (e.g. color) or the page index changes, a new annotation is created.

SHAPE_POLYLINE PSPDFKit.InteractionMode

When this mode is activated, the creation of new polyline annotations will be enabled. This transforms the page to a drawable canvas and an annotation is created while drawing on it. If properties (e.g. color) or the page index changes, a new annotation is created.

INK_ERASER PSPDFKit.InteractionMode

When this mode is activated, removing of current ink annotation points will be enabled. This transforms the page to a canvas where the cursor can remove ink annotation points by hand, as well as choose the cursor width.

NOTE PSPDFKit.InteractionMode

When this mode is activated, the creation of new note annotations will be enabled. This transforms the page to a clickable area where the annotation will be created at the position of the click.

COMMENT_MARKER PSPDFKit.InteractionMode

When this mode is activated, the creation of new comment marker annotations will be enabled. This transforms the page to a clickable area where the annotation will be created at the position of the click.

TEXT PSPDFKit.InteractionMode

When this mode is activated, the creation of new text annotations will be enabled. This transforms the page to a clickable area where the annotation will be created at the position of the click.

PAN PSPDFKit.InteractionMode

This enables the pan tool to allow the user to navigate on a desktop browser using mouse dragging. This will disable text selection.

On a touch device, this will have no effect since panning is already the default technique for scrolling on websites.

SEARCH PSPDFKit.InteractionMode

Enables the search mode and focuses the search input field.

DOCUMENT_EDITOR PSPDFKit.InteractionMode

This shows the document editor modal.

MARQUEE_ZOOM PSPDFKit.InteractionMode

This enables the Marquee Zoom tool. When enabled, you can draw a rectangle on the screen which is zoomed into and scrolled to, once the pointer is released.

(static, readonly) LayoutMode

Describes how the pages will be laid out in the document view.

Properties:
Name Type Description
SINGLE PSPDFKit.LayoutMode

Pages will always be displayed in the single page mode.

This is the default mode.

DOUBLE PSPDFKit.LayoutMode

Pages will always be displayed in groups of two.

AUTO PSPDFKit.LayoutMode

Automatically sets the layout mode to PSPDFKit.LayoutMode.SINGLE or PSPDFKit.LayoutMode.DOUBLE depending on the available space.

Specifically PSPDFKit.LayoutMode.DOUBLE is chosen when the PSPDFKit container is in landscape mode and its size is greater than 992px.

This mode is a perfect fit for tablets in particular since it will automatically update the layout mode then device orientation changes.

When the dimensions of the viewport change (i.e. the browser window is resized), the view will be restored to make the current page visible.

(static, readonly) NoteIcon

Available icons for Note Annotations.

Properties:
Name Type Description
COMMENT
RIGHT_POINTER
RIGHT_ARROW
CHECK
CIRCLE
CROSS
INSERT
NEW_PARAGRAPH
NOTE
PARAGRAPH
HELP
STAR
KEY

(static, readonly) PrintMode

Describes mode used to print a PDF document.

Properties:
Name Type Description
DOM PSPDFKit.PrintMode

This method will render all pages of the PDF document in advance before it sends the results to the printer. This works in all major browsers and will not give your users access to the source PDF file. However, this method is CPU-bound and memory usage scales with PDF size.

Because of its reliability and cross browsers support this method is the default.

Some caveats when using this method:

  • To achieve cross-browser support, we render the resulting images into the main window. We try to hide already existing HTML by applying display: none !important. If the printed page still contains other HTML elements, make sure to apply an appropriate print stylesheet to your web app.
  • This method will produce incorrect results, when pages of the document have different sizes. Unfortunately, there's no way to work around this issue since it's a CSS limitation.
EXPORT_PDF PSPDFKit.PrintMode

This method is built to be resource efficient and to avoid having to render all pages in advance, which might balloon memory usage to multi-GB on PDFs with 100+ pages.

It supports all common browsers, however some fall back to opening the PDF file in a new tab, which might give your users unwanted access to the source files.

Google Chrome and Microsoft Internet Explorer provide the APIs required to use the native renderer, as a fallback on other browser we generate and open a PDF in a new tab. This allows users to print the PDF in a native PDF reader which can, as opposed to browser-built implementations, talk directly to the connected printer.

When using this print mode, we can not call the PSPDFKit.RenderPageCallback when printing pages.

Note: If the PDF is password-protected, we always fall back to opening the PDF in a new tab.

(static, readonly) ScrollMode

Describes mode of page scrolling in the document view - either continuous, per spread (paginated) or disabled (changing pages through the UI is disabled).

Properties:
Name Type Description
CONTINUOUS PSPDFKit.ScrollMode

Render all pages as a list and allow smooth scrolling.

This is the default mode.

PER_SPREAD PSPDFKit.ScrollMode

Makes scrolling only possible within a spread. Whenever this mode is activated, or pages are changed when this mode is active, the zoom mode will be reset to PSPDFKit.ZoomMode.FIT_TO_VIEWPORT.

DISABLED PSPDFKit.ScrollMode

Makes scrolling only possible within a spread and doesn't allow changing pages. Whenever this mode is activated the zoom mode will be reset to PSPDFKit.ZoomMode.FIT_TO_VIEWPORT.

(static, readonly) ShowSignatureValidationStatusMode

Controls when the digital signature validation UI should be shown.

Properties:
Name Type Description
IF_SIGNED PSPDFKit.ShowSignatureValidationStatusMode

Show the digital signature validation UI if digital signatures are found on the current document.

HAS_WARNINGS PSPDFKit.ShowSignatureValidationStatusMode

Only show the digital signature validation UI if digital signatures with problems or invalid ones are found, and also if the document has been modified since the moment it's been signed.

HAS_ERRORS PSPDFKit.ShowSignatureValidationStatusMode

Only show the digital signature validation UI if invalid signatures are found.

NEVER PSPDFKit.ShowSignatureValidationStatusMode

Never show the digital signature validation UI.

(static, readonly) SidebarMode

Controls the current sidebar mode in the viewer.

Properties:
Name Type Description
ANNOTATIONS PSPDFKit.SidebarMode

Annotations sidebar.

BOOKMARKS PSPDFKit.SidebarMode

Bookmarks.

DOCUMENT_OUTLINE PSPDFKit.SidebarMode

Document Outline (table of contents).

THUMBNAILS PSPDFKit.SidebarMode

Thumbnails preview.

(static, readonly) SidebarPlacement

Controls the sidebar placement.

Properties:
Name Type Description
START PSPDFKit.SidebarPlacement

The sidebar is shown before the content in the reading direction. For any LTR languages this will be the left side, for RTL languages this will be the right side.

END PSPDFKit.SidebarPlacement

The sidebar is shown after the content in the reading direction. For any LTR languages this will be the right side, for RTL languages this will be the left side.

(static, readonly) SignatureSaveMode

Selects the save mode for ink signatures.

Properties:
Name Type Description
ALWAYS PSPDFKit.SignatureSaveMode

Always store new ink signatures.

NEVER PSPDFKit.SignatureSaveMode

Never store new ink signatures.

USING_UI PSPDFKit.SignatureSaveMode

Store new ink signatures if the option is selected in the UI.

(static, readonly) SignatureValidationStatus

The different possible validation states of the signature.

Properties:
Name Type Description
valid PSPDFKit.SignatureValidationStatus

The overall status of the signature is valid, that is, it should be shown with a green checkmark or similar in the UI.

warning PSPDFKit.SignatureValidationStatus

The overall status of the signature is valid with concerns, that is, it should be shown with a yellow warning or similar in the UI.

error PSPDFKit.SignatureValidationStatus

The overall status of the signature is that it is invalid, that is, it should be shown with a red cross of similar in the UI.

(static, readonly) Theme

Describes theme to use.

Note: Themes are not supported in IE and setting this option won't have any effect: IE users will get the default light theme. You can customize the appearance of the UI using our public CSS classes. Please refer to this guide article for information on how to customize the appearance.

Properties:
Name Type Description
LIGHT PSPDFKit.Theme

Light mode. This is the default theme.

DARK PSPDFKit.Theme

Dark mode.

AUTO PSPDFKit.Theme

Uses PSPDFKit.Theme.LIGHT or PSPDFKit.Theme.DARK based on the user preferences and the prefers-color-scheme media query. Note this is not available in every browser.

(static, readonly) ToolbarPlacement

Configure where the toolbar is placed.

Properties:
Name Type Description
TOP PSPDFKit.ToolbarPlacement

The default value. The toolbar will be placed at the top of the viewport.

BOTTOM PSPDFKit.ToolbarPlacement

The toolbar will be placed at the bottom of the viewport.

(static, readonly) version

Returns the framework version (e.g. "2019.4.0").

(static, readonly) ZoomMode

A specific zoom mode that will always be applied whenever the viewport is resized.

Properties:
Name Type Description
AUTO PSPDFKit.ZoomMode

Generates a zoomLevel that will automatically align the page for the best viewing experience.

FIT_TO_WIDTH PSPDFKit.ZoomMode

Uses a zoomLevel that will fit the width of the broadest page into the viewport. The height might overflow.

FIT_TO_VIEWPORT PSPDFKit.ZoomMode

Uses a zoomLevel that will fit the current page into the viewport completely.


Methods

(static) load(configuration) → {Promise.<PSPDFKit.Instance, PSPDFKit.Error>}

Creates a new PSPDFKit instance.

Returns a Promise resolving to a new PSPDFKit.Instance, or rejecting with a PSPDFKit.Error.

It requires a configuration object. When the configuration is invalid, the promise will be rejected with a PSPDFKit.Error.

Parameters:
Name Type Description
configuration PSPDFKit.Configuration

A configuration Object

Returns:

Promise that resolves in an PSPDFKit.Instance

Type
Promise.<PSPDFKit.Instance, PSPDFKit.Error>
Examples

Load PSPDFKit for Web Server

PSPDFKit.load({
  authPayload: { jwt: "xxx.xxx.xxx" },
  container: ".foo",
  documentId: "85203",
  instant: true,
}).then((instance) => {
  console.log("Successfully mounted PSPDFKit", instance);
}).catch((error) => {
  console.error(error.message);
})

Load PSPDFKit for Web Standalone

PSPDFKit.load({
  pdf: "/sales-report.pdf",
  container: ".foo",
  licenseKey: "YOUR_LICENSE_KEY",
}).then((instance) => {
  console.log("Successfully mounted PSPDFKit", instance);
}).catch((error) => {
  console.error(error.message);
})

(static) preloadWorker(configuration) → {Promise.<void>}

Preloads the standalone WASM worker.

In cases where you don't want to load a PDF right away, the first invocation of PSPDFKit.load after allowing this function to resolve will be significantly faster.

If PSPDFKit.load is called while this function has not yet resolved, then PSPDFKit.load will simply reuse the request from this function without adding any overhead.

Parameters:
Name Type Description
configuration PSPDFKit.Configuration

A configuration Object

Returns:

Promise that resolves when preloading is complete

Type
Promise.<void>
Example
// Fetches worker asynchronously
PSPDFKit.preloadWorker(configuration);
document.querySelector("#open-pdf-button").addEventListener(async () => {
  await PSPDFKit.load({ ...configuration, pdf: "my-doc.pdf" });
});

(static) unload(target) → {boolean}

Unloads an existing PSPDFKit instance.

It requires an target parameter that is a CSS selector, an HTMLElement or the reference to a PSPDFKit.Instance returned by PSPDFKit.load.

Parameters:
Name Type Description
target HTMLElement | string | PSPDFKit.Instance

A target to unload

Throws:

Will throw an error when the target is invalid but will work when it does not have a mounted PSPDFKit for Web instance.

Type
PSPDFKit.Error
Returns:

When true, an instance of PSPDFKit for Web was unmounted.

Type
boolean
Examples

Unload PSPDFKit for Web using an instance

let instance = null;
PSPDFKit.load({
  pdf: "/sales-report.pdf",
  container: ".foo",
}).then((i) => {
  instance = i
})
.then(() => {
  // Unload the given instance
  PSPDFKit.unload(instance)
}).catch((error) => {
  console.error(error.message);
})

Unload PSPDFKit for Web using a CSS selector

PSPDFKit.load({
  pdf: "/sales-report.pdf",
  container: ".foo",
})
.then(() => {
  // Unload the given instance
  PSPDFKit.unload(".foo")
})

Unload PSPDFKit for Web using an HTMLElement

PSPDFKit.load({
  pdf: "/sales-report.pdf",
  container: ".foo",
})
.then(() => {
  // Unload the given instance
  PSPDFKit.unload(document.querySelector(".foo"))
})

(static) viewStateFromOpenParameters() → {PSPDFKit.ViewState}

Merges the properties extracted from the location.hash into the PSPDFKit.ViewState.

Properties will be extracted following the PDF Open Parameters spec.

Currently, we only support the page parameter.

Parameters:
Type Description
PSPDFKit.ViewState
Returns:
Type
PSPDFKit.ViewState

Type Definitions

AnnotationTooltipCallback(annotation)

This callback is called whenever an annotation gets selected and can be used to define and return an array of PSPDFKit.ToolItem that will be rendered in a tooltip for the given annotation.

If the callback returns an empty array then PSPDFKit won't show any tooltip for the selected annotation.

Parameters:
Name Type Description
annotation Annotation

The selected annotation.

Example

Register a AnnotationTooltipCallback handler to show a tooltip for text annotations only.

PSPDFKit.load({
  annotationTooltipCallback: function(annotation) {
    if (annotation instanceof PSPDFKit.Annotations.TextAnnotation) {
      var toolItem = {
        type: 'custom',
        title: 'tooltip item for text annotations',
        id: 'item-text-tooltip-annotation',
        className: 'TooltipItem-Text',
        onPress: function () {
          console.log(annotation)
        }
      }
      return [toolItem]
    } else {
      return []
    }
  }
  // ...
});

IsEditableAnnotationCallback(annotation)

This callback defines which annotations are read-only. This callback will receive the Annotation a user wants to modify and by returning true or false you can define if the annotation should be read-only (false) or modifiable (true).

For more information, see PSPDFKit.Configuration#isEditableAnnotation.

Parameters:
Name Type Description
annotation Annotation
Example

Only allow the modification of annotations from the same author

PSPDFKit.load({
  isEditableAnnotation: function(annotation) {
    return annotation.creatorName === myCurrentUser.name;
  },
});

RenderPageCallback(canvas, pageIndex, size)

This callback is called whenever a page is rendered or printed (only for PSPDFKit.PrintMode.DOM). You can use it to render watermarks on the page.

Make sure that the rendering commands are as efficient as possible as they might be invoked multiple times per page (once per tile).

For more information, see PSPDFKit.Configuration#renderPageCallback.

Parameters:
Name Type Description
canvas CanvasRenderingContext2D

A 2D <canvas/> rendering context.

pageIndex number

The current page index, starting with 0 for the first page.

size PSPDFKit.Geometry.Size

The size of the page that you're drawing at. The canvas is already scaled accordingly.

Example

Register a RenderPageCallback handler at configuration time.

PSPDFKit.load({
  renderPageCallback: function(ctx, pageIndex, pageSize) {
    ctx.beginPath();
    ctx.moveTo(0, 0);
    ctx.lineTo(pageSize.width, pageSize.height);
    ctx.stroke();

    ctx.font = "30px Comic Sans MS";
    ctx.fillStyle = "red";
    ctx.textAlign = "center";
    ctx.fillText(
      `This is page ${pageIndex + 1}`,
      pageSize.width / 2,
      pageSize.height / 2
    );
  }
  // ...
});

TrustedCAsCallback() → {Promise.<Array.<(ArrayBuffer|string)>>}

On Standalone, by implementing this callback you have a fine grained control over which certificates are going to be used for digital signatures validation.

For more information, see PSPDFKit.Configuration#trustedCAsCallback

Returns:

The CA certificates in DER (ArrayBuffer) or PEM (string) format. PSPDFKit.load({ trustedCAsCallback: function() { return new Promise((resolve, reject) => { fetch("/your-certificate.cer") .then(res => res.arrayBuffer()) .then(cert => resolve([cert])) .catch(reject) }); }, // ... });

Type
Promise.<Array.<(ArrayBuffer|string)>>
Example
<caption>Fetch and use custom set of certificates (Standalone)</caption>

TwoStepSignatureCallback(signaturePreparedData) → {Promise.<ArrayBuffer>}

This callback is called when a document has been prepared for digitally signing by calling PSPDFKit.Instance#signDocument. It receives the current document hash and file contents to be signed as arguments, and must return a Promise object that resolves to a PKCS7 container to sign the document with. If the returned Promise object rejects, the document will not be signed.

The provided file contents can be used as input for a cryptographic library or service of your choice to be signed (hashed and encrypted in a PKCS7 container). The file contents hash is also provided so it can be used it to verify the validity of the contents.

See this guide article for more information on how to digitally sign a document on Standalone.

Parameters:
Name Type Description
signaturePreparedData Object

Signature prepared data.

Properties
Name Type Description
hash string

Hash of the current document.

fileContents ArrayBuffer

Content of the file to be signed.

Returns:

A promise that resolves to an ArrayBuffer containing the PKCS7 container.

Type
Promise.<ArrayBuffer>
Example

Sign document (Standalone)

instance.signDocument(null, function({ hash, fileContents }) {
  return new Promise(function(resolve, reject) {
    const PKCS7Container = getPKCS7Container(hash, fileContents);
    if (PKCS7Container != null) {
      return resolve(PKCS7Container)
    }
    reject(new Error("Could not retrieve the PKCS7 container."))
  })
}).then(function() {
  console.log("Document signed!");
})