[api-minor] Add a getDocument
parameter that allows disabling of the NativeImageDecoder
(e.g. for use with Node.js)
Note that I initially tried to add this as a parameter to the `PDFPageProxy.render` method, such that it could be passed to `PartialEvaluator.getOperatorList`. However, given all the different code-paths that call `getOperatorList` (there's a bunch only in `annotation.js`), this seemed to very quickly become unwieldy and thus difficult to maintain compared to simply using the existing `evaluatorOptions`.
This commit is contained in:
parent
3e5c6e4287
commit
9c34d0aa8c
@ -112,7 +112,8 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
||||
forceDataSchema: false,
|
||||
maxImageSize: -1,
|
||||
disableFontFace: false,
|
||||
cMapOptions: { url: null, packed: false }
|
||||
cMapOptions: { url: null, packed: false },
|
||||
disableNativeImageDecoder: false,
|
||||
};
|
||||
|
||||
function NativeImageDecoder(xref, resources, handler, forceDataSchema) {
|
||||
@ -388,13 +389,15 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
||||
return;
|
||||
}
|
||||
|
||||
var useNativeImageDecoder = !this.options.disableNativeImageDecoder;
|
||||
// If there is no imageMask, create the PDFImage and a lot
|
||||
// of image processing can be done here.
|
||||
var objId = 'img_' + this.idFactory.createObjId();
|
||||
operatorList.addDependency(objId);
|
||||
args = [objId, w, h];
|
||||
|
||||
if (!softMask && !mask && image instanceof JpegStream &&
|
||||
if (useNativeImageDecoder &&
|
||||
!softMask && !mask && image instanceof JpegStream &&
|
||||
NativeImageDecoder.isSupported(image, this.xref, resources)) {
|
||||
// These JPEGs don't need any more processing so we can just send it.
|
||||
operatorList.addOp(OPS.paintJpegXObject, args);
|
||||
@ -406,8 +409,9 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
||||
|
||||
// Creates native image decoder only if a JPEG image or mask is present.
|
||||
var nativeImageDecoder = null;
|
||||
if (image instanceof JpegStream || mask instanceof JpegStream ||
|
||||
softMask instanceof JpegStream) {
|
||||
if (useNativeImageDecoder &&
|
||||
(image instanceof JpegStream || mask instanceof JpegStream ||
|
||||
softMask instanceof JpegStream)) {
|
||||
nativeImageDecoder = new NativeImageDecoder(self.xref, resources,
|
||||
self.handler, self.options.forceDataSchema);
|
||||
}
|
||||
|
@ -737,7 +737,8 @@ var WorkerMessageHandler = {
|
||||
forceDataSchema: data.disableCreateObjectURL,
|
||||
maxImageSize: data.maxImageSize === undefined ? -1 : data.maxImageSize,
|
||||
disableFontFace: data.disableFontFace,
|
||||
cMapOptions: cMapOptions
|
||||
cMapOptions: cMapOptions,
|
||||
disableNativeImageDecoder: data.disableNativeImageDecoder,
|
||||
};
|
||||
|
||||
getPdfManager(data, evaluatorOptions).then(function (newPdfManager) {
|
||||
|
@ -131,6 +131,10 @@ if (typeof PDFJSDev !== 'undefined' &&
|
||||
* @property {string} docBaseUrl - (optional) The base URL of the document,
|
||||
* used when attempting to recover valid absolute URLs for annotations, and
|
||||
* outline items, that (incorrectly) only specify relative URLs.
|
||||
* @property {boolean} disableNativeImageDecoder - (optional) Disable decoding
|
||||
* of certain (simple) JPEG images in the browser. This is useful for
|
||||
* environments without DOM image support, such as e.g. Node.js.
|
||||
* The default value is `false`.
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -244,6 +248,7 @@ function getDocument(src, pdfDataRangeTransport,
|
||||
}
|
||||
|
||||
params.rangeChunkSize = params.rangeChunkSize || DEFAULT_RANGE_CHUNK_SIZE;
|
||||
params.disableNativeImageDecoder = params.disableNativeImageDecoder === true;
|
||||
|
||||
if (!worker) {
|
||||
// Worker was not provided -- creating and owning our own.
|
||||
@ -304,6 +309,7 @@ function _fetchDocument(worker, source, pdfDataRangeTransport, docId) {
|
||||
postMessageTransfers: getDefaultSetting('postMessageTransfers') &&
|
||||
!isPostMessageTransfersDisabled,
|
||||
docBaseUrl: source.docBaseUrl,
|
||||
disableNativeImageDecoder: source.disableNativeImageDecoder,
|
||||
}).then(function (workerId) {
|
||||
if (worker.destroyed) {
|
||||
throw new Error('Worker was destroyed');
|
||||
|
Loading…
Reference in New Issue
Block a user