class UI {
static allowedToolbarItems = [
'sidebar-thumbnails',
'sidebar-document-ouline',
'sidebar-bookmarks',
'pager',
'pan',
'zoom-out',
'zoom-in',
'zoom-mode',
'spacer',
'search',
'export-pdf'
]
// 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.
static Instance
static loadPSPDFKit(arrayBuffer, container, licenseKey, locale) {
UI.Instance = PSPDFKit.load({
inlineWorkers: false,
locale: locale,
licenseKey: licenseKey,
styleSheets: ['/css/site.css'],
container: container,
document: arrayBuffer,
annotationPresets: UI.getPresets(),
electronicSignatures: {
creationModes: ['DRAW', 'TYPE', 'IMAGE'],
},
initialViewState: new PSPDFKit.ViewState({
sidebarMode: PSPDFKit.SidebarMode.THUMBNAILS,
}),
isEditableAnnotation: function (annotation) {
// Check if the annotation is a signature
// This will allow new signatures, but not allow edits.
if (annotation.isSignature || annotation.description == 'FRAME') {
return false
}
return true
//return !annotation.isSignature;
},
customRenderers: {
Annotation: UI.annotationRenderer,
},
})
return UI.Instance;
}
static addToolbarItems(instance, handler) {
var toolbarItems = instance.toolbarItems.filter((item) => UI.allowedToolbarItems.includes(item.type));
if(!IS_READONLY)
toolbarItems = toolbarItems.concat(UI.getWritableItems(handler));
if(!IS_DESKTOP)
toolbarItems = toolbarItems.concat(UI.getMobileItems(handler));
instance.setToolbarItems(toolbarItems)
}
static annotationRenderer(data) {
// leave everything as is
return null
}
static createElementFromHTML(html) {
const el = document.createElement('div')
el.innerHTML = html.trim()
return el.firstChild
}
static getWritableItems = function (callback) {
return [
{
type: 'custom',
id: 'button-share',
className: 'button-share',
title: 'Teilen',
onPress() {
callback('SHARE')
},
icon: ``,
}
];
}
static getMobileItems = function (callback) {
return [
{
type: 'custom',
id: 'button-reset',
className: 'button-reset',
title: 'Zurücksetzen',
onPress() {
callback('RESET')
},
icon: ``,
},
{
type: 'custom',
id: 'button-reject',
className: 'button-reject',
title: 'Ablehnen',
onPress() {
callback('REJECT')
},
icon: ``,
},
{
type: 'custom',
id: 'button-finish',
className: 'button-finish',
title: 'Abschließen',
onPress() {
callback('FINISH')
},
}
];
}
static getPresets() {
const annotationPresets = PSPDFKit.defaultAnnotationPresets
annotationPresets.ink = {
lineWidth: 10,
}
annotationPresets.widget = {
readOnly: true,
}
return annotationPresets
}
}