Merge pull request #9480 from Snuffleupagus/refactor-worker-options
[api-major] Move the worker related options from the global `PDFJS` object
This commit is contained in:
commit
99060e2485
@ -15,7 +15,8 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
PDFJS.workerSrc = '../../node_modules/pdfjs-dist/build/pdf.worker.js';
|
PDFJS.GlobalWorkerOptions.workerSrc =
|
||||||
|
'../../node_modules/pdfjs-dist/build/pdf.worker.js';
|
||||||
|
|
||||||
var DEFAULT_URL = '../../test/pdfs/f1040.pdf';
|
var DEFAULT_URL = '../../test/pdfs/f1040.pdf';
|
||||||
var DEFAULT_SCALE = 1.0;
|
var DEFAULT_SCALE = 1.0;
|
||||||
|
@ -8,7 +8,8 @@ require('pdfjs-dist');
|
|||||||
var pdfPath = '../helloworld/helloworld.pdf';
|
var pdfPath = '../helloworld/helloworld.pdf';
|
||||||
|
|
||||||
// Setting worker path to worker bundle.
|
// Setting worker path to worker bundle.
|
||||||
PDFJS.workerSrc = '../../build/browserify/pdf.worker.bundle.js';
|
PDFJS.GlobalWorkerOptions.workerSrc =
|
||||||
|
'../../build/browserify/pdf.worker.bundle.js';
|
||||||
|
|
||||||
// Loading a document.
|
// Loading a document.
|
||||||
var loadingTask = PDFJS.getDocument(pdfPath);
|
var loadingTask = PDFJS.getDocument(pdfPath);
|
||||||
|
@ -22,7 +22,8 @@ if (!PDFJS.PDFViewer || !PDFJS.getDocument) {
|
|||||||
|
|
||||||
// The workerSrc property shall be specified.
|
// The workerSrc property shall be specified.
|
||||||
//
|
//
|
||||||
PDFJS.workerSrc = '../../node_modules/pdfjs-dist/build/pdf.worker.js';
|
PDFJS.GlobalWorkerOptions.workerSrc =
|
||||||
|
'../../node_modules/pdfjs-dist/build/pdf.worker.js';
|
||||||
|
|
||||||
// Some PDFs need external cmaps.
|
// Some PDFs need external cmaps.
|
||||||
//
|
//
|
||||||
|
@ -22,7 +22,8 @@ if (!PDFJS.PDFViewer || !PDFJS.getDocument) {
|
|||||||
|
|
||||||
// The workerSrc property shall be specified.
|
// The workerSrc property shall be specified.
|
||||||
//
|
//
|
||||||
PDFJS.workerSrc = '../../node_modules/pdfjs-dist/build/pdf.worker.js';
|
PDFJS.GlobalWorkerOptions.workerSrc =
|
||||||
|
'../../node_modules/pdfjs-dist/build/pdf.worker.js';
|
||||||
|
|
||||||
// Some PDFs need external cmaps.
|
// Some PDFs need external cmaps.
|
||||||
//
|
//
|
||||||
|
@ -22,7 +22,8 @@ if (!PDFJS.PDFSinglePageViewer || !PDFJS.getDocument) {
|
|||||||
|
|
||||||
// The workerSrc property shall be specified.
|
// The workerSrc property shall be specified.
|
||||||
//
|
//
|
||||||
PDFJS.workerSrc = '../../node_modules/pdfjs-dist/build/pdf.worker.js';
|
PDFJS.GlobalWorkerOptions.workerSrc =
|
||||||
|
'../../node_modules/pdfjs-dist/build/pdf.worker.js';
|
||||||
|
|
||||||
// Some PDFs need external cmaps.
|
// Some PDFs need external cmaps.
|
||||||
//
|
//
|
||||||
|
@ -2,17 +2,19 @@
|
|||||||
|
|
||||||
// In production, the bundled pdf.js shall be used instead of SystemJS.
|
// In production, the bundled pdf.js shall be used instead of SystemJS.
|
||||||
Promise.all([System.import('pdfjs/display/api'),
|
Promise.all([System.import('pdfjs/display/api'),
|
||||||
System.import('pdfjs/display/global'),
|
System.import('pdfjs/display/worker_options'),
|
||||||
System.import('pdfjs/display/network'),
|
System.import('pdfjs/display/network'),
|
||||||
System.resolve('pdfjs/worker_loader')])
|
System.resolve('pdfjs/worker_loader')])
|
||||||
.then(function (modules) {
|
.then(function (modules) {
|
||||||
var api = modules[0], global = modules[1], network = modules[2];
|
var api = modules[0];
|
||||||
|
var GlobalWorkerOptions = modules[1].GlobalWorkerOptions;
|
||||||
|
var network = modules[2];
|
||||||
api.setPDFNetworkStreamFactory((params) => {
|
api.setPDFNetworkStreamFactory((params) => {
|
||||||
return new network.PDFNetworkStream(params);
|
return new network.PDFNetworkStream(params);
|
||||||
});
|
});
|
||||||
|
|
||||||
// In production, change this to point to the built `pdf.worker.js` file.
|
// In production, change this to point to the built `pdf.worker.js` file.
|
||||||
global.PDFJS.workerSrc = modules[3];
|
GlobalWorkerOptions.workerSrc = modules[3];
|
||||||
|
|
||||||
// Fetch the PDF document from the URL using promises.
|
// Fetch the PDF document from the URL using promises.
|
||||||
api.getDocument('helloworld.pdf').then(function (pdf) {
|
api.getDocument('helloworld.pdf').then(function (pdf) {
|
||||||
|
@ -22,7 +22,8 @@
|
|||||||
//
|
//
|
||||||
// The workerSrc property shall be specified.
|
// The workerSrc property shall be specified.
|
||||||
//
|
//
|
||||||
PDFJS.workerSrc = '../../node_modules/pdfjs-dist/build/pdf.worker.js';
|
PDFJS.GlobalWorkerOptions.workerSrc =
|
||||||
|
'../../node_modules/pdfjs-dist/build/pdf.worker.js';
|
||||||
|
|
||||||
//
|
//
|
||||||
// Asynchronous download PDF
|
// Asynchronous download PDF
|
||||||
|
@ -34,7 +34,8 @@
|
|||||||
//
|
//
|
||||||
// The workerSrc property shall be specified.
|
// The workerSrc property shall be specified.
|
||||||
//
|
//
|
||||||
PDFJS.workerSrc = '../../node_modules/pdfjs-dist/build/pdf.worker.js';
|
PDFJS.GlobalWorkerOptions.workerSrc =
|
||||||
|
'../../node_modules/pdfjs-dist/build/pdf.worker.js';
|
||||||
|
|
||||||
// Opening PDF by passing its binary data as a string. It is still preferable
|
// Opening PDF by passing its binary data as a string. It is still preferable
|
||||||
// to use Uint8Array, but string or array-like structure will work too.
|
// to use Uint8Array, but string or array-like structure will work too.
|
||||||
|
@ -33,7 +33,8 @@
|
|||||||
// pdf.js's one, or the pdf.js is executed via eval(), the workerSrc property
|
// pdf.js's one, or the pdf.js is executed via eval(), the workerSrc property
|
||||||
// shall be specified.
|
// shall be specified.
|
||||||
//
|
//
|
||||||
// PDFJS.workerSrc = '../../node_modules/pdfjs-dist/build/pdf.worker.js';
|
// PDFJS.GlobalWorkerOptions.workerSrc =
|
||||||
|
// '../../node_modules/pdfjs-dist/build/pdf.worker.js';
|
||||||
|
|
||||||
var pdfDoc = null,
|
var pdfDoc = null,
|
||||||
pageNum = 1,
|
pageNum = 1,
|
||||||
|
@ -24,10 +24,12 @@ 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;
|
PDFJS.maxImageSize = 1024 * 1024;
|
||||||
PDFJS.workerSrc = '../../node_modules/pdfjs-dist/build/pdf.worker.js';
|
|
||||||
PDFJS.cMapUrl = '../../node_modules/pdfjs-dist/cmaps/';
|
PDFJS.cMapUrl = '../../node_modules/pdfjs-dist/cmaps/';
|
||||||
PDFJS.cMapPacked = true;
|
PDFJS.cMapPacked = true;
|
||||||
|
|
||||||
|
PDFJS.GlobalWorkerOptions.workerSrc =
|
||||||
|
'../../node_modules/pdfjs-dist/build/pdf.worker.js';
|
||||||
|
|
||||||
var DEFAULT_URL = '../../web/compressed.tracemonkey-pldi-09.pdf';
|
var DEFAULT_URL = '../../web/compressed.tracemonkey-pldi-09.pdf';
|
||||||
var DEFAULT_SCALE_DELTA = 1.1;
|
var DEFAULT_SCALE_DELTA = 1.1;
|
||||||
var MIN_SCALE = 0.25;
|
var MIN_SCALE = 0.25;
|
||||||
|
@ -39,16 +39,21 @@ function renderDocument(pdf, svgLib) {
|
|||||||
Promise.all([System.import('pdfjs/display/api'),
|
Promise.all([System.import('pdfjs/display/api'),
|
||||||
System.import('pdfjs/display/svg'),
|
System.import('pdfjs/display/svg'),
|
||||||
System.import('pdfjs/display/global'),
|
System.import('pdfjs/display/global'),
|
||||||
|
System.import('pdfjs/display/worker_options'),
|
||||||
System.import('pdfjs/display/network'),
|
System.import('pdfjs/display/network'),
|
||||||
System.resolve('pdfjs/worker_loader')])
|
System.resolve('pdfjs/worker_loader')])
|
||||||
.then(function (modules) {
|
.then(function (modules) {
|
||||||
var api = modules[0], svg = modules[1], global = modules[2], network = modules[3];
|
var api = modules[0];
|
||||||
|
var svg = modules[1];
|
||||||
|
var global = modules[2];
|
||||||
|
var GlobalWorkerOptions = modules[3].GlobalWorkerOptions;
|
||||||
|
var network = modules[4];
|
||||||
api.setPDFNetworkStreamFactory((params) => {
|
api.setPDFNetworkStreamFactory((params) => {
|
||||||
return new network.PDFNetworkStream(params);
|
return new network.PDFNetworkStream(params);
|
||||||
});
|
});
|
||||||
|
|
||||||
// In production, change this to point to the built `pdf.worker.js` file.
|
// In production, change this to point to the built `pdf.worker.js` file.
|
||||||
global.PDFJS.workerSrc = modules[4];
|
GlobalWorkerOptions.workerSrc = modules[5];
|
||||||
|
|
||||||
// In production, change this to point to where the cMaps are placed.
|
// In production, change this to point to where the cMaps are placed.
|
||||||
global.PDFJS.cMapUrl = '../../external/bcmaps/';
|
global.PDFJS.cMapUrl = '../../external/bcmaps/';
|
||||||
|
@ -18,7 +18,8 @@ var PAGE_NUMBER = 1;
|
|||||||
var PAGE_SCALE = 1.5;
|
var PAGE_SCALE = 1.5;
|
||||||
var SVG_NS = 'http://www.w3.org/2000/svg';
|
var SVG_NS = 'http://www.w3.org/2000/svg';
|
||||||
|
|
||||||
PDFJS.workerSrc = '../../node_modules/pdfjs-dist/build/pdf.worker.js';
|
PDFJS.GlobalWorkerOptions.workerSrc =
|
||||||
|
'../../node_modules/pdfjs-dist/build/pdf.worker.js';
|
||||||
|
|
||||||
function buildSVG(viewport, textContent) {
|
function buildSVG(viewport, textContent) {
|
||||||
// Building SVG with size of the viewport (for simplicity)
|
// Building SVG with size of the viewport (for simplicity)
|
||||||
|
@ -8,7 +8,8 @@ var pdfjsLib = require('pdfjs-dist');
|
|||||||
var pdfPath = '../helloworld/helloworld.pdf';
|
var pdfPath = '../helloworld/helloworld.pdf';
|
||||||
|
|
||||||
// Setting worker path to worker bundle.
|
// Setting worker path to worker bundle.
|
||||||
pdfjsLib.PDFJS.workerSrc = '../../build/webpack/pdf.worker.bundle.js';
|
pdfjsLib.GlobalWorkerOptions.workerSrc =
|
||||||
|
'../../build/webpack/pdf.worker.bundle.js';
|
||||||
|
|
||||||
// Loading a document.
|
// Loading a document.
|
||||||
var loadingTask = pdfjsLib.getDocument(pdfPath);
|
var loadingTask = pdfjsLib.getDocument(pdfPath);
|
||||||
|
2
external/dist/webpack.js
vendored
2
external/dist/webpack.js
vendored
@ -18,7 +18,7 @@ var pdfjs = require('./build/pdf.js');
|
|||||||
var PdfjsWorker = require('worker-loader!./build/pdf.worker.js');
|
var PdfjsWorker = require('worker-loader!./build/pdf.worker.js');
|
||||||
|
|
||||||
if (typeof window !== 'undefined' && 'Worker' in window) {
|
if (typeof window !== 'undefined' && 'Worker' in window) {
|
||||||
pdfjs.PDFJS.workerPort = new PdfjsWorker();
|
pdfjs.GlobalWorkerOptions.workerPort = new PdfjsWorker();
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = pdfjs;
|
module.exports = pdfjs;
|
||||||
|
@ -16,9 +16,10 @@
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
assert, createPromiseCapability, getVerbosityLevel, info, InvalidPDFException,
|
assert, createPromiseCapability, getVerbosityLevel, info, InvalidPDFException,
|
||||||
isArrayBuffer, isSameOrigin, MessageHandler, MissingPDFException,
|
isArrayBuffer, isNum, isSameOrigin, MessageHandler, MissingPDFException,
|
||||||
NativeImageDecoding, PageViewport, PasswordException, stringToBytes,
|
NativeImageDecoding, PageViewport, PasswordException, setVerbosityLevel,
|
||||||
UnexpectedResponseException, UnknownErrorException, unreachable, Util, warn
|
stringToBytes, UnexpectedResponseException, UnknownErrorException,
|
||||||
|
unreachable, Util, warn
|
||||||
} from '../shared/util';
|
} from '../shared/util';
|
||||||
import {
|
import {
|
||||||
DOMCanvasFactory, DOMCMapReaderFactory, DummyStatTimer, getDefaultSetting,
|
DOMCanvasFactory, DOMCMapReaderFactory, DummyStatTimer, getDefaultSetting,
|
||||||
@ -27,17 +28,17 @@ import {
|
|||||||
import { FontFaceObject, FontLoader } from './font_loader';
|
import { FontFaceObject, FontLoader } from './font_loader';
|
||||||
import { CanvasGraphics } from './canvas';
|
import { CanvasGraphics } from './canvas';
|
||||||
import globalScope from '../shared/global_scope';
|
import globalScope from '../shared/global_scope';
|
||||||
|
import { GlobalWorkerOptions } from './worker_options';
|
||||||
import { Metadata } from './metadata';
|
import { Metadata } from './metadata';
|
||||||
import { PDFDataTransportStream } from './transport_stream';
|
import { PDFDataTransportStream } from './transport_stream';
|
||||||
import { WebGLContext } from './webgl';
|
import { WebGLContext } from './webgl';
|
||||||
|
|
||||||
var DEFAULT_RANGE_CHUNK_SIZE = 65536; // 2^16 = 65536
|
var DEFAULT_RANGE_CHUNK_SIZE = 65536; // 2^16 = 65536
|
||||||
|
|
||||||
var isWorkerDisabled = false;
|
let isWorkerDisabled = false;
|
||||||
var workerSrc;
|
let workerSrc;
|
||||||
var isPostMessageTransfersDisabled = false;
|
|
||||||
|
|
||||||
var pdfjsFilePath =
|
const pdfjsFilePath =
|
||||||
typeof PDFJSDev !== 'undefined' &&
|
typeof PDFJSDev !== 'undefined' &&
|
||||||
PDFJSDev.test('PRODUCTION && !(MOZCENTRAL || FIREFOX)') &&
|
PDFJSDev.test('PRODUCTION && !(MOZCENTRAL || FIREFOX)') &&
|
||||||
typeof document !== 'undefined' && document.currentScript ?
|
typeof document !== 'undefined' && document.currentScript ?
|
||||||
@ -46,8 +47,8 @@ var pdfjsFilePath =
|
|||||||
var fakeWorkerFilesLoader = null;
|
var fakeWorkerFilesLoader = null;
|
||||||
var useRequireEnsure = false;
|
var useRequireEnsure = false;
|
||||||
if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('GENERIC')) {
|
if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('GENERIC')) {
|
||||||
// For GENERIC build we need add support of different fake file loaders
|
// For GENERIC build we need to add support for different fake file loaders
|
||||||
// for different frameworks.
|
// for different frameworks.
|
||||||
if (typeof window === 'undefined') {
|
if (typeof window === 'undefined') {
|
||||||
// node.js - disable worker and set require.ensure.
|
// node.js - disable worker and set require.ensure.
|
||||||
isWorkerDisabled = true;
|
isWorkerDisabled = true;
|
||||||
@ -124,8 +125,12 @@ function setPDFNetworkStreamFactory(pdfNetworkStreamFactory) {
|
|||||||
* @property {number} rangeChunkSize - Optional parameter to specify
|
* @property {number} rangeChunkSize - Optional parameter to specify
|
||||||
* maximum number of bytes fetched per range request. The default value is
|
* maximum number of bytes fetched per range request. The default value is
|
||||||
* 2^16 = 65536.
|
* 2^16 = 65536.
|
||||||
* @property {PDFWorker} worker - The worker that will be used for the loading
|
* @property {PDFWorker} worker - (optional) The worker that will be used for
|
||||||
* and parsing of the PDF data.
|
* the loading and parsing of the PDF data.
|
||||||
|
* @property {boolean} postMessageTransfers - (optional) Enables transfer usage
|
||||||
|
* in postMessage for ArrayBuffers. The default value is `true`.
|
||||||
|
* @property {number} verbosity - (optional) Controls the logging level; the
|
||||||
|
* constants from {VerbosityLevel} should be used.
|
||||||
* @property {string} docBaseUrl - (optional) The base URL of the document,
|
* @property {string} docBaseUrl - (optional) The base URL of the document,
|
||||||
* used when attempting to recover valid absolute URLs for annotations, and
|
* used when attempting to recover valid absolute URLs for annotations, and
|
||||||
* outline items, that (incorrectly) only specify relative URLs.
|
* outline items, that (incorrectly) only specify relative URLs.
|
||||||
@ -192,7 +197,7 @@ function getDocument(src) {
|
|||||||
|
|
||||||
var params = {};
|
var params = {};
|
||||||
var rangeTransport = null;
|
var rangeTransport = null;
|
||||||
var worker = null;
|
let worker = null;
|
||||||
var CMapReaderFactory = DOMCMapReaderFactory;
|
var CMapReaderFactory = DOMCMapReaderFactory;
|
||||||
|
|
||||||
for (var key in source) {
|
for (var key in source) {
|
||||||
@ -238,11 +243,23 @@ function getDocument(src) {
|
|||||||
params.nativeImageDecoderSupport = NativeImageDecoding.DECODE;
|
params.nativeImageDecoderSupport = NativeImageDecoding.DECODE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set the main-thread verbosity level.
|
||||||
|
setVerbosityLevel(params.verbosity);
|
||||||
|
|
||||||
if (!worker) {
|
if (!worker) {
|
||||||
|
const workerParams = {
|
||||||
|
postMessageTransfers: params.postMessageTransfers,
|
||||||
|
verbosity: params.verbosity,
|
||||||
|
};
|
||||||
// Worker was not provided -- creating and owning our own. If message port
|
// Worker was not provided -- creating and owning our own. If message port
|
||||||
// is specified in global settings, using it.
|
// is specified in global worker options, using it.
|
||||||
var workerPort = getDefaultSetting('workerPort');
|
let workerPort = GlobalWorkerOptions.workerPort;
|
||||||
worker = workerPort ? PDFWorker.fromPort(workerPort) : new PDFWorker();
|
if (workerPort) {
|
||||||
|
workerParams.port = workerPort;
|
||||||
|
worker = PDFWorker.fromPort(workerParams);
|
||||||
|
} else {
|
||||||
|
worker = new PDFWorker(workerParams);
|
||||||
|
}
|
||||||
task._worker = worker;
|
task._worker = worker;
|
||||||
}
|
}
|
||||||
var docId = task.docId;
|
var docId = task.docId;
|
||||||
@ -313,8 +330,7 @@ function _fetchDocument(worker, source, pdfDataRangeTransport, docId) {
|
|||||||
maxImageSize: getDefaultSetting('maxImageSize'),
|
maxImageSize: getDefaultSetting('maxImageSize'),
|
||||||
disableFontFace: getDefaultSetting('disableFontFace'),
|
disableFontFace: getDefaultSetting('disableFontFace'),
|
||||||
disableCreateObjectURL: getDefaultSetting('disableCreateObjectURL'),
|
disableCreateObjectURL: getDefaultSetting('disableCreateObjectURL'),
|
||||||
postMessageTransfers: getDefaultSetting('postMessageTransfers') &&
|
postMessageTransfers: worker.postMessageTransfers,
|
||||||
!isPostMessageTransfersDisabled,
|
|
||||||
docBaseUrl: source.docBaseUrl,
|
docBaseUrl: source.docBaseUrl,
|
||||||
nativeImageDecoderSupport: source.nativeImageDecoderSupport,
|
nativeImageDecoderSupport: source.nativeImageDecoderSupport,
|
||||||
ignoreErrors: source.ignoreErrors,
|
ignoreErrors: source.ignoreErrors,
|
||||||
@ -1191,9 +1207,19 @@ class LoopbackPort {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {Object} PDFWorkerParameters
|
||||||
|
* @property {string} name - (optional) The name of the worker.
|
||||||
|
* @property {Object} port - (optional) The `workerPort`.
|
||||||
|
* @property {boolean} postMessageTransfers - (optional) Enables transfer usage
|
||||||
|
* in postMessage for ArrayBuffers. The default value is `true`.
|
||||||
|
* @property {number} verbosity - (optional) Controls the logging level; the
|
||||||
|
* constants from {VerbosityLevel} should be used.
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PDF.js web worker abstraction, it controls instantiation of PDF documents and
|
* PDF.js web worker abstraction, it controls instantiation of PDF documents and
|
||||||
* WorkerTransport for them. If creation of a web worker is not possible,
|
* WorkerTransport for them. If creation of a web worker is not possible,
|
||||||
* a "fake" worker will be used instead.
|
* a "fake" worker will be used instead.
|
||||||
* @class
|
* @class
|
||||||
*/
|
*/
|
||||||
@ -1201,8 +1227,8 @@ var PDFWorker = (function PDFWorkerClosure() {
|
|||||||
let nextFakeWorkerId = 0;
|
let nextFakeWorkerId = 0;
|
||||||
|
|
||||||
function getWorkerSrc() {
|
function getWorkerSrc() {
|
||||||
if (getDefaultSetting('workerSrc')) {
|
if (GlobalWorkerOptions.workerSrc) {
|
||||||
return getDefaultSetting('workerSrc');
|
return GlobalWorkerOptions.workerSrc;
|
||||||
}
|
}
|
||||||
if (typeof workerSrc !== 'undefined') {
|
if (typeof workerSrc !== 'undefined') {
|
||||||
return workerSrc;
|
return workerSrc;
|
||||||
@ -1212,7 +1238,7 @@ var PDFWorker = (function PDFWorkerClosure() {
|
|||||||
pdfjsFilePath) {
|
pdfjsFilePath) {
|
||||||
return pdfjsFilePath.replace(/(\.(?:min\.)?js)(\?.*)?$/i, '.worker$1$2');
|
return pdfjsFilePath.replace(/(\.(?:min\.)?js)(\?.*)?$/i, '.worker$1$2');
|
||||||
}
|
}
|
||||||
throw new Error('No PDFJS.workerSrc specified');
|
throw new Error('No "GlobalWorkerOptions.workerSrc" specified.');
|
||||||
}
|
}
|
||||||
|
|
||||||
function getMainThreadWorkerMessageHandler() {
|
function getMainThreadWorkerMessageHandler() {
|
||||||
@ -1279,14 +1305,19 @@ var PDFWorker = (function PDFWorkerClosure() {
|
|||||||
|
|
||||||
let pdfWorkerPorts = new WeakMap();
|
let pdfWorkerPorts = new WeakMap();
|
||||||
|
|
||||||
function PDFWorker(name, port) {
|
/**
|
||||||
|
* @param {PDFWorkerParameters} params - The worker initialization parameters.
|
||||||
|
*/
|
||||||
|
function PDFWorker({ name = null, port = null,
|
||||||
|
postMessageTransfers = true, verbosity = null, } = {}) {
|
||||||
if (port && pdfWorkerPorts.has(port)) {
|
if (port && pdfWorkerPorts.has(port)) {
|
||||||
throw new Error('Cannot use more than one PDFWorker per port');
|
throw new Error('Cannot use more than one PDFWorker per port');
|
||||||
}
|
}
|
||||||
|
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.destroyed = false;
|
this.destroyed = false;
|
||||||
this.postMessageTransfers = true;
|
this.postMessageTransfers = postMessageTransfers !== false;
|
||||||
|
this.verbosity = (isNum(verbosity) ? verbosity : getVerbosityLevel());
|
||||||
|
|
||||||
this._readyCapability = createPromiseCapability();
|
this._readyCapability = createPromiseCapability();
|
||||||
this._port = null;
|
this._port = null;
|
||||||
@ -1383,12 +1414,11 @@ var PDFWorker = (function PDFWorkerClosure() {
|
|||||||
this._webWorker = worker;
|
this._webWorker = worker;
|
||||||
if (!data.supportTransfers) {
|
if (!data.supportTransfers) {
|
||||||
this.postMessageTransfers = false;
|
this.postMessageTransfers = false;
|
||||||
isPostMessageTransfersDisabled = true;
|
|
||||||
}
|
}
|
||||||
this._readyCapability.resolve();
|
this._readyCapability.resolve();
|
||||||
// Send global setting, e.g. verbosity level.
|
// Send global setting, e.g. verbosity level.
|
||||||
messageHandler.send('configure', {
|
messageHandler.send('configure', {
|
||||||
verbosity: getVerbosityLevel(),
|
verbosity: this.verbosity,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
this._setupFakeWorker();
|
this._setupFakeWorker();
|
||||||
@ -1411,11 +1441,8 @@ var PDFWorker = (function PDFWorkerClosure() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var sendTest = function () {
|
const sendTest = () => {
|
||||||
var postMessageTransfers =
|
let testObj = new Uint8Array([this.postMessageTransfers ? 255 : 0]);
|
||||||
getDefaultSetting('postMessageTransfers') &&
|
|
||||||
!isPostMessageTransfersDisabled;
|
|
||||||
var testObj = new Uint8Array([postMessageTransfers ? 255 : 0]);
|
|
||||||
// Some versions of Opera throw a DATA_CLONE_ERR on serializing the
|
// Some versions of Opera throw a DATA_CLONE_ERR on serializing the
|
||||||
// typed array. Also, checking if we can use transfers.
|
// typed array. Also, checking if we can use transfers.
|
||||||
try {
|
try {
|
||||||
@ -1494,11 +1521,14 @@ var PDFWorker = (function PDFWorkerClosure() {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
PDFWorker.fromPort = function (port) {
|
/**
|
||||||
if (pdfWorkerPorts.has(port)) {
|
* @param {PDFWorkerParameters} params - The worker initialization parameters.
|
||||||
return pdfWorkerPorts.get(port);
|
*/
|
||||||
|
PDFWorker.fromPort = function(params) {
|
||||||
|
if (pdfWorkerPorts.has(params.port)) {
|
||||||
|
return pdfWorkerPorts.get(params.port);
|
||||||
}
|
}
|
||||||
return new PDFWorker(null, port);
|
return new PDFWorker(params);
|
||||||
};
|
};
|
||||||
|
|
||||||
PDFWorker.getWorkerSrc = function() {
|
PDFWorker.getWorkerSrc = function() {
|
||||||
|
@ -349,12 +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 'postMessageTransfers':
|
|
||||||
return globalSettings ? globalSettings.postMessageTransfers : true;
|
|
||||||
case 'workerPort':
|
|
||||||
return globalSettings ? globalSettings.workerPort : null;
|
|
||||||
case 'workerSrc':
|
|
||||||
return globalSettings ? globalSettings.workerSrc : null;
|
|
||||||
case 'maxImageSize':
|
case 'maxImageSize':
|
||||||
return globalSettings ? globalSettings.maxImageSize : -1;
|
return globalSettings ? globalSettings.maxImageSize : -1;
|
||||||
case 'isEvalSupported':
|
case 'isEvalSupported':
|
||||||
|
@ -14,11 +14,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import {
|
import {
|
||||||
createBlob, createObjectURL, createPromiseCapability, getVerbosityLevel,
|
createBlob, createObjectURL, createPromiseCapability, InvalidPDFException,
|
||||||
InvalidPDFException, isLittleEndian, MissingPDFException, OPS, PageViewport,
|
isLittleEndian, MissingPDFException, OPS, PageViewport, PasswordException,
|
||||||
PasswordException, PasswordResponses, removeNullCharacters, setVerbosityLevel,
|
PasswordResponses, removeNullCharacters, shadow, UnexpectedResponseException,
|
||||||
shadow, UnexpectedResponseException, UnknownErrorException,
|
UnknownErrorException, UNSUPPORTED_FEATURES, Util
|
||||||
UNSUPPORTED_FEATURES, Util, VERBOSITY_LEVELS
|
|
||||||
} from '../shared/util';
|
} from '../shared/util';
|
||||||
import { DEFAULT_LINK_REL, getFilenameFromUrl, LinkTarget } from './dom_utils';
|
import { DEFAULT_LINK_REL, getFilenameFromUrl, LinkTarget } from './dom_utils';
|
||||||
import {
|
import {
|
||||||
@ -26,6 +25,7 @@ import {
|
|||||||
} from './api';
|
} from './api';
|
||||||
import { AnnotationLayer } from './annotation_layer';
|
import { AnnotationLayer } from './annotation_layer';
|
||||||
import globalScope from '../shared/global_scope';
|
import globalScope from '../shared/global_scope';
|
||||||
|
import { GlobalWorkerOptions } from './worker_options';
|
||||||
import { Metadata } from './metadata';
|
import { Metadata } from './metadata';
|
||||||
import { renderTextLayer } from './text_layer';
|
import { renderTextLayer } from './text_layer';
|
||||||
import { SVGGraphics } from './svg';
|
import { SVGGraphics } from './svg';
|
||||||
@ -41,22 +41,6 @@ var PDFJS = globalScope.PDFJS;
|
|||||||
|
|
||||||
PDFJS.pdfBug = false;
|
PDFJS.pdfBug = false;
|
||||||
|
|
||||||
if (PDFJS.verbosity !== undefined) {
|
|
||||||
setVerbosityLevel(PDFJS.verbosity);
|
|
||||||
}
|
|
||||||
delete PDFJS.verbosity;
|
|
||||||
Object.defineProperty(PDFJS, 'verbosity', {
|
|
||||||
get() {
|
|
||||||
return getVerbosityLevel();
|
|
||||||
},
|
|
||||||
set(level) {
|
|
||||||
setVerbosityLevel(level);
|
|
||||||
},
|
|
||||||
enumerable: true,
|
|
||||||
configurable: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
PDFJS.VERBOSITY_LEVELS = VERBOSITY_LEVELS;
|
|
||||||
PDFJS.OPS = OPS;
|
PDFJS.OPS = OPS;
|
||||||
PDFJS.UNSUPPORTED_FEATURES = UNSUPPORTED_FEATURES;
|
PDFJS.UNSUPPORTED_FEATURES = UNSUPPORTED_FEATURES;
|
||||||
PDFJS.shadow = shadow;
|
PDFJS.shadow = shadow;
|
||||||
@ -111,21 +95,6 @@ PDFJS.cMapPacked = PDFJS.cMapPacked === undefined ? false : PDFJS.cMapPacked;
|
|||||||
PDFJS.disableFontFace = (PDFJS.disableFontFace === undefined ?
|
PDFJS.disableFontFace = (PDFJS.disableFontFace === undefined ?
|
||||||
false : PDFJS.disableFontFace);
|
false : PDFJS.disableFontFace);
|
||||||
|
|
||||||
/**
|
|
||||||
* Path and filename of the worker file. Required when the worker is enabled
|
|
||||||
* in development mode. If unspecified in the production build, the worker
|
|
||||||
* will be loaded based on the location of the pdf.js file. It is recommended
|
|
||||||
* that the workerSrc is set in a custom application to prevent issues caused
|
|
||||||
* by third-party frameworks and libraries.
|
|
||||||
* @var {string}
|
|
||||||
*/
|
|
||||||
PDFJS.workerSrc = (PDFJS.workerSrc === undefined ? null : PDFJS.workerSrc);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Defines global port for worker process. Overrides `workerSrc` setting.
|
|
||||||
*/
|
|
||||||
PDFJS.workerPort = (PDFJS.workerPort === undefined ? null : PDFJS.workerPort);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Disable range request loading of PDF files. When enabled and if the server
|
* Disable range request loading of PDF files. When enabled and if the server
|
||||||
* supports partial content requests then the PDF will be fetched in chunks.
|
* supports partial content requests then the PDF will be fetched in chunks.
|
||||||
@ -161,13 +130,6 @@ PDFJS.disableAutoFetch = (PDFJS.disableAutoFetch === undefined ?
|
|||||||
*/
|
*/
|
||||||
PDFJS.pdfBug = (PDFJS.pdfBug === undefined ? false : PDFJS.pdfBug);
|
PDFJS.pdfBug = (PDFJS.pdfBug === undefined ? false : PDFJS.pdfBug);
|
||||||
|
|
||||||
/**
|
|
||||||
* Enables transfer usage in postMessage for ArrayBuffers.
|
|
||||||
* @var {boolean}
|
|
||||||
*/
|
|
||||||
PDFJS.postMessageTransfers = (PDFJS.postMessageTransfers === undefined ?
|
|
||||||
true : PDFJS.postMessageTransfers);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Disables URL.createObjectURL usage.
|
* Disables URL.createObjectURL usage.
|
||||||
* @var {boolean}
|
* @var {boolean}
|
||||||
@ -208,6 +170,7 @@ PDFJS.getDocument = getDocument;
|
|||||||
PDFJS.LoopbackPort = LoopbackPort;
|
PDFJS.LoopbackPort = LoopbackPort;
|
||||||
PDFJS.PDFDataRangeTransport = PDFDataRangeTransport;
|
PDFJS.PDFDataRangeTransport = PDFDataRangeTransport;
|
||||||
PDFJS.PDFWorker = PDFWorker;
|
PDFJS.PDFWorker = PDFWorker;
|
||||||
|
PDFJS.GlobalWorkerOptions = GlobalWorkerOptions;
|
||||||
|
|
||||||
PDFJS.getFilenameFromUrl = getFilenameFromUrl;
|
PDFJS.getFilenameFromUrl = getFilenameFromUrl;
|
||||||
|
|
||||||
|
39
src/display/worker_options.js
Normal file
39
src/display/worker_options.js
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
/* Copyright 2018 Mozilla Foundation
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
const GlobalWorkerOptions = Object.create(null);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines global port for worker process. Overrides the `workerSrc` option.
|
||||||
|
* @var {Object}
|
||||||
|
*/
|
||||||
|
GlobalWorkerOptions.workerPort = (GlobalWorkerOptions.workerPort === undefined ?
|
||||||
|
null : GlobalWorkerOptions.workerPort);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Path and filename of the worker file. Required when workers are enabled in
|
||||||
|
* development mode. If unspecified in production builds, the worker will be
|
||||||
|
* loaded based on the location of the `pdf.js` file.
|
||||||
|
*
|
||||||
|
* NOTE: The `workerSrc` should always be set in custom applications, in order
|
||||||
|
* to prevent issues caused by third-party frameworks and libraries.
|
||||||
|
* @var {string}
|
||||||
|
*/
|
||||||
|
GlobalWorkerOptions.workerSrc = (GlobalWorkerOptions.workerSrc === undefined ?
|
||||||
|
'' : GlobalWorkerOptions.workerSrc);
|
||||||
|
|
||||||
|
export {
|
||||||
|
GlobalWorkerOptions,
|
||||||
|
};
|
@ -23,20 +23,10 @@
|
|||||||
* to the PDF.js.
|
* to the PDF.js.
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
function PDFJS() {
|
function PDFJS() { // eslint-disable-line no-unused-vars
|
||||||
// Mock class constructor. See src/display/api.js.
|
// Mock class constructor. See src/display/api.js.
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Controls the logging level.
|
|
||||||
* The constants from PDFJS.VERBOSITY_LEVELS should be used:
|
|
||||||
* - errors
|
|
||||||
* - warnings [default]
|
|
||||||
* - infos
|
|
||||||
* @var {number}
|
|
||||||
*/
|
|
||||||
PDFJS.verbosity = PDFJS.VERBOSITY_LEVELS.warnings;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the eventual result of an asynchronous operation.
|
* Represents the eventual result of an asynchronous operation.
|
||||||
* @external Promise
|
* @external Promise
|
||||||
|
@ -28,6 +28,7 @@ var pdfjsDisplayTextLayer = require('./display/text_layer.js');
|
|||||||
var pdfjsDisplayAnnotationLayer = require('./display/annotation_layer.js');
|
var pdfjsDisplayAnnotationLayer = require('./display/annotation_layer.js');
|
||||||
var pdfjsDisplayDOMUtils = require('./display/dom_utils.js');
|
var pdfjsDisplayDOMUtils = require('./display/dom_utils.js');
|
||||||
var pdfjsDisplaySVG = require('./display/svg.js');
|
var pdfjsDisplaySVG = require('./display/svg.js');
|
||||||
|
let pdfjsDisplayWorkerOptions = require('./display/worker_options.js');
|
||||||
|
|
||||||
if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) {
|
if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) {
|
||||||
const isNodeJS = require('./shared/is_node.js');
|
const isNodeJS = require('./shared/is_node.js');
|
||||||
@ -82,6 +83,7 @@ exports.NativeImageDecoding = pdfjsSharedUtil.NativeImageDecoding;
|
|||||||
exports.UnexpectedResponseException =
|
exports.UnexpectedResponseException =
|
||||||
pdfjsSharedUtil.UnexpectedResponseException;
|
pdfjsSharedUtil.UnexpectedResponseException;
|
||||||
exports.OPS = pdfjsSharedUtil.OPS;
|
exports.OPS = pdfjsSharedUtil.OPS;
|
||||||
|
exports.VerbosityLevel = pdfjsSharedUtil.VerbosityLevel;
|
||||||
exports.UNSUPPORTED_FEATURES = pdfjsSharedUtil.UNSUPPORTED_FEATURES;
|
exports.UNSUPPORTED_FEATURES = pdfjsSharedUtil.UNSUPPORTED_FEATURES;
|
||||||
exports.createValidAbsoluteUrl = pdfjsSharedUtil.createValidAbsoluteUrl;
|
exports.createValidAbsoluteUrl = pdfjsSharedUtil.createValidAbsoluteUrl;
|
||||||
exports.createObjectURL = pdfjsSharedUtil.createObjectURL;
|
exports.createObjectURL = pdfjsSharedUtil.createObjectURL;
|
||||||
@ -93,3 +95,4 @@ exports.RenderingCancelledException =
|
|||||||
exports.getFilenameFromUrl = pdfjsDisplayDOMUtils.getFilenameFromUrl;
|
exports.getFilenameFromUrl = pdfjsDisplayDOMUtils.getFilenameFromUrl;
|
||||||
exports.LinkTarget = pdfjsDisplayDOMUtils.LinkTarget;
|
exports.LinkTarget = pdfjsDisplayDOMUtils.LinkTarget;
|
||||||
exports.addLinkAttributes = pdfjsDisplayDOMUtils.addLinkAttributes;
|
exports.addLinkAttributes = pdfjsDisplayDOMUtils.addLinkAttributes;
|
||||||
|
exports.GlobalWorkerOptions = pdfjsDisplayWorkerOptions.GlobalWorkerOptions;
|
||||||
|
@ -142,10 +142,10 @@ var FontType = {
|
|||||||
MMTYPE1: 10,
|
MMTYPE1: 10,
|
||||||
};
|
};
|
||||||
|
|
||||||
var VERBOSITY_LEVELS = {
|
const VerbosityLevel = {
|
||||||
errors: 0,
|
ERRORS: 0,
|
||||||
warnings: 1,
|
WARNINGS: 1,
|
||||||
infos: 5,
|
INFOS: 5,
|
||||||
};
|
};
|
||||||
|
|
||||||
var CMapCompressionType = {
|
var CMapCompressionType = {
|
||||||
@ -251,10 +251,12 @@ var OPS = {
|
|||||||
constructPath: 91,
|
constructPath: 91,
|
||||||
};
|
};
|
||||||
|
|
||||||
var verbosity = VERBOSITY_LEVELS.warnings;
|
let verbosity = VerbosityLevel.WARNINGS;
|
||||||
|
|
||||||
function setVerbosityLevel(level) {
|
function setVerbosityLevel(level) {
|
||||||
verbosity = level;
|
if (Number.isInteger(level)) {
|
||||||
|
verbosity = level;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getVerbosityLevel() {
|
function getVerbosityLevel() {
|
||||||
@ -265,19 +267,19 @@ function getVerbosityLevel() {
|
|||||||
// as warning that Workers were disabled, which is important to devs but not
|
// as warning that Workers were disabled, which is important to devs but not
|
||||||
// end users.
|
// end users.
|
||||||
function info(msg) {
|
function info(msg) {
|
||||||
if (verbosity >= VERBOSITY_LEVELS.infos) {
|
if (verbosity >= VerbosityLevel.INFOS) {
|
||||||
console.log('Info: ' + msg);
|
console.log('Info: ' + msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Non-fatal warnings.
|
// Non-fatal warnings.
|
||||||
function warn(msg) {
|
function warn(msg) {
|
||||||
if (verbosity >= VERBOSITY_LEVELS.warnings) {
|
if (verbosity >= VerbosityLevel.WARNINGS) {
|
||||||
console.log('Warning: ' + msg);
|
console.log('Warning: ' + msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated API function -- display regardless of the PDFJS.verbosity setting.
|
// Deprecated API function -- display regardless of the `verbosity` setting.
|
||||||
function deprecated(details) {
|
function deprecated(details) {
|
||||||
console.log('Deprecated API usage: ' + details);
|
console.log('Deprecated API usage: ' + details);
|
||||||
}
|
}
|
||||||
@ -1573,7 +1575,7 @@ export {
|
|||||||
FONT_IDENTITY_MATRIX,
|
FONT_IDENTITY_MATRIX,
|
||||||
IDENTITY_MATRIX,
|
IDENTITY_MATRIX,
|
||||||
OPS,
|
OPS,
|
||||||
VERBOSITY_LEVELS,
|
VerbosityLevel,
|
||||||
UNSUPPORTED_FEATURES,
|
UNSUPPORTED_FEATURES,
|
||||||
AnnotationBorderStyleType,
|
AnnotationBorderStyleType,
|
||||||
AnnotationFieldFlag,
|
AnnotationFieldFlag,
|
||||||
|
@ -16,9 +16,10 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var WAITING_TIME = 100; // ms
|
const WAITING_TIME = 100; // ms
|
||||||
var PDF_TO_CSS_UNITS = 96.0 / 72.0;
|
const PDF_TO_CSS_UNITS = 96.0 / 72.0;
|
||||||
const IMAGE_RESOURCES_PATH = '/web/images/';
|
const IMAGE_RESOURCES_PATH = '/web/images/';
|
||||||
|
const WORKER_SRC = '../build/generic/build/pdf.worker.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @class
|
* @class
|
||||||
@ -267,8 +268,9 @@ var Driver = (function DriverClosure() { // eslint-disable-line no-unused-vars
|
|||||||
* @param {DriverOptions} options
|
* @param {DriverOptions} options
|
||||||
*/
|
*/
|
||||||
function Driver(options) {
|
function Driver(options) {
|
||||||
// Configure the global PDFJS object
|
// Configure the global worker options.
|
||||||
PDFJS.workerSrc = '../build/generic/build/pdf.worker.js';
|
PDFJS.GlobalWorkerOptions.workerSrc = WORKER_SRC;
|
||||||
|
|
||||||
PDFJS.cMapPacked = true;
|
PDFJS.cMapPacked = true;
|
||||||
PDFJS.cMapUrl = '../external/bcmaps/';
|
PDFJS.cMapUrl = '../external/bcmaps/';
|
||||||
PDFJS.pdfBug = true;
|
PDFJS.pdfBug = true;
|
||||||
|
@ -24,10 +24,10 @@ import {
|
|||||||
DOMCanvasFactory, RenderingCancelledException
|
DOMCanvasFactory, RenderingCancelledException
|
||||||
} from '../../src/display/dom_utils';
|
} from '../../src/display/dom_utils';
|
||||||
import {
|
import {
|
||||||
getDocument, PDFDocumentProxy, PDFPageProxy, PDFWorker
|
getDocument, PDFDataRangeTransport, PDFDocumentProxy, PDFPageProxy, PDFWorker
|
||||||
} from '../../src/display/api';
|
} from '../../src/display/api';
|
||||||
|
import { GlobalWorkerOptions } from '../../src/display/worker_options';
|
||||||
import isNodeJS from '../../src/shared/is_node';
|
import isNodeJS from '../../src/shared/is_node';
|
||||||
import { PDFJS } from '../../src/display/global';
|
|
||||||
|
|
||||||
describe('api', function() {
|
describe('api', function() {
|
||||||
let basicApiFileName = 'basicapi.pdf';
|
let basicApiFileName = 'basicapi.pdf';
|
||||||
@ -324,7 +324,7 @@ describe('api', function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
it('worker created or destroyed', function (done) {
|
it('worker created or destroyed', function (done) {
|
||||||
var worker = new PDFJS.PDFWorker('test1');
|
var worker = new PDFWorker({ name: 'test1', });
|
||||||
worker.promise.then(function () {
|
worker.promise.then(function () {
|
||||||
expect(worker.name).toEqual('test1');
|
expect(worker.name).toEqual('test1');
|
||||||
expect(!!worker.port).toEqual(true);
|
expect(!!worker.port).toEqual(true);
|
||||||
@ -361,7 +361,7 @@ describe('api', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('worker created and can be used in getDocument', function (done) {
|
it('worker created and can be used in getDocument', function (done) {
|
||||||
var worker = new PDFJS.PDFWorker('test1');
|
var worker = new PDFWorker({ name: 'test1', });
|
||||||
var loadingTask = getDocument(
|
var loadingTask = getDocument(
|
||||||
buildGetDocumentParams(basicApiFileName, {
|
buildGetDocumentParams(basicApiFileName, {
|
||||||
worker,
|
worker,
|
||||||
@ -386,9 +386,9 @@ describe('api', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('creates more than one worker', function (done) {
|
it('creates more than one worker', function (done) {
|
||||||
var worker1 = new PDFJS.PDFWorker('test1');
|
var worker1 = new PDFWorker({ name: 'test1', });
|
||||||
var worker2 = new PDFJS.PDFWorker('test2');
|
var worker2 = new PDFWorker({ name: 'test2', });
|
||||||
var worker3 = new PDFJS.PDFWorker('test3');
|
var worker3 = new PDFWorker({ name: 'test3', });
|
||||||
var ready = Promise.all([worker1.promise, worker2.promise,
|
var ready = Promise.all([worker1.promise, worker2.promise,
|
||||||
worker3.promise]);
|
worker3.promise]);
|
||||||
ready.then(function () {
|
ready.then(function () {
|
||||||
@ -406,7 +406,7 @@ describe('api', function() {
|
|||||||
it('gets current workerSrc', function() {
|
it('gets current workerSrc', function() {
|
||||||
let workerSrc = PDFWorker.getWorkerSrc();
|
let workerSrc = PDFWorker.getWorkerSrc();
|
||||||
expect(typeof workerSrc).toEqual('string');
|
expect(typeof workerSrc).toEqual('string');
|
||||||
expect(workerSrc).toEqual(PDFJS.workerSrc);
|
expect(workerSrc).toEqual(GlobalWorkerOptions.workerSrc);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('PDFDocument', function() {
|
describe('PDFDocument', function() {
|
||||||
@ -1305,7 +1305,7 @@ describe('api', function() {
|
|||||||
var fetches = 0;
|
var fetches = 0;
|
||||||
var getDocumentPromise = getDocumentData().then(function (data) {
|
var getDocumentPromise = getDocumentData().then(function (data) {
|
||||||
var initialData = data.subarray(0, initialDataLength);
|
var initialData = data.subarray(0, initialDataLength);
|
||||||
transport = new PDFJS.PDFDataRangeTransport(data.length, initialData);
|
transport = new PDFDataRangeTransport(data.length, initialData);
|
||||||
transport.requestDataRange = function (begin, end) {
|
transport.requestDataRange = function (begin, end) {
|
||||||
fetches++;
|
fetches++;
|
||||||
waitSome(function () {
|
waitSome(function () {
|
||||||
@ -1339,7 +1339,7 @@ describe('api', function() {
|
|||||||
var fetches = 0;
|
var fetches = 0;
|
||||||
var getDocumentPromise = getDocumentData().then(function (data) {
|
var getDocumentPromise = getDocumentData().then(function (data) {
|
||||||
var initialData = data.subarray(0, initialDataLength);
|
var initialData = data.subarray(0, initialDataLength);
|
||||||
transport = new PDFJS.PDFDataRangeTransport(data.length, initialData);
|
transport = new PDFDataRangeTransport(data.length, initialData);
|
||||||
transport.requestDataRange = function (begin, end) {
|
transport.requestDataRange = function (begin, end) {
|
||||||
fetches++;
|
fetches++;
|
||||||
if (fetches === 1) {
|
if (fetches === 1) {
|
||||||
|
@ -42,8 +42,8 @@
|
|||||||
|
|
||||||
function initializePDFJS(callback) {
|
function initializePDFJS(callback) {
|
||||||
Promise.all([
|
Promise.all([
|
||||||
'pdfjs/display/global',
|
|
||||||
'pdfjs/display/api',
|
'pdfjs/display/api',
|
||||||
|
'pdfjs/display/worker_options',
|
||||||
'pdfjs/display/network',
|
'pdfjs/display/network',
|
||||||
'pdfjs/display/fetch_stream',
|
'pdfjs/display/fetch_stream',
|
||||||
'pdfjs/shared/is_node',
|
'pdfjs/shared/is_node',
|
||||||
@ -77,9 +77,9 @@ function initializePDFJS(callback) {
|
|||||||
'pdfjs-test/unit/util_stream_spec',
|
'pdfjs-test/unit/util_stream_spec',
|
||||||
].map(function (moduleName) {
|
].map(function (moduleName) {
|
||||||
return SystemJS.import(moduleName);
|
return SystemJS.import(moduleName);
|
||||||
})).then(function (modules) {
|
})).then(function(modules) {
|
||||||
var displayGlobal = modules[0];
|
var displayApi = modules[0];
|
||||||
var displayApi = modules[1];
|
const GlobalWorkerOptions = modules[1].GlobalWorkerOptions;
|
||||||
var PDFNetworkStream = modules[2].PDFNetworkStream;
|
var PDFNetworkStream = modules[2].PDFNetworkStream;
|
||||||
var PDFFetchStream = modules[3].PDFFetchStream;
|
var PDFFetchStream = modules[3].PDFFetchStream;
|
||||||
const isNodeJS = modules[4];
|
const isNodeJS = modules[4];
|
||||||
@ -101,7 +101,7 @@ function initializePDFJS(callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Configure the worker.
|
// Configure the worker.
|
||||||
displayGlobal.PDFJS.workerSrc = '../../build/generic/build/pdf.worker.js';
|
GlobalWorkerOptions.workerSrc = '../../build/generic/build/pdf.worker.js';
|
||||||
|
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
|
12
web/app.js
12
web/app.js
@ -21,9 +21,9 @@ import {
|
|||||||
ProgressBar, RendererType, TextLayerMode
|
ProgressBar, RendererType, TextLayerMode
|
||||||
} from './ui_utils';
|
} from './ui_utils';
|
||||||
import {
|
import {
|
||||||
build, createBlob, getDocument, getFilenameFromUrl, InvalidPDFException,
|
build, createBlob, getDocument, getFilenameFromUrl, GlobalWorkerOptions,
|
||||||
LinkTarget, MissingPDFException, OPS, PDFJS, PDFWorker, shadow,
|
InvalidPDFException, LinkTarget, MissingPDFException, OPS, PDFJS, PDFWorker,
|
||||||
UnexpectedResponseException, UNSUPPORTED_FEATURES, version
|
shadow, UnexpectedResponseException, UNSUPPORTED_FEATURES, version
|
||||||
} from 'pdfjs-lib';
|
} from 'pdfjs-lib';
|
||||||
import { CursorTool, PDFCursorTools } from './pdf_cursor_tools';
|
import { CursorTool, PDFCursorTools } from './pdf_cursor_tools';
|
||||||
import { PDFRenderingQueue, RenderingStates } from './pdf_rendering_queue';
|
import { PDFRenderingQueue, RenderingStates } from './pdf_rendering_queue';
|
||||||
@ -54,11 +54,11 @@ function configure(PDFJS) {
|
|||||||
PDFJS.imageResourcesPath = './images/';
|
PDFJS.imageResourcesPath = './images/';
|
||||||
if (typeof PDFJSDev !== 'undefined' &&
|
if (typeof PDFJSDev !== 'undefined' &&
|
||||||
PDFJSDev.test('FIREFOX || MOZCENTRAL || GENERIC || CHROME')) {
|
PDFJSDev.test('FIREFOX || MOZCENTRAL || GENERIC || CHROME')) {
|
||||||
PDFJS.workerSrc = '../build/pdf.worker.js';
|
GlobalWorkerOptions.workerSrc = '../build/pdf.worker.js';
|
||||||
}
|
}
|
||||||
if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('PRODUCTION')) {
|
if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('PRODUCTION')) {
|
||||||
PDFJS.cMapUrl = '../external/bcmaps/';
|
PDFJS.cMapUrl = '../external/bcmaps/';
|
||||||
PDFJS.workerSrc = '../src/worker_loader.js';
|
GlobalWorkerOptions.workerSrc = '../src/worker_loader.js';
|
||||||
} else {
|
} else {
|
||||||
PDFJS.cMapUrl = '../web/cmaps/';
|
PDFJS.cMapUrl = '../web/cmaps/';
|
||||||
}
|
}
|
||||||
@ -740,6 +740,8 @@ let PDFViewerApplication = {
|
|||||||
PDFJSDev.test('FIREFOX || MOZCENTRAL || CHROME')) {
|
PDFJSDev.test('FIREFOX || MOZCENTRAL || CHROME')) {
|
||||||
parameters.docBaseUrl = this.baseUrl;
|
parameters.docBaseUrl = this.baseUrl;
|
||||||
}
|
}
|
||||||
|
// TODO: Remove this once all options are moved from the `PDFJS` object.
|
||||||
|
parameters.verbosity = PDFJS.verbosity;
|
||||||
|
|
||||||
if (args) {
|
if (args) {
|
||||||
for (let prop in args) {
|
for (let prop in args) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user