diff --git a/src/dbp-signature-lit-element.js b/src/dbp-signature-lit-element.js index 60b0c0a1564f3f50d76b563b53a568f2f572713d..2140d4dc9e05db6805afc5a107e3a0c8779a396c 100644 --- a/src/dbp-signature-lit-element.js +++ b/src/dbp-signature-lit-element.js @@ -139,10 +139,9 @@ export default class DBPSignatureLitElement extends DBPSignatureBaseLitElement { * * @param file * @param annotations - * @param i18n * @returns {File} */ - async addAnnotationsToFile(file, annotations, i18n) { + async addAnnotationsToFile(file, annotations) { // We need to work with the AnnotationFactory because the pdf file is broken if // we add the multiple annotations to the file itself let pdfFactory = await utils.getAnnotationFactoryFromFile(file); @@ -156,9 +155,10 @@ export default class DBPSignatureLitElement extends DBPSignatureBaseLitElement { return; } - const annotationKey = key1 + '-' + key2; - pdfFactory = await utils.addKeyValuePdfAnnotationToAnnotationFactory( - pdfFactory, i18n, 'AppName', this.auth['user-full-name'], annotationKey, value); + // TODO: use real key1 names + pdfFactory = await utils.addKeyValuePdfAnnotationsToAnnotationFactory( + pdfFactory, 'AppNameDE', 'AppNameEN', this.auth['user-full-name'], key1, + "Geschaeftszahl", "Businessnumber", key2, value); }); // output the AnnotationFactory as File again @@ -209,9 +209,8 @@ export default class DBPSignatureLitElement extends DBPSignatureBaseLitElement { * Add an annotation to a file on the queue * * @param key - * @param i18n */ - async addAnnotationToPDF(key, i18n) { + async addAnnotationToPDF(key) { const annotationKey = prompt("Please enter a key"); if (annotationKey === null || annotationKey === "") { @@ -228,8 +227,8 @@ export default class DBPSignatureLitElement extends DBPSignatureBaseLitElement { // console.log("file before annotation", file); - // annotate the pwd with the key and value - file = await utils.addKeyValuePdfAnnotation(file, i18n, 'AppName', this.auth['user-full-name'], annotationKey, annotationValue); + // annotate the pdf with the key and value + file = await utils.addKeyValuePdfAnnotation(file, 'AppNameDE', 'AppNameEN', this.auth['user-full-name'], annotationKey, annotationValue); // console.log("file after annotation", file); diff --git a/src/utils.js b/src/utils.js index 194e9574db46ba9931c98f5c9b46dc6d90e94357..cfa7144451bf7d85795b2e94b4105ef665b7ece9 100644 --- a/src/utils.js +++ b/src/utils.js @@ -146,14 +146,14 @@ export const getPDFSignatureCount = async (file) => { * Adds an annotation to a PDF file * * @param file - * @param i18n - * @param appName + * @param appNameDE + * @param appNameEN * @param personName * @param key * @param value * @returns {File} */ -export const addKeyValuePdfAnnotation = async (file, i18n, appName, personName, key, value) => { +export const addKeyValuePdfAnnotation = async (file, appNameDE, appNameEN, personName, key, value) => { key = key.trim(); value = value.trim(); @@ -163,7 +163,8 @@ export const addKeyValuePdfAnnotation = async (file, i18n, appName, personName, } let annotationFactory = await getAnnotationFactoryFromFile(file); - annotationFactory = addKeyValuePdfAnnotationToAnnotationFactory(annotationFactory, i18n, appName, personName, key, value); + annotationFactory = addKeyValuePdfAnnotationsToAnnotationFactory(annotationFactory, appNameDE, appNameEN, + personName, key, 'Name DE', 'Name EN', 'key2', value); return writeAnnotationFactoryToFile(annotationFactory, file); }; @@ -197,36 +198,58 @@ export const getAnnotationFactoryFromFile = async (file) => { * Adds a key/value annotation to a AnnotationFactory and returns the AnnotationFactory * * @param annotationFactory - * @param i18n - * @param appName + * @param appNameDE + * @param appNameEN * @param personName - * @param key + * @param key1 + * @param key1NameDE + * @param key1NameEN + * @param key2 * @param value * @returns PdfFactory */ -export const addKeyValuePdfAnnotationToAnnotationFactory = (annotationFactory, i18n, appName, personName, key, value) => { - key = key.trim(); +export const addKeyValuePdfAnnotationsToAnnotationFactory = (annotationFactory, appNameDE, appNameEN, personName, + key1, key1NameDE, key1NameEN, key2, value) => { + key1 = key1.trim(); + key1NameDE = key1NameDE.trim(); + key1NameEN = key1NameEN.trim(); + key2 = key2.trim(); value = value.trim(); // don't annotate if key or value are empty - if (key === '' || value === '') { + if (key1 === '' || key2 === '' || value === '') { return annotationFactory; } - // console.log("annotationFactory.getAnnotations() before", annotationFactory.getAnnotations()); + // add human readable annotation + let author = personName + ' via "' + appNameDE + ' / ' + appNameEN + '"'; + let content = key1NameDE + ': ' + value +"\n" + key1NameEN + ': ' + value; + annotationFactory = addPdfAnnotationToAnnotationFactory(annotationFactory, author, content); + + // add machine readable annotation + author = 'Maschinell aufgebracht, bitte nicht entfernen / Applied automatically, please do not remove'; + content = 'dbp-annotation-' + key1 + '-' + key2 + '=' + value; + annotationFactory = addPdfAnnotationToAnnotationFactory(annotationFactory, author, content); + + return annotationFactory; +}; + +export const addPdfAnnotationToAnnotationFactory = (annotationFactory, author, content) => { + author = author.trim(); + content = content.trim(); + + // don't annotate if author of content are empty + if (author === '' || content === '') { + return annotationFactory; + } const page = 0; - const rect = [1, 1, 1, 1]; - const author = i18n.t('annotation-author', { - appName: appName, - personName: personName - }); - const contents = 'dbp-annotation-' + key + '=' + value; + const rect = [0, 0, 0, 0]; // annotationFactory.checkRect(4, rect); // Create single free text annotation with print flag and 0 font size - let annotation = Object.assign(annotationFactory.createBaseAnnotation(page, rect, contents, author), { + let annotation = Object.assign(annotationFactory.createBaseAnnotation(page, rect, content, author), { annotation_flag: 4, // enable print to be PDF/A conform color: {r: 1, g: 1, b: 1}, // white to (maybe) hide it better opacity: 0.001, // we can't set to 0 because of "if (opacity) {" diff --git a/vendor/toolkit b/vendor/toolkit index e728b2a0094aaa18cecc3b081238f8e189871c35..a8ab1f7220f86eea76e5f601c080da066496f7df 160000 --- a/vendor/toolkit +++ b/vendor/toolkit @@ -1 +1 @@ -Subproject commit e728b2a0094aaa18cecc3b081238f8e189871c35 +Subproject commit a8ab1f7220f86eea76e5f601c080da066496f7df