From e49d03985347f9e116eec882d9fc0eab5fa4aca6 Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Thu, 23 Jun 2022 16:27:03 +0200 Subject: [PATCH] Correctly order added annotations when saving or printing - the annotations must be rendered in the same order as the chronological one. - fix a bug in document.js which avoids to read a saved pdf correctly in Acrobat: there is no need to reset the xref state: it's done in worker.js once everything has been saved. --- src/core/annotation.js | 24 +++++------------------- src/core/document.js | 1 - test/test_manifest.json | 6 ++---- 3 files changed, 7 insertions(+), 24 deletions(-) diff --git a/src/core/annotation.js b/src/core/annotation.js index 3e9d0d577..638456b97 100644 --- a/src/core/annotation.js +++ b/src/core/annotation.js @@ -245,9 +245,9 @@ class AnnotationFactory { static async saveNewAnnotations(evaluator, task, annotations) { const xref = evaluator.xref; let baseFontRef; - const results = []; const dependencies = []; const promises = []; + for (const annotation of annotations) { switch (annotation.annotationType) { case AnnotationEditorType.FREETEXT: @@ -266,7 +266,6 @@ class AnnotationFactory { FreeTextAnnotation.createNewAnnotation( xref, annotation, - results, dependencies, { evaluator, task, baseFontRef } ) @@ -274,20 +273,13 @@ class AnnotationFactory { break; case AnnotationEditorType.INK: promises.push( - InkAnnotation.createNewAnnotation( - xref, - annotation, - results, - dependencies - ) + InkAnnotation.createNewAnnotation(xref, annotation, dependencies) ); } } - await Promise.all(promises); - return { - annotations: results, + annotations: await Promise.all(promises), dependencies, }; } @@ -1360,13 +1352,7 @@ class MarkupAnnotation extends Annotation { this._streams.push(this.appearance, appearanceStream); } - static async createNewAnnotation( - xref, - annotation, - results, - dependencies, - params - ) { + static async createNewAnnotation(xref, annotation, dependencies, params) { const annotationRef = xref.getNewRef(); const apRef = xref.getNewRef(); const annotationDict = this.createNewDict(annotation, xref, { apRef }); @@ -1385,7 +1371,7 @@ class MarkupAnnotation extends Annotation { : null; writeObject(annotationRef, annotationDict, buffer, transform); - results.push({ ref: annotationRef, data: buffer.join("") }); + return { ref: annotationRef, data: buffer.join("") }; } static async createNewPrintAnnotation(xref, annotation, params) { diff --git a/src/core/document.js b/src/core/document.js index 069d1f361..c89078d90 100644 --- a/src/core/document.js +++ b/src/core/document.js @@ -314,7 +314,6 @@ class Page { ...newData.annotations ); - this.xref.resetNewRef(); return objects; } diff --git a/test/test_manifest.json b/test/test_manifest.json index 5cb901d6b..7b794dc9c 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -6638,8 +6638,7 @@ "fontSize": 10, "value": "Hello World", "pageIndex": 0, - "rect": [67.5, 543, 119, 556.5], - "orderIndex": 0 + "rect": [67.5, 543, 119, 556.5] }, "pdfjs_internal_editor_1": { "annotationType": 15, @@ -6662,8 +6661,7 @@ ] }], "pageIndex": 0, - "rect": [71.5, 534.5, 115, 562], - "orderIndex": 1 + "rect": [71.5, 534.5, 115, 562] } } }