diff --git a/examples/mobile-viewer/viewer.js b/examples/mobile-viewer/viewer.js index 2501dbdfa..2b8f3854a 100644 --- a/examples/mobile-viewer/viewer.js +++ b/examples/mobile-viewer/viewer.js @@ -23,7 +23,7 @@ if (typeof PDFJS === 'undefined' || !PDFJS.PDFViewer || !PDFJS.getDocument) { var USE_ONLY_CSS_ZOOM = true; var TEXT_LAYER_MODE = 0; // DISABLE -PDFJS.maxImageSize = 1024 * 1024; +var MAX_IMAGE_SIZE = 1024 * 1024; PDFJS.cMapUrl = '../../node_modules/pdfjs-dist/cmaps/'; PDFJS.cMapPacked = true; @@ -62,7 +62,10 @@ var PDFViewerApplication = { this.setTitleUsingUrl(url); // Loading document. - var loadingTask = PDFJS.getDocument(url); + var loadingTask = PDFJS.getDocument({ + url: url, + maxImageSize: MAX_IMAGE_SIZE, + }); this.pdfLoadingTask = loadingTask; loadingTask.onProgress = function (progressData) { diff --git a/src/core/worker.js b/src/core/worker.js index 12a75df53..742718aad 100644 --- a/src/core/worker.js +++ b/src/core/worker.js @@ -614,7 +614,7 @@ var WorkerMessageHandler = { var evaluatorOptions = { forceDataSchema: data.disableCreateObjectURL, - maxImageSize: data.maxImageSize === undefined ? -1 : data.maxImageSize, + maxImageSize: data.maxImageSize, disableFontFace: data.disableFontFace, nativeImageDecoderSupport: data.nativeImageDecoderSupport, ignoreErrors: data.ignoreErrors, diff --git a/src/display/api.js b/src/display/api.js index bdec3bf94..545c6e1ee 100644 --- a/src/display/api.js +++ b/src/display/api.js @@ -150,6 +150,9 @@ function setPDFNetworkStreamFactory(pdfNetworkStreamFactory) { * `getOperatorList`, `getTextContent`, and `RenderTask`, when the associated * PDF data cannot be successfully parsed, instead of attempting to recover * whatever possible of the data. The default value is `false`. + * @property {number} maxImageSize - (optional) The maximum allowed image size + * in total pixels, i.e. width * height. Images above this value will not be + * rendered. Use -1 for no limit, which is also the default value. */ /** @@ -195,7 +198,7 @@ function getDocument(src) { source = src; } - var params = {}; + let params = Object.create(null); var rangeTransport = null; let worker = null; var CMapReaderFactory = DOMCMapReaderFactory; @@ -237,11 +240,14 @@ function getDocument(src) { params.rangeChunkSize = params.rangeChunkSize || DEFAULT_RANGE_CHUNK_SIZE; params.ignoreErrors = params.stopAtErrors !== true; - const nativeImageDecoderValues = Object.values(NativeImageDecoding); + const NativeImageDecoderValues = Object.values(NativeImageDecoding); if (params.nativeImageDecoderSupport === undefined || - !nativeImageDecoderValues.includes(params.nativeImageDecoderSupport)) { + !NativeImageDecoderValues.includes(params.nativeImageDecoderSupport)) { params.nativeImageDecoderSupport = NativeImageDecoding.DECODE; } + if (!Number.isInteger(params.maxImageSize)) { + params.maxImageSize = -1; + } // Set the main-thread verbosity level. setVerbosityLevel(params.verbosity); @@ -327,7 +333,7 @@ function _fetchDocument(worker, source, pdfDataRangeTransport, docId) { rangeChunkSize: source.rangeChunkSize, length: source.length, }, - maxImageSize: getDefaultSetting('maxImageSize'), + maxImageSize: source.maxImageSize, disableFontFace: getDefaultSetting('disableFontFace'), disableCreateObjectURL: getDefaultSetting('disableCreateObjectURL'), postMessageTransfers: worker.postMessageTransfers, diff --git a/src/display/dom_utils.js b/src/display/dom_utils.js index 69a9e974c..776115cbd 100644 --- a/src/display/dom_utils.js +++ b/src/display/dom_utils.js @@ -349,8 +349,6 @@ function getDefaultSetting(id) { return globalSettings ? globalSettings.cMapUrl : null; case 'cMapPacked': return globalSettings ? globalSettings.cMapPacked : false; - case 'maxImageSize': - return globalSettings ? globalSettings.maxImageSize : -1; case 'isEvalSupported': return globalSettings ? globalSettings.isEvalSupported : true; default: diff --git a/src/display/global.js b/src/display/global.js index 4c3a5f4fe..24d36ccdc 100644 --- a/src/display/global.js +++ b/src/display/global.js @@ -65,14 +65,6 @@ PDFJS.Util = Util; PDFJS.PageViewport = PageViewport; PDFJS.createPromiseCapability = createPromiseCapability; -/** - * The maximum allowed image size in total pixels e.g. width * height. Images - * above this value will not be drawn. Use -1 for no limit. - * @var {number} - */ -PDFJS.maxImageSize = (PDFJS.maxImageSize === undefined ? - -1 : PDFJS.maxImageSize); - /** * The url of where the predefined Adobe CMaps are located. Include trailing * slash. diff --git a/web/app_options.js b/web/app_options.js index a2e53b7f0..638410303 100644 --- a/web/app_options.js +++ b/web/app_options.js @@ -128,6 +128,11 @@ const defaultOptions = { kind: OptionKind.VIEWER, }, + maxImageSize: { + /** @type {number} */ + value: -1, + kind: OptionKind.API, + }, postMessageTransfers: { /** @type {boolean} */ value: true,