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 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) {
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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:
|
||||
|
@ -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.
|
||||
|
@ -128,6 +128,11 @@ const defaultOptions = {
|
||||
kind: OptionKind.VIEWER,
|
||||
},
|
||||
|
||||
maxImageSize: {
|
||||
/** @type {number} */
|
||||
value: -1,
|
||||
kind: OptionKind.API,
|
||||
},
|
||||
postMessageTransfers: {
|
||||
/** @type {boolean} */
|
||||
value: true,
|
||||
|
Loading…
x
Reference in New Issue
Block a user