The main PSPDFKit namespace is exported in the global PSPDFKit
.
Classes
Namespaces
Members
Methods
Type Definitions
Members
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 |
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. |
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. |
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. |
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
.
arrow
highlighter
line
rectangle
ellipse
polygon
polyline
text-highlighter
ink
ink-signature
note
text
stamp
image
widget
strikeout
underline
squiggle
highlight
redaction
Type:
- Object.<PSPDFKit.AnnotationPreset>
Returns a deep copy of an array containing the default editable annotation types.
Type:
- Array.<PSPDFKit.Annotations.Annotation>
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:
Approved
NotApproved
Draft
Final
Completed
Confidential
ForPublicRelease
NotForPublicRelease
ForComment
Void
PreliminaryResults
InformationOnly
Rejected
Accepted
InitialHere
SignHere
Witness
AsIs
Departmental
Experimental
Expired
Sold
TopSecret
Revised
RejectedWithText
Type:
Returns a deep copy of an array containing the default toolbar items ordered by PSPDFKit.ToolbarItem#type in the following way:
sidebar-thumbnails
sidebar-document-outline
sidebar-annotations
sidebar-bookmarks
pager
pan
zoom-out
zoom-in
zoom-mode
spacer
annotate
ink
highlighter
text-highlighter
ink-eraser
ink-signature
image
stamp
note
text
line
arrow
rectangle
ellipse
polygon
polyline
print
document-editor
search
export-pdf
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
redact-text-highlighter
redact-rectangle
Type:
- Array.<PSPDFKit.ToolbarItem>
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. |
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. |
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 |
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. |
REDACT_TEXT_HIGHLIGHTER |
PSPDFKit.InteractionMode | When this mode is activated, the creation of new redaction annotations will be enabled by highlighting regions of text and the text will be marked for redaction as it's selected. |
REDACT_SHAPE_RECTANGLE |
PSPDFKit.InteractionMode | When this mode is activated, the creation of new redaction annotations will be enabled by drawing rectangles on the pages. This transforms the page to a drawable canvas and annotations are created while drawing on it. |
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. |
Available icons for Note Annotations.
Properties:
Name | Type | Description |
---|---|---|
COMMENT |
PSPDFKit.NoteIcon | |
RIGHT_POINTER |
PSPDFKit.NoteIcon | |
RIGHT_ARROW |
PSPDFKit.NoteIcon | |
CHECK |
PSPDFKit.NoteIcon | |
CIRCLE |
PSPDFKit.NoteIcon | |
CROSS |
PSPDFKit.NoteIcon | |
INSERT |
PSPDFKit.NoteIcon | |
NEW_PARAGRAPH |
PSPDFKit.NoteIcon | |
NOTE |
PSPDFKit.NoteIcon | |
PARAGRAPH |
PSPDFKit.NoteIcon | |
HELP |
PSPDFKit.NoteIcon | |
STAR |
PSPDFKit.NoteIcon | |
KEY |
PSPDFKit.NoteIcon |
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:
|
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. |
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. |
Allows you to perform a search by a built-in pattern that matches common strings.
Note that by design, some of these patterns might overfit the criteria (i.e. include false positive results). This might happen since we strive for including all positive results and avoid data loss. Make sure to review the matches found.
Properties:
Name | Type | Description |
---|---|---|
CREDIT_CARD_NUMBER |
PSPDFKit.SearchPattern | Catches credit card numbers with a number beginning with 1-6, and must be 13 to 19 digits long. Spaces and - are allowed anywhere in the number. |
DATE |
PSPDFKit.SearchPattern | Matches date formats such as mm/dd/yyyy, mm/dd/yy, dd/mm/yyyy, and dd/mm/yy.
It will reject any days/months greater than 31 and will match if a
leading zero is or is not used for a single digit day or month.
The delimiter can either be |
TIME |
PSPDFKit.SearchPattern | Matches time formats such as 00:00:00, 00:00, 00:00 PM. 12 and 24 hour formats are allowed. Seconds and 12 hour AM/PM denotation are both optional. |
EMAIL_ADDRESS |
PSPDFKit.SearchPattern | Matches an email address with the format of xyz@xyz.xyz where xyz can be any alpha numeric character or a . For more information on the pattern please see http://emailregex.com/. |
INTERNATIONAL_PHONE_NUMBER |
PSPDFKit.SearchPattern | Matches International style phone numbers with a prefix of + or 00, containing between 7 - 15 digits with spaces or - occurring anywhere within the number. |
IP_V4 |
PSPDFKit.SearchPattern | Matches an IPV4 address limited to number ranges of 0-255 with an optional mask. |
IP_V6 |
PSPDFKit.SearchPattern | Matches full and compressed IPv6 addresses as defined in RFC 2373. |
MAC_ADDRESS |
PSPDFKit.SearchPattern | Matches a MAC address with delimiters of either |
NORTH_AMERICAN_PHONE_NUMBER |
PSPDFKit.SearchPattern | Matches a NANP (https://en.wikipedia.org/wiki/North_American_Numbering_Plan) style phone number. In general this will match US, Canadian and various other Caribbean countries.
The pattern will also match an optional international prefix of |
SOCIAL_SECURITY_NUMBER |
PSPDFKit.SearchPattern | Matches a US social security number (SSN). The format of the number should be either XXX-XX-XXXX or XXXXXXXXX with X denoting [0-9]. We expect the number to have word boundaries on either side, or to be the start/end of the string. |
URL |
PSPDFKit.SearchPattern | Matches a URL with a prefix of http|https|www with an optional subdomain. |
US_ZIP_CODE |
PSPDFKit.SearchPattern | Matches a USA style Zip Code. The format expected is 00000 or 00000-0000, where the delimiter can either be |
VIN |
PSPDFKit.SearchPattern | Matches US and ISO 3779 standard VINs.
The format expects 17 characters with the last 5 characters being numeric. |
Redactions Search Type
Properties:
Name | Type | Description |
---|---|---|
TEXT |
PSPDFKit.SearchType | This is the default search type. This is used when you want to search for strings/text. |
PRESET |
PSPDFKit.SearchType | The search type when you want to use the patterns provided by us. see PSPDFKit.SearchPattern for the list of all the patterns. |
REGEX |
PSPDFKit.SearchType | The search type when you want to search using regex. The regular expression flavor is based on ICU regular expression, which is a derivative of Perl regular expressions. |
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. |
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. |
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. |
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. |
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. |
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 |
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. |
Returns the framework version (e.g. "2019.4.0").
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
Generates a new unique ID usable as an ID of annotation, formField, bookmark or comment.
Returns:
A unique identifier.
- Type
- string
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({
document: "/sales-report.pdf",
container: ".foo",
licenseKey: "YOUR_LICENSE_KEY",
}).then((instance) => {
console.log("Successfully mounted PSPDFKit", instance);
}).catch((error) => {
console.error(error.message);
})
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, document: "my-doc.pdf" });
});
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({
document: "/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({
document: "/sales-report.pdf",
container: ".foo",
})
.then(() => {
// Unload the given instance
PSPDFKit.unload(".foo")
})
Unload PSPDFKit for Web using an HTMLElement
PSPDFKit.load({
document: "/sales-report.pdf",
container: ".foo",
})
.then(() => {
// Unload the given instance
PSPDFKit.unload(document.querySelector(".foo"))
})
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
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 []
}
}
// ...
});
An union of supported types of changes.
Type:
- Annotation | Bookmark | FormField | FormFieldValue | Comment
This callback defines which annotations are rendered using their AP stream instead of their default,
native appearance. When set, it will be called with each annotation about to be rendered. If the
callback returns true
, the annotation will be rendered using its AP stream. If it returns false
,
the default, native appearance will be used instead.
This callback may be called multiple times, even for the same annotation, so in order to prevent hurting performance it's preferable to avoid running any CPU expensive operation on it.
For more information, see PSPDFKit.Configuration#IsAPStreamRendered.
Parameters:
Name | Type | Description |
---|---|---|
annotation |
Annotation |
Example
Render rectangle annotations using their AP stream
PSPDFKit.load({
isAPStreamRendered: annotation => {
// Render rectangle annotations using their AP stream.
if (annotation instanceof PSPDFKit.Annotations.RectangleAnnotation) {
return true;
}
// The rest of the annotations will be rendered using their default, native appearance.
return false;
}
// ...
});
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;
},
});
Indicates the type of modification made to a PSPDFKit.Change.
Type:
- 'CREATED' | 'UPDATED' | 'DELETED'
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 |
pageIndex |
number | The current page index, starting with |
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
);
}
// ...
});
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>
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
|
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!");
})