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.getReadOnlyItems(handler));
else
toolbarItems = toolbarItems.concat(UI.getWritableItems(handler));
if (!IS_DESKTOP_SIZE && !IS_READONLY)
toolbarItems = toolbarItems.concat(UI.getMobileWritableItems(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: ``,
},
{
type: 'custom',
id: 'button-logout',
className: 'button-logout',
title: 'logout',
onPress() {
callback('LOGOUT')
},
icon: ``
},
{
type: 'custom',
id: 'mock',
className: 'mock',
title: 'Mock',
icon: ``
}
];
}
static getReadOnlyItems = function (callback) {
return [
{
type: 'custom',
id: 'button-copy-url',
className: 'button-copy-url',
title: 'Teilen',
onPress() {
callback('COPY_URL')
},
icon: ``,
}
];
}
static getMobileWritableItems = function (callback) {
return [
{
type: 'custom',
id: 'button-finish',
className: 'button-finish',
onPress() {
callback('FINISH')
},
icon: ``
},
{
type: 'custom',
id: 'button-reject',
className: 'button-reject',
title: 'Ablehnen',
onPress() {
callback('REJECT')
},
icon: ``,
},
{
type: 'custom',
id: 'button-reset',
className: 'button-reset',
title: 'Zurücksetzen',
onPress() {
callback('RESET')
},
icon: ``,
}
];
}
static getPresets() {
const annotationPresets = PSPDFKit.defaultAnnotationPresets
annotationPresets.ink = {
lineWidth: 10,
}
annotationPresets.widget = {
readOnly: true,
}
return annotationPresets
}
}