Liebe Community,
ich habe folgenden Interceptor entworfen, um eine Funktion zum „Einbrennen“ der Annotations anzubieten:
class EDAnnotationFlattener {
// code fragements taken from https://docs.apryse.com/documentation/web/guides/annotation/flatten-annotations/
async flattenAllAnnotations(instance) {
const confirmation = confirm("Alle Anmerkungen werden unwiederruflich in das PDF integriert. Sind Sie sicher, dass sie dies tun möchten?");
if (!confirmation) {
return;
}
const { documentViewer, PDFNet, annotationManager } = instance.Core;
await PDFNet.initialize();
const theDocument = await documentViewer.getDocument().getPDFDoc();
// export annotations from the document
const allAnnotations = await annotationManager.exportAnnotations();
// Run PDFNet methods with memory management
await PDFNet.runWithCleanup(async () => {
// lock the document before a write operation
// runWithCleanup will auto unlock when complete
theDocument.lock();
// import annotations to PDFNet
const fdfDocument = await PDFNet.FDFDoc.createFromXFDF(allAnnotations);
await theDocument.fdfUpdate(fdfDocument);
// flatten all annotations in the document
// see https://docs.apryse.com/api/web/Core.PDFNet.PDFDoc.html#flattenAnnotations__anchor
await theDocument.flattenAnnotations();
// clear the original annotations
annotationManager.deleteAnnotations(annotationManager.getAnnotationsList());
});
// clear the cache (rendered) data with the newly updated document
documentViewer.refreshAll();
// Update viewer to render with the new document
documentViewer.updateView();
// Refresh searchable and selectable text data with the new document
documentViewer.getDocument().refreshTextData();
}
initEditorConfiguration(instance) {
// Create a new action button
const aButton = {
type: 'actionButton',
img: 'paint-roller-solid.svg',
title: 'Alle Anmerkungen fixieren',
onClick: () => this.flattenAllAnnotations(instance)
};
// Add the new button to the header
instance.UI.setHeaderItems(header => {
header.push(aButton);
});
};
}
window.ed.registerInterceptor(new EDAnnotationFlattener);
Wobei ich nicht sicher bin: Wie baue ich ein neues Icon ein, wie platziere ich es in der Edit-Toolbar und wie baue ich einen „besser integrierten“ Confirmation-Dialog?
Hat da jemand von Euch ein paar Hinweise für mich?