diff --git a/web/app.js b/web/app.js index 80d64f220..1d7fed31e 100644 --- a/web/app.js +++ b/web/app.js @@ -399,6 +399,7 @@ let PDFViewerApplication = { renderInteractiveForms: viewerPrefs['renderInteractiveForms'], enablePrintAutoRotate: viewerPrefs['enablePrintAutoRotate'], useOnlyCssZoom: PDFJS.useOnlyCssZoom, + maxCanvasPixels: PDFJS.maxCanvasPixels, }); pdfRenderingQueue.setViewer(this.pdfViewer); pdfLinkService.setViewer(this.pdfViewer); diff --git a/web/base_viewer.js b/web/base_viewer.js index acc2d439f..259817da9 100644 --- a/web/base_viewer.js +++ b/web/base_viewer.js @@ -50,6 +50,9 @@ const DEFAULT_CACHE_SIZE = 10; * @property {string} renderer - 'canvas' or 'svg'. The default is 'canvas'. * @property {boolean} useOnlyCssZoom - (optional) Enables CSS only zooming. * The default value is `false`. + * @property {number} maxCanvasPixels - (optional) The maximum supported canvas + * size in total pixels, i.e. width * height. Use -1 for no limit. + * The default value is 4096 * 4096 (16 mega-pixels). * @property {IL10n} l10n - Localization service. */ @@ -114,6 +117,7 @@ class BaseViewer { this.enablePrintAutoRotate = options.enablePrintAutoRotate || false; this.renderer = options.renderer || RendererType.CANVAS; this.useOnlyCssZoom = options.useOnlyCssZoom || false; + this.maxCanvasPixels = options.maxCanvasPixels; this.l10n = options.l10n || NullL10n; this.defaultRenderingQueue = !options.renderingQueue; @@ -381,6 +385,7 @@ class BaseViewer { renderInteractiveForms: this.renderInteractiveForms, renderer: this.renderer, useOnlyCssZoom: this.useOnlyCssZoom, + maxCanvasPixels: this.maxCanvasPixels, l10n: this.l10n, }); bindOnAfterAndBeforeDraw(pageView); diff --git a/web/pdf_page_view.js b/web/pdf_page_view.js index df2cdd9ab..5abbf0703 100644 --- a/web/pdf_page_view.js +++ b/web/pdf_page_view.js @@ -18,10 +18,11 @@ import { RendererType, roundToDivide } from './ui_utils'; import { - createPromiseCapability, PDFJS, RenderingCancelledException, SVGGraphics + createPromiseCapability, RenderingCancelledException, SVGGraphics } from 'pdfjs-lib'; import { getGlobalEventBus } from './dom_events'; import { RenderingStates } from './pdf_rendering_queue'; +import { viewerCompatibilityParams } from './viewer_compatibility'; /** * @typedef {Object} PDFPageViewOptions @@ -40,9 +41,14 @@ import { RenderingStates } from './pdf_rendering_queue'; * @property {string} renderer - 'canvas' or 'svg'. The default is 'canvas'. * @property {boolean} useOnlyCssZoom - (optional) Enables CSS only zooming. * The default value is `false`. + * @property {number} maxCanvasPixels - (optional) The maximum supported canvas + * size in total pixels, i.e. width * height. Use -1 for no limit. + * The default value is 4096 * 4096 (16 mega-pixels). * @property {IL10n} l10n - Localization service. */ +const MAX_CANVAS_PIXELS = viewerCompatibilityParams.maxCanvasPixels || 16777216; + /** * @implements {IRenderableView} */ @@ -67,6 +73,7 @@ class PDFPageView { this.enhanceTextSelection = options.enhanceTextSelection || false; this.renderInteractiveForms = options.renderInteractiveForms || false; this.useOnlyCssZoom = options.useOnlyCssZoom || false; + this.maxCanvasPixels = options.maxCanvasPixels || MAX_CANVAS_PIXELS; this.eventBus = options.eventBus || getGlobalEventBus(); this.renderingQueue = options.renderingQueue; @@ -211,11 +218,11 @@ class PDFPageView { } let isScalingRestricted = false; - if (this.canvas && PDFJS.maxCanvasPixels > 0) { + if (this.canvas && this.maxCanvasPixels > 0) { let outputScale = this.outputScale; if (((Math.floor(this.viewport.width) * outputScale.sx) | 0) * ((Math.floor(this.viewport.height) * outputScale.sy) | 0) > - PDFJS.maxCanvasPixels) { + this.maxCanvasPixels) { isScalingRestricted = true; } } @@ -529,9 +536,9 @@ class PDFPageView { outputScale.scaled = true; } - if (PDFJS.maxCanvasPixels > 0) { + if (this.maxCanvasPixels > 0) { let pixelsInViewport = viewport.width * viewport.height; - let maxScale = Math.sqrt(PDFJS.maxCanvasPixels / pixelsInViewport); + let maxScale = Math.sqrt(this.maxCanvasPixels / pixelsInViewport); if (outputScale.sx > maxScale || outputScale.sy > maxScale) { outputScale.sx = maxScale; outputScale.sy = maxScale;