Skip to content
Snippets Groups Projects
Unverified Commit 6170c8a9 authored by Bekerle, Patrizio's avatar Bekerle, Patrizio :fire:
Browse files

Implement complex multi-annotation adding (#37)

parent 831967d5
No related branches found
No related tags found
No related merge requests found
Pipeline #18253 failed
...@@ -139,10 +139,9 @@ export default class DBPSignatureLitElement extends DBPSignatureBaseLitElement { ...@@ -139,10 +139,9 @@ export default class DBPSignatureLitElement extends DBPSignatureBaseLitElement {
* *
* @param file * @param file
* @param annotations * @param annotations
* @param i18n
* @returns {File} * @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 need to work with the AnnotationFactory because the pdf file is broken if
// we add the multiple annotations to the file itself // we add the multiple annotations to the file itself
let pdfFactory = await utils.getAnnotationFactoryFromFile(file); let pdfFactory = await utils.getAnnotationFactoryFromFile(file);
...@@ -156,9 +155,10 @@ export default class DBPSignatureLitElement extends DBPSignatureBaseLitElement { ...@@ -156,9 +155,10 @@ export default class DBPSignatureLitElement extends DBPSignatureBaseLitElement {
return; return;
} }
const annotationKey = key1 + '-' + key2; // TODO: use real key1 names
pdfFactory = await utils.addKeyValuePdfAnnotationToAnnotationFactory( pdfFactory = await utils.addKeyValuePdfAnnotationsToAnnotationFactory(
pdfFactory, i18n, 'AppName', this.auth['user-full-name'], annotationKey, value); pdfFactory, 'AppNameDE', 'AppNameEN', this.auth['user-full-name'], key1,
"Geschaeftszahl", "Businessnumber", key2, value);
}); });
// output the AnnotationFactory as File again // output the AnnotationFactory as File again
...@@ -209,9 +209,8 @@ export default class DBPSignatureLitElement extends DBPSignatureBaseLitElement { ...@@ -209,9 +209,8 @@ export default class DBPSignatureLitElement extends DBPSignatureBaseLitElement {
* Add an annotation to a file on the queue * Add an annotation to a file on the queue
* *
* @param key * @param key
* @param i18n
*/ */
async addAnnotationToPDF(key, i18n) { async addAnnotationToPDF(key) {
const annotationKey = prompt("Please enter a key"); const annotationKey = prompt("Please enter a key");
if (annotationKey === null || annotationKey === "") { if (annotationKey === null || annotationKey === "") {
...@@ -228,8 +227,8 @@ export default class DBPSignatureLitElement extends DBPSignatureBaseLitElement { ...@@ -228,8 +227,8 @@ export default class DBPSignatureLitElement extends DBPSignatureBaseLitElement {
// console.log("file before annotation", file); // console.log("file before annotation", file);
// annotate the pwd with the key and value // annotate the pdf with the key and value
file = await utils.addKeyValuePdfAnnotation(file, i18n, 'AppName', this.auth['user-full-name'], annotationKey, annotationValue); file = await utils.addKeyValuePdfAnnotation(file, 'AppNameDE', 'AppNameEN', this.auth['user-full-name'], annotationKey, annotationValue);
// console.log("file after annotation", file); // console.log("file after annotation", file);
......
...@@ -146,14 +146,14 @@ export const getPDFSignatureCount = async (file) => { ...@@ -146,14 +146,14 @@ export const getPDFSignatureCount = async (file) => {
* Adds an annotation to a PDF file * Adds an annotation to a PDF file
* *
* @param file * @param file
* @param i18n * @param appNameDE
* @param appName * @param appNameEN
* @param personName * @param personName
* @param key * @param key
* @param value * @param value
* @returns {File} * @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(); key = key.trim();
value = value.trim(); value = value.trim();
...@@ -163,7 +163,8 @@ export const addKeyValuePdfAnnotation = async (file, i18n, appName, personName, ...@@ -163,7 +163,8 @@ export const addKeyValuePdfAnnotation = async (file, i18n, appName, personName,
} }
let annotationFactory = await getAnnotationFactoryFromFile(file); 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); return writeAnnotationFactoryToFile(annotationFactory, file);
}; };
...@@ -197,36 +198,58 @@ export const getAnnotationFactoryFromFile = async (file) => { ...@@ -197,36 +198,58 @@ export const getAnnotationFactoryFromFile = async (file) => {
* Adds a key/value annotation to a AnnotationFactory and returns the AnnotationFactory * Adds a key/value annotation to a AnnotationFactory and returns the AnnotationFactory
* *
* @param annotationFactory * @param annotationFactory
* @param i18n * @param appNameDE
* @param appName * @param appNameEN
* @param personName * @param personName
* @param key * @param key1
* @param key1NameDE
* @param key1NameEN
* @param key2
* @param value * @param value
* @returns PdfFactory * @returns PdfFactory
*/ */
export const addKeyValuePdfAnnotationToAnnotationFactory = (annotationFactory, i18n, appName, personName, key, value) => { export const addKeyValuePdfAnnotationsToAnnotationFactory = (annotationFactory, appNameDE, appNameEN, personName,
key = key.trim(); key1, key1NameDE, key1NameEN, key2, value) => {
key1 = key1.trim();
key1NameDE = key1NameDE.trim();
key1NameEN = key1NameEN.trim();
key2 = key2.trim();
value = value.trim(); value = value.trim();
// don't annotate if key or value are empty // don't annotate if key or value are empty
if (key === '' || value === '') { if (key1 === '' || key2 === '' || value === '') {
return annotationFactory; 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 page = 0;
const rect = [1, 1, 1, 1]; const rect = [0, 0, 0, 0];
const author = i18n.t('annotation-author', {
appName: appName,
personName: personName
});
const contents = 'dbp-annotation-' + key + '=' + value;
// annotationFactory.checkRect(4, rect); // annotationFactory.checkRect(4, rect);
// Create single free text annotation with print flag and 0 font size // 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 annotation_flag: 4, // enable print to be PDF/A conform
color: {r: 1, g: 1, b: 1}, // white to (maybe) hide it better 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) {" opacity: 0.001, // we can't set to 0 because of "if (opacity) {"
......
Subproject commit e728b2a0094aaa18cecc3b081238f8e189871c35 Subproject commit a8ab1f7220f86eea76e5f601c080da066496f7df
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment