Move the maxImageSize
option from the global PDFJS
object and into getDocument
instead
This commit is contained in:
parent
b0956a5d91
commit
b674409397
@ -23,7 +23,7 @@ if (typeof PDFJS === 'undefined' || !PDFJS.PDFViewer || !PDFJS.getDocument) {
|
|||||||
|
|
||||||
var USE_ONLY_CSS_ZOOM = true;
|
var USE_ONLY_CSS_ZOOM = true;
|
||||||
var TEXT_LAYER_MODE = 0; // DISABLE
|
var TEXT_LAYER_MODE = 0; // DISABLE
|
||||||
PDFJS.maxImageSize = 1024 * 1024;
|
var MAX_IMAGE_SIZE = 1024 * 1024;
|
||||||
PDFJS.cMapUrl = '../../node_modules/pdfjs-dist/cmaps/';
|
PDFJS.cMapUrl = '../../node_modules/pdfjs-dist/cmaps/';
|
||||||
PDFJS.cMapPacked = true;
|
PDFJS.cMapPacked = true;
|
||||||
|
|
||||||
@ -62,7 +62,10 @@ var PDFViewerApplication = {
|
|||||||
this.setTitleUsingUrl(url);
|
this.setTitleUsingUrl(url);
|
||||||
|
|
||||||
// Loading document.
|
// Loading document.
|
||||||
var loadingTask = PDFJS.getDocument(url);
|
var loadingTask = PDFJS.getDocument({
|
||||||
|
url: url,
|
||||||
|
maxImageSize: MAX_IMAGE_SIZE,
|
||||||
|
});
|
||||||
this.pdfLoadingTask = loadingTask;
|
this.pdfLoadingTask = loadingTask;
|
||||||
|
|
||||||
loadingTask.onProgress = function (progressData) {
|
loadingTask.onProgress = function (progressData) {
|
||||||
|
@ -614,7 +614,7 @@ var WorkerMessageHandler = {
|
|||||||
|
|
||||||
var evaluatorOptions = {
|
var evaluatorOptions = {
|
||||||
forceDataSchema: data.disableCreateObjectURL,
|
forceDataSchema: data.disableCreateObjectURL,
|
||||||
maxImageSize: data.maxImageSize === undefined ? -1 : data.maxImageSize,
|
maxImageSize: data.maxImageSize,
|
||||||
disableFontFace: data.disableFontFace,
|
disableFontFace: data.disableFontFace,
|
||||||
nativeImageDecoderSupport: data.nativeImageDecoderSupport,
|
nativeImageDecoderSupport: data.nativeImageDecoderSupport,
|
||||||
ignoreErrors: data.ignoreErrors,
|
ignoreErrors: data.ignoreErrors,
|
||||||
|
@ -150,6 +150,9 @@ function setPDFNetworkStreamFactory(pdfNetworkStreamFactory) {
|
|||||||
* `getOperatorList`, `getTextContent`, and `RenderTask`, when the associated
|
* `getOperatorList`, `getTextContent`, and `RenderTask`, when the associated
|
||||||
* PDF data cannot be successfully parsed, instead of attempting to recover
|
* PDF data cannot be successfully parsed, instead of attempting to recover
|
||||||
* whatever possible of the data. The default value is `false`.
|
* 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;
|
source = src;
|
||||||
}
|
}
|
||||||
|
|
||||||
var params = {};
|
let params = Object.create(null);
|
||||||
var rangeTransport = null;
|
var rangeTransport = null;
|
||||||
let worker = null;
|
let worker = null;
|
||||||
var CMapReaderFactory = DOMCMapReaderFactory;
|
var CMapReaderFactory = DOMCMapReaderFactory;
|
||||||
@ -237,11 +240,14 @@ function getDocument(src) {
|
|||||||
params.rangeChunkSize = params.rangeChunkSize || DEFAULT_RANGE_CHUNK_SIZE;
|
params.rangeChunkSize = params.rangeChunkSize || DEFAULT_RANGE_CHUNK_SIZE;
|
||||||
params.ignoreErrors = params.stopAtErrors !== true;
|
params.ignoreErrors = params.stopAtErrors !== true;
|
||||||
|
|
||||||
const nativeImageDecoderValues = Object.values(NativeImageDecoding);
|
const NativeImageDecoderValues = Object.values(NativeImageDecoding);
|
||||||
if (params.nativeImageDecoderSupport === undefined ||
|
if (params.nativeImageDecoderSupport === undefined ||
|
||||||
!nativeImageDecoderValues.includes(params.nativeImageDecoderSupport)) {
|
!NativeImageDecoderValues.includes(params.nativeImageDecoderSupport)) {
|
||||||
params.nativeImageDecoderSupport = NativeImageDecoding.DECODE;
|
params.nativeImageDecoderSupport = NativeImageDecoding.DECODE;
|
||||||
}
|
}
|
||||||
|
if (!Number.isInteger(params.maxImageSize)) {
|
||||||
|
params.maxImageSize = -1;
|
||||||
|
}
|
||||||
|
|
||||||
// Set the main-thread verbosity level.
|
// Set the main-thread verbosity level.
|
||||||
setVerbosityLevel(params.verbosity);
|
setVerbosityLevel(params.verbosity);
|
||||||
@ -327,7 +333,7 @@ function _fetchDocument(worker, source, pdfDataRangeTransport, docId) {
|
|||||||
rangeChunkSize: source.rangeChunkSize,
|
rangeChunkSize: source.rangeChunkSize,
|
||||||
length: source.length,
|
length: source.length,
|
||||||
},
|
},
|
||||||
maxImageSize: getDefaultSetting('maxImageSize'),
|
maxImageSize: source.maxImageSize,
|
||||||
disableFontFace: getDefaultSetting('disableFontFace'),
|
disableFontFace: getDefaultSetting('disableFontFace'),
|
||||||
disableCreateObjectURL: getDefaultSetting('disableCreateObjectURL'),
|
disableCreateObjectURL: getDefaultSetting('disableCreateObjectURL'),
|
||||||
postMessageTransfers: worker.postMessageTransfers,
|
postMessageTransfers: worker.postMessageTransfers,
|
||||||
|
@ -349,8 +349,6 @@ function getDefaultSetting(id) {
|
|||||||
return globalSettings ? globalSettings.cMapUrl : null;
|
return globalSettings ? globalSettings.cMapUrl : null;
|
||||||
case 'cMapPacked':
|
case 'cMapPacked':
|
||||||
return globalSettings ? globalSettings.cMapPacked : false;
|
return globalSettings ? globalSettings.cMapPacked : false;
|
||||||
case 'maxImageSize':
|
|
||||||
return globalSettings ? globalSettings.maxImageSize : -1;
|
|
||||||
case 'isEvalSupported':
|
case 'isEvalSupported':
|
||||||
return globalSettings ? globalSettings.isEvalSupported : true;
|
return globalSettings ? globalSettings.isEvalSupported : true;
|
||||||
default:
|
default:
|
||||||
|
@ -65,14 +65,6 @@ PDFJS.Util = Util;
|
|||||||
PDFJS.PageViewport = PageViewport;
|
PDFJS.PageViewport = PageViewport;
|
||||||
PDFJS.createPromiseCapability = createPromiseCapability;
|
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
|
* The url of where the predefined Adobe CMaps are located. Include trailing
|
||||||
* slash.
|
* slash.
|
||||||
|
@ -128,6 +128,11 @@ const defaultOptions = {
|
|||||||
kind: OptionKind.VIEWER,
|
kind: OptionKind.VIEWER,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
maxImageSize: {
|
||||||
|
/** @type {number} */
|
||||||
|
value: -1,
|
||||||
|
kind: OptionKind.API,
|
||||||
|
},
|
||||||
postMessageTransfers: {
|
postMessageTransfers: {
|
||||||
/** @type {boolean} */
|
/** @type {boolean} */
|
||||||
value: true,
|
value: true,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user