From 527258c31677ee024e093c1844714aecf4614c0f Mon Sep 17 00:00:00 2001
From: Jonas Jenwald <jonas.jenwald@gmail.com>
Date: Fri, 9 Dec 2022 14:30:12 +0100
Subject: [PATCH] Ensure that the various layers always get the correct initial
 size (issue 15795)

---
 web/pdf_page_view.js | 7 +++++++
 web/pdf_viewer.js    | 4 ++++
 2 files changed, 11 insertions(+)

diff --git a/web/pdf_page_view.js b/web/pdf_page_view.js
index 38e344573..befa9de82 100644
--- a/web/pdf_page_view.js
+++ b/web/pdf_page_view.js
@@ -195,6 +195,13 @@ class PDFPageView {
         PDFJSDev.test("!PRODUCTION || GENERIC")) &&
       this._isStandalone
     ) {
+      // Ensure that the various layers always get the correct initial size,
+      // see issue 15795.
+      docStyle.setProperty(
+        "--scale-factor",
+        this.scale * PixelsPerInch.PDF_TO_CSS_UNITS
+      );
+
       const { optionalContentConfigPromise } = options;
       if (optionalContentConfigPromise) {
         // Ensure that the thumbnails always display the *initial* document
diff --git a/web/pdf_viewer.js b/web/pdf_viewer.js
index 40ed8c78e..ec3ffbeb2 100644
--- a/web/pdf_viewer.js
+++ b/web/pdf_viewer.js
@@ -747,6 +747,10 @@ class PDFViewer {
         const viewport = firstPdfPage.getViewport({
           scale: scale * PixelsPerInch.PDF_TO_CSS_UNITS,
         });
+        // Ensure that the various layers always get the correct initial size,
+        // see issue 15795.
+        docStyle.setProperty("--scale-factor", viewport.scale);
+
         const textLayerFactory =
           textLayerMode !== TextLayerMode.DISABLE && !isPureXfa ? this : null;
         const annotationLayerFactory =