class UI {
allowedToolbarItems = [
"sidebar-thumbnails",
"sidebar-document-ouline",
"sidebar-bookmarks",
"pager",
"pan",
"zoom-out",
"zoom-in",
"zoom-mode",
"spacer",
"search"
]
// Load the PSPDFKit UI by setting a target element as the container to render in
// and a arraybuffer which represents the document that should be displayed.
loadPSPDFKit(arrayBuffer, container) {
return PSPDFKit.load({
container: container,
document: arrayBuffer,
autoSaveMode: "DISABLED",
annotationPresets: this.getPresets(),
electronicSignatures: {
creationModes: ["DRAW", "TYPE"]
},
isEditableAnnotation: function (annotation) {
// Check if the annotation is a signature
// This will allow new signatures, but not allow edits.
return !annotation.isSignature;
}
})
}
configurePSPDFKit(instance, handler) {
instance.addEventListener("annotations.load", (loadedAnnotations) => {
console.log("annotations loaded", loadedAnnotations.toJS());
})
instance.addEventListener("annotations.change", () => {
console.log("annotations changed")
})
instance.addEventListener("annotations.create", async (createdAnnotations) => {
console.log("annotations created");
})
const toolbarItems = this.getToolbarItems(instance, handler)
instance.setToolbarItems(toolbarItems)
console.debug("PSPDFKit configured!");
}
getToolbarItems(instance, handler) {
const customItems = this.getCustomItems(handler)
const defaultItems = this.getDefaultItems(instance.toolbarItems)
return defaultItems.concat(customItems)
}
getCustomItems = function (callback) {
const customItems = [
{
type: "custom",
id: "button-reset",
className: "button-reset",
title: "Zurücksetzen",
onPress() {
callback("RESET")
},
icon: ``
},
{
type: "custom",
id: "button-finish",
className: "button-finish",
title: "Abschließen",
onPress() {
callback("FINISH")
},
icon: ``
}
]
return customItems
}
getDefaultItems(items) {
return items.filter((item) => this.allowedToolbarItems.includes(item.type))
}
getPresets() {
const annotationPresets = PSPDFKit.defaultAnnotationPresets;
annotationPresets.ink = {
lineWidth: 10
};
annotationPresets.widget = {
readOnly: true
}
return annotationPresets;
}
}