diff --git a/web/annotation_layer_builder.js b/web/annotation_layer_builder.js index fc1707a74..9b1a633b7 100644 --- a/web/annotation_layer_builder.js +++ b/web/annotation_layer_builder.js @@ -60,9 +60,11 @@ class AnnotationLayerBuilder { /** * @param {PageViewport} viewport * @param {string} intent (default value is 'display') + * @returns {Promise} A promise that is resolved when rendering of the + * annotations is complete. */ render(viewport, intent = "display") { - this.pdfPage.getAnnotations({ intent }).then(annotations => { + return this.pdfPage.getAnnotations({ intent }).then(annotations => { if (this._cancelled) { return; } diff --git a/web/pdf_page_view.js b/web/pdf_page_view.js index 966f5b6ac..e0eeee9fe 100644 --- a/web/pdf_page_view.js +++ b/web/pdf_page_view.js @@ -142,6 +142,24 @@ class PDFPageView { } } + /** + * @private + */ + async _renderAnnotationLayer() { + let error = null; + try { + await this.annotationLayer.render(this.viewport, "display"); + } catch (ex) { + error = ex; + } finally { + this.eventBus.dispatch("annotationlayerrendered", { + source: this, + pageNumber: this.id, + error, + }); + } + } + /** * @private */ @@ -384,7 +402,7 @@ class PDFPageView { } if (redrawAnnotations && this.annotationLayer) { - this.annotationLayer.render(this.viewport, "display"); + this._renderAnnotationLayer(); } } @@ -542,7 +560,7 @@ class PDFPageView { this.l10n ); } - this.annotationLayer.render(this.viewport, "display"); + this._renderAnnotationLayer(); } div.setAttribute("data-loaded", true);