function loadPSPDFKit(arrayBuffer, container, licenseKey, locale) { return PSPDFKit.load({ inlineWorkers: false, locale: locale, licenseKey: licenseKey, styleSheets: ['/css/site.css'], container: container, document: arrayBuffer, annotationPresets: getPresets(), electronicSignatures: { creationModes: ['DRAW', 'TYPE', 'IMAGE'], }, initialViewState: new PSPDFKit.ViewState({ sidebarMode: PSPDFKit.SidebarMode.THUMBNAILS, }), isEditableAnnotation: function (annotation) { return !(annotation.isSignature || annotation.description === 'FRAME') }, }).then((instance) => { if (READ_AND_CONFIRM) { const totalPages = instance.totalPageCount || 0 const storageKeyAll = 'pspdf_all_pages_rendered' const storageKeyUnviewed = 'pspdf_unviewed_pages' let unviewed = totalPages > 0 ? Array.from({ length: totalPages }, (_, i) => i + 1) : [] const saveState = () => { sessionStorage.setItem(storageKeyUnviewed, JSON.stringify(unviewed)) sessionStorage.setItem(storageKeyAll, JSON.stringify(unviewed.length === 0 && totalPages > 0)) } const markPageViewed = (pageIndex) => { const pageNumber = pageIndex + 1 if (pageNumber < 1 || pageNumber > totalPages) return const idx = unviewed.indexOf(pageNumber) if (idx >= 0) { unviewed.splice(idx, 1) saveState() } } // initial state in session storage saveState() // mark the initially visible page const initialPage = instance.viewState?.currentPageIndex ?? 0 markPageViewed(initialPage) instance.addEventListener('viewState.currentPageIndex.change', (pageIndex) => { console.log('Active page:', pageIndex + 1) markPageViewed(pageIndex) }) } return instance }) } const allowedToolbarItems = [ 'sidebar-thumbnails', 'sidebar-document-ouline', 'sidebar-bookmarks', 'pager', 'pan', 'zoom-out', 'zoom-in', 'zoom-mode', 'spacer', 'search', 'export-pdf' ] function addToolbarItems(instance, handler) { var toolbarItems = instance.toolbarItems.filter((item) => allowedToolbarItems.includes(item.type)); if (IS_READONLY) toolbarItems = toolbarItems.concat(getReadOnlyItems(handler)); else toolbarItems = toolbarItems.concat(getWritableItems(handler)); if (!IS_DESKTOP_SIZE && !IS_READONLY) toolbarItems = toolbarItems.concat(getMobileWritableItems(handler)); instance.setToolbarItems(toolbarItems) } function getWritableItems(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: `` } ]; } function getReadOnlyItems(callback) { return [ { type: 'custom', id: 'button-copy-url', className: 'button-copy-url', title: 'Teilen', onPress() { callback('COPY_URL') }, icon: ` `, } ]; } function getMobileWritableItems(callback) { const items = [ { 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: ` `, } ] if (!READ_AND_CONFIRM) { items.push({ type: 'custom', id: 'button-reset', className: 'button-reset', title: 'Zurücksetzen', onPress() { callback('RESET') }, icon: ` ` }) } return items } function getPresets() { const annotationPresets = PSPDFKit.defaultAnnotationPresets annotationPresets.ink = { lineWidth: 10, } annotationPresets.widget = { readOnly: true, } return annotationPresets }