From 5e44b241b221b15fd0e8fb56b153b444ccba45a7 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Wed, 5 Aug 2020 12:43:29 +0200 Subject: [PATCH 1/2] [api-minor] Fix the `annotationStorage` parameter in `PDFPageProxy.render` While the parameter name (clearly) suggests that an `AnnotationStorage`-instance is expected, looking at the only call-sites that include the parameter (i.e. the `PDFPrintServiceFactory` instances) it actually contains just a normal Object. Hence it seems much more reasonable to actually pass a valid `AnnotationStorage`-instance, as the name suggests, and simply have `PDFPageProxy.render` do the `annotationStorage.getAll()` call. (Since we cannot send an `AnnotationStorage`-instance as-is to the worker-thread, given the "structured clone algorithm".) --- src/display/api.js | 3 ++- web/firefox_print_service.js | 2 +- web/pdf_print_service.js | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/display/api.js b/src/display/api.js index ba7bfdabfd2fa..571c2449482a3 100644 --- a/src/display/api.js +++ b/src/display/api.js @@ -1133,7 +1133,8 @@ class PDFPageProxy { pageIndex: this._pageIndex, intent: renderingIntent, renderInteractiveForms: renderInteractiveForms === true, - annotationStorage, + annotationStorage: + (annotationStorage && annotationStorage.getAll()) || null, }); } diff --git a/web/firefox_print_service.js b/web/firefox_print_service.js index 11cd0f1312b85..3098c519e60a6 100644 --- a/web/firefox_print_service.js +++ b/web/firefox_print_service.js @@ -57,7 +57,7 @@ function composePage( transform: [PRINT_UNITS, 0, 0, PRINT_UNITS, 0, 0], viewport: pdfPage.getViewport({ scale: 1, rotation: size.rotation }), intent: "print", - annotationStorage: pdfDocument.annotationStorage.getAll(), + annotationStorage: pdfDocument.annotationStorage, }; return pdfPage.render(renderContext).promise; }) diff --git a/web/pdf_print_service.js b/web/pdf_print_service.js index ebde93a0ee9c1..2321f0cf34615 100644 --- a/web/pdf_print_service.js +++ b/web/pdf_print_service.js @@ -54,7 +54,7 @@ function renderPage( transform: [PRINT_UNITS, 0, 0, PRINT_UNITS, 0, 0], viewport: pdfPage.getViewport({ scale: 1, rotation: size.rotation }), intent: "print", - annotationStorage: pdfDocument.annotationStorage.getAll(), + annotationStorage: pdfDocument.annotationStorage, }; return pdfPage.render(renderContext).promise; }) From a6c1ef82ae148d5661def6f1ce47ccc3427c965b Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Wed, 5 Aug 2020 12:57:32 +0200 Subject: [PATCH 2/2] Update `BaseViewer.createAnnotationLayerBuilder`, and `PDFPageView`, to accurately reflect `IPDFAnnotationLayerFactory` (PR 12147 follow-up) --- web/base_viewer.js | 6 +++++- web/interfaces.js | 3 ++- web/pdf_page_view.js | 4 ++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/web/base_viewer.js b/web/base_viewer.js index ede70ee5f7234..e4dce389ce784 100644 --- a/web/base_viewer.js +++ b/web/base_viewer.js @@ -435,6 +435,8 @@ class BaseViewer { const pagesCount = pdfDocument.numPages; const firstPagePromise = pdfDocument.getPage(1); + const annotationStorage = pdfDocument.annotationStorage; + this._pagesCapability.promise.then(() => { this.eventBus.dispatch("pagesloaded", { source: this, @@ -481,6 +483,7 @@ class BaseViewer { eventBus: this.eventBus, id: pageNum, scale, + annotationStorage, defaultViewport: viewport.clone(), renderingQueue: this.renderingQueue, textLayerFactory, @@ -1153,6 +1156,7 @@ class BaseViewer { createAnnotationLayerBuilder( pageDiv, pdfPage, + annotationStorage = null, imageResourcesPath = "", renderInteractiveForms = false, l10n = NullL10n @@ -1160,11 +1164,11 @@ class BaseViewer { return new AnnotationLayerBuilder({ pageDiv, pdfPage, + annotationStorage, imageResourcesPath, renderInteractiveForms, linkService: this.linkService, downloadManager: this.downloadManager, - annotationStorage: this.pdfDocument.annotationStorage, l10n, }); } diff --git a/web/interfaces.js b/web/interfaces.js index 7db2de726f147..81dd4b2e077e5 100644 --- a/web/interfaces.js +++ b/web/interfaces.js @@ -165,7 +165,8 @@ class IPDFAnnotationLayerFactory { /** * @param {HTMLDivElement} pageDiv * @param {PDFPage} pdfPage - * @param {AnnotationStorage} [annotationStorage] + * @param {AnnotationStorage} [annotationStorage] - Storage for annotation + * data in forms. * @param {string} [imageResourcesPath] - Path for image resources, mainly * for annotation icons. Include trailing slash. * @param {boolean} renderInteractiveForms diff --git a/web/pdf_page_view.js b/web/pdf_page_view.js index ecf0326f8d899..966f5b6ac963f 100644 --- a/web/pdf_page_view.js +++ b/web/pdf_page_view.js @@ -38,6 +38,8 @@ import { viewerCompatibilityParams } from "./viewer_compatibility.js"; * @property {number} id - The page unique ID (normally its number). * @property {number} scale - The page scale display. * @property {PageViewport} defaultViewport - The page viewport. + * @property {AnnotationStorage} [annotationStorage] - Storage for annotation + * data in forms. The default value is `null`. * @property {PDFRenderingQueue} renderingQueue - The rendering queue object. * @property {IPDFTextLayerFactory} textLayerFactory * @property {number} [textLayerMode] - Controls if the text layer used for @@ -81,6 +83,7 @@ class PDFPageView { this.rotation = 0; this.scale = options.scale || DEFAULT_SCALE; this.viewport = defaultViewport; + this._annotationStorage = options.annotationStorage || null; this.pdfPageRotate = defaultViewport.rotation; this.hasRestrictedScaling = false; this.textLayerMode = Number.isInteger(options.textLayerMode) @@ -533,6 +536,7 @@ class PDFPageView { this.annotationLayer = this.annotationLayerFactory.createAnnotationLayerBuilder( div, pdfPage, + this._annotationStorage, this.imageResourcesPath, this.renderInteractiveForms, this.l10n