|
@@ -22,8 +22,8 @@ if (typeof PDFJS === 'undefined') {
|
|
|
(typeof window !== 'undefined' ? window : this).PDFJS = {};
|
|
|
}
|
|
|
|
|
|
-PDFJS.version = '1.0.1063';
|
|
|
-PDFJS.build = '5332c02';
|
|
|
+PDFJS.version = '1.0.1065';
|
|
|
+PDFJS.build = '6ceb652';
|
|
|
|
|
|
(function pdfjsWrapper() {
|
|
|
// Use strict in our context only - users might not want it
|
|
@@ -1761,6 +1761,9 @@ PDFJS.maxCanvasPixels = (PDFJS.maxCanvasPixels === undefined ?
|
|
|
* @property {TypedArray} initialData - A typed array with the first portion or
|
|
|
* all of the pdf data. Used by the extension since some data is already
|
|
|
* loaded before the switch to range requests.
|
|
|
+ * @property {number} length - The PDF file length. It's used for progress
|
|
|
+ * reports and range requests operations.
|
|
|
+ * @property {PDFDataRangeTransport} range
|
|
|
*/
|
|
|
|
|
|
/**
|
|
@@ -1777,44 +1780,63 @@ PDFJS.maxCanvasPixels = (PDFJS.maxCanvasPixels === undefined ?
|
|
|
* is used, which means it must follow the same origin rules that any XHR does
|
|
|
* e.g. No cross domain requests without CORS.
|
|
|
*
|
|
|
- * @param {string|TypedArray|DocumentInitParameters} source Can be a url to
|
|
|
- * where a PDF is located, a typed array (Uint8Array) already populated with
|
|
|
- * data or parameter object.
|
|
|
+ * @param {string|TypedArray|DocumentInitParameters|PDFDataRangeTransport} src
|
|
|
+ * Can be a url to where a PDF is located, a typed array (Uint8Array)
|
|
|
+ * already populated with data or parameter object.
|
|
|
*
|
|
|
- * @param {Object} pdfDataRangeTransport is optional. It is used if you want
|
|
|
- * to manually serve range requests for data in the PDF. See viewer.js for
|
|
|
- * an example of pdfDataRangeTransport's interface.
|
|
|
+ * @param {PDFDataRangeTransport} pdfDataRangeTransport (deprecated) It is used
|
|
|
+ * if you want to manually serve range requests for data in the PDF.
|
|
|
*
|
|
|
- * @param {function} passwordCallback is optional. It is used to request a
|
|
|
+ * @param {function} passwordCallback (deprecated) It is used to request a
|
|
|
* password if wrong or no password was provided. The callback receives two
|
|
|
* parameters: function that needs to be called with new password and reason
|
|
|
* (see {PasswordResponses}).
|
|
|
*
|
|
|
- * @param {function} progressCallback is optional. It is used to be able to
|
|
|
+ * @param {function} progressCallback (deprecated) It is used to be able to
|
|
|
* monitor the loading progress of the PDF file (necessary to implement e.g.
|
|
|
* a loading bar). The callback receives an {Object} with the properties:
|
|
|
* {number} loaded and {number} total.
|
|
|
*
|
|
|
- * @return {Promise} A promise that is resolved with {@link PDFDocumentProxy}
|
|
|
- * object.
|
|
|
+ * @return {PDFDocumentLoadingTask}
|
|
|
*/
|
|
|
-PDFJS.getDocument = function getDocument(source,
|
|
|
+PDFJS.getDocument = function getDocument(src,
|
|
|
pdfDataRangeTransport,
|
|
|
passwordCallback,
|
|
|
progressCallback) {
|
|
|
- var workerInitializedCapability, workerReadyCapability, transport;
|
|
|
-
|
|
|
- if (typeof source === 'string') {
|
|
|
- source = { url: source };
|
|
|
- } else if (isArrayBuffer(source)) {
|
|
|
- source = { data: source };
|
|
|
- } else if (typeof source !== 'object') {
|
|
|
- error('Invalid parameter in getDocument, need either Uint8Array, ' +
|
|
|
- 'string or a parameter object');
|
|
|
- }
|
|
|
+ var task = new PDFDocumentLoadingTask();
|
|
|
+
|
|
|
+ // Support of the obsolete arguments (for compatibility with API v1.0)
|
|
|
+ if (pdfDataRangeTransport) {
|
|
|
+ if (!(pdfDataRangeTransport instanceof PDFDataRangeTransport)) {
|
|
|
+ // Not a PDFDataRangeTransport instance, trying to add missing properties.
|
|
|
+ pdfDataRangeTransport = Object.create(pdfDataRangeTransport);
|
|
|
+ pdfDataRangeTransport.length = src.length;
|
|
|
+ pdfDataRangeTransport.initialData = src.initialData;
|
|
|
+ }
|
|
|
+ src = Object.create(src);
|
|
|
+ src.range = pdfDataRangeTransport;
|
|
|
+ }
|
|
|
+ task.onPassword = passwordCallback || null;
|
|
|
+ task.onProgress = progressCallback || null;
|
|
|
+
|
|
|
+ var workerInitializedCapability, transport;
|
|
|
+ var source;
|
|
|
+ if (typeof src === 'string') {
|
|
|
+ source = { url: src };
|
|
|
+ } else if (isArrayBuffer(src)) {
|
|
|
+ source = { data: src };
|
|
|
+ } else if (src instanceof PDFDataRangeTransport) {
|
|
|
+ source = { range: src };
|
|
|
+ } else {
|
|
|
+ if (typeof src !== 'object') {
|
|
|
+ error('Invalid parameter in getDocument, need either Uint8Array, ' +
|
|
|
+ 'string or a parameter object');
|
|
|
+ }
|
|
|
+ if (!src.url && !src.data && !src.range) {
|
|
|
+ error('Invalid parameter object: need either .data, .range or .url');
|
|
|
+ }
|
|
|
|
|
|
- if (!source.url && !source.data) {
|
|
|
- error('Invalid parameter array, need either .data or .url');
|
|
|
+ source = src;
|
|
|
}
|
|
|
|
|
|
// copy/use all keys as is except 'url' -- full path is required
|
|
@@ -1823,22 +1845,148 @@ PDFJS.getDocument = function getDocument(source,
|
|
|
if (key === 'url' && typeof window !== 'undefined') {
|
|
|
params[key] = combineUrl(window.location.href, source[key]);
|
|
|
continue;
|
|
|
+ } else if (key === 'range') {
|
|
|
+ continue;
|
|
|
}
|
|
|
params[key] = source[key];
|
|
|
}
|
|
|
|
|
|
workerInitializedCapability = createPromiseCapability();
|
|
|
- workerReadyCapability = createPromiseCapability();
|
|
|
- transport = new WorkerTransport(workerInitializedCapability,
|
|
|
- workerReadyCapability, pdfDataRangeTransport,
|
|
|
- progressCallback);
|
|
|
+ transport = new WorkerTransport(workerInitializedCapability, source.range);
|
|
|
workerInitializedCapability.promise.then(function transportInitialized() {
|
|
|
- transport.passwordCallback = passwordCallback;
|
|
|
- transport.fetchDocument(params);
|
|
|
+ transport.fetchDocument(task, params);
|
|
|
});
|
|
|
- return workerReadyCapability.promise;
|
|
|
+
|
|
|
+ return task;
|
|
|
};
|
|
|
|
|
|
+/**
|
|
|
+ * PDF document loading operation.
|
|
|
+ * @class
|
|
|
+ */
|
|
|
+var PDFDocumentLoadingTask = (function PDFDocumentLoadingTaskClosure() {
|
|
|
+ /** @constructs PDFDocumentLoadingTask */
|
|
|
+ function PDFDocumentLoadingTask() {
|
|
|
+ this._capability = createPromiseCapability();
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Callback to request a password if wrong or no password was provided.
|
|
|
+ * The callback receives two parameters: function that needs to be called
|
|
|
+ * with new password and reason (see {PasswordResponses}).
|
|
|
+ */
|
|
|
+ this.onPassword = null;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Callback to be able to monitor the loading progress of the PDF file
|
|
|
+ * (necessary to implement e.g. a loading bar). The callback receives
|
|
|
+ * an {Object} with the properties: {number} loaded and {number} total.
|
|
|
+ */
|
|
|
+ this.onProgress = null;
|
|
|
+ }
|
|
|
+
|
|
|
+ PDFDocumentLoadingTask.prototype =
|
|
|
+ /** @lends PDFDocumentLoadingTask.prototype */ {
|
|
|
+ /**
|
|
|
+ * @return {Promise}
|
|
|
+ */
|
|
|
+ get promise() {
|
|
|
+ return this._capability.promise;
|
|
|
+ },
|
|
|
+
|
|
|
+ // TODO add cancel or abort method
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Registers callbacks to indicate the document loading completion.
|
|
|
+ *
|
|
|
+ * @param {function} onFulfilled The callback for the loading completion.
|
|
|
+ * @param {function} onRejected The callback for the loading failure.
|
|
|
+ * @return {Promise} A promise that is resolved after the onFulfilled or
|
|
|
+ * onRejected callback.
|
|
|
+ */
|
|
|
+ then: function PDFDocumentLoadingTask_then(onFulfilled, onRejected) {
|
|
|
+ return this.promise.then.apply(this.promise, arguments);
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ return PDFDocumentLoadingTask;
|
|
|
+})();
|
|
|
+
|
|
|
+/**
|
|
|
+ * Abstract class to support range requests file loading.
|
|
|
+ * @class
|
|
|
+ */
|
|
|
+var PDFDataRangeTransport = (function pdfDataRangeTransportClosure() {
|
|
|
+ /**
|
|
|
+ * @constructs PDFDataRangeTransport
|
|
|
+ * @param {number} length
|
|
|
+ * @param {Uint8Array} initialData
|
|
|
+ */
|
|
|
+ function PDFDataRangeTransport(length, initialData) {
|
|
|
+ this.length = length;
|
|
|
+ this.initialData = initialData;
|
|
|
+
|
|
|
+ this._rangeListeners = [];
|
|
|
+ this._progressListeners = [];
|
|
|
+ this._progressiveReadListeners = [];
|
|
|
+ this._readyCapability = createPromiseCapability();
|
|
|
+ }
|
|
|
+ PDFDataRangeTransport.prototype =
|
|
|
+ /** @lends PDFDataRangeTransport.prototype */ {
|
|
|
+ addRangeListener:
|
|
|
+ function PDFDataRangeTransport_addRangeListener(listener) {
|
|
|
+ this._rangeListeners.push(listener);
|
|
|
+ },
|
|
|
+
|
|
|
+ addProgressListener:
|
|
|
+ function PDFDataRangeTransport_addProgressListener(listener) {
|
|
|
+ this._progressListeners.push(listener);
|
|
|
+ },
|
|
|
+
|
|
|
+ addProgressiveReadListener:
|
|
|
+ function PDFDataRangeTransport_addProgressiveReadListener(listener) {
|
|
|
+ this._progressiveReadListeners.push(listener);
|
|
|
+ },
|
|
|
+
|
|
|
+ onDataRange: function PDFDataRangeTransport_onDataRange(begin, chunk) {
|
|
|
+ var listeners = this._rangeListeners;
|
|
|
+ for (var i = 0, n = listeners.length; i < n; ++i) {
|
|
|
+ listeners[i](begin, chunk);
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ onDataProgress: function PDFDataRangeTransport_onDataProgress(loaded) {
|
|
|
+ this._readyCapability.promise.then(function () {
|
|
|
+ var listeners = this._progressListeners;
|
|
|
+ for (var i = 0, n = listeners.length; i < n; ++i) {
|
|
|
+ listeners[i](loaded);
|
|
|
+ }
|
|
|
+ }.bind(this));
|
|
|
+ },
|
|
|
+
|
|
|
+ onDataProgressiveRead:
|
|
|
+ function PDFDataRangeTransport_onDataProgress(chunk) {
|
|
|
+ this._readyCapability.promise.then(function () {
|
|
|
+ var listeners = this._progressiveReadListeners;
|
|
|
+ for (var i = 0, n = listeners.length; i < n; ++i) {
|
|
|
+ listeners[i](chunk);
|
|
|
+ }
|
|
|
+ }.bind(this));
|
|
|
+ },
|
|
|
+
|
|
|
+ transportReady: function PDFDataRangeTransport_transportReady() {
|
|
|
+ this._readyCapability.resolve();
|
|
|
+ },
|
|
|
+
|
|
|
+ requestDataRange:
|
|
|
+ function PDFDataRangeTransport_requestDataRange(begin, end) {
|
|
|
+ throw new Error('Abstract method PDFDataRangeTransport.requestDataRange');
|
|
|
+ }
|
|
|
+ };
|
|
|
+ return PDFDataRangeTransport;
|
|
|
+})();
|
|
|
+
|
|
|
+PDFJS.PDFDataRangeTransport = PDFDataRangeTransport;
|
|
|
+
|
|
|
/**
|
|
|
* Proxy to a PDFDocument in the worker thread. Also, contains commonly used
|
|
|
* properties that can be read synchronously.
|
|
@@ -1954,7 +2102,7 @@ var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
|
|
|
return this.transport.downloadInfoCapability.promise;
|
|
|
},
|
|
|
/**
|
|
|
- * @returns {Promise} A promise this is resolved with current stats about
|
|
|
+ * @return {Promise} A promise this is resolved with current stats about
|
|
|
* document structures (see {@link PDFDocumentStats}).
|
|
|
*/
|
|
|
getStats: function PDFDocumentProxy_getStats() {
|
|
@@ -2018,7 +2166,7 @@ var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
|
|
|
* (default value is 'display').
|
|
|
* @property {Object} imageLayer - (optional) An object that has beginLayout,
|
|
|
* endLayout and appendImage functions.
|
|
|
- * @property {function} continueCallback - (optional) A function that will be
|
|
|
+ * @property {function} continueCallback - (deprecated) A function that will be
|
|
|
* called each time the rendering is paused. To continue
|
|
|
* rendering call the function that is the first argument
|
|
|
* to the callback.
|
|
@@ -2151,7 +2299,12 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
|
|
|
intentState.renderTasks = [];
|
|
|
}
|
|
|
intentState.renderTasks.push(internalRenderTask);
|
|
|
- var renderTask = new RenderTask(internalRenderTask);
|
|
|
+ var renderTask = internalRenderTask.task;
|
|
|
+
|
|
|
+ // Obsolete parameter support
|
|
|
+ if (params.continueCallback) {
|
|
|
+ renderTask.onContinue = params.continueCallback;
|
|
|
+ }
|
|
|
|
|
|
var self = this;
|
|
|
intentState.displayReadyCapability.promise.then(
|
|
@@ -2316,19 +2469,16 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
|
|
|
* @ignore
|
|
|
*/
|
|
|
var WorkerTransport = (function WorkerTransportClosure() {
|
|
|
- function WorkerTransport(workerInitializedCapability, workerReadyCapability,
|
|
|
- pdfDataRangeTransport, progressCallback) {
|
|
|
+ function WorkerTransport(workerInitializedCapability, pdfDataRangeTransport) {
|
|
|
this.pdfDataRangeTransport = pdfDataRangeTransport;
|
|
|
-
|
|
|
this.workerInitializedCapability = workerInitializedCapability;
|
|
|
- this.workerReadyCapability = workerReadyCapability;
|
|
|
- this.progressCallback = progressCallback;
|
|
|
this.commonObjs = new PDFObjects();
|
|
|
|
|
|
+ this.loadingTask = null;
|
|
|
+
|
|
|
this.pageCache = [];
|
|
|
this.pagePromises = [];
|
|
|
this.downloadInfoCapability = createPromiseCapability();
|
|
|
- this.passwordCallback = null;
|
|
|
|
|
|
// If worker support isn't disabled explicit and the browser has worker
|
|
|
// support, create a new web worker and test if it/the browser fullfills
|
|
@@ -2423,48 +2573,50 @@ var WorkerTransport = (function WorkerTransportClosure() {
|
|
|
this.numPages = data.pdfInfo.numPages;
|
|
|
var pdfDocument = new PDFDocumentProxy(pdfInfo, this);
|
|
|
this.pdfDocument = pdfDocument;
|
|
|
- this.workerReadyCapability.resolve(pdfDocument);
|
|
|
+ this.loadingTask._capability.resolve(pdfDocument);
|
|
|
}, this);
|
|
|
|
|
|
messageHandler.on('NeedPassword',
|
|
|
function transportNeedPassword(exception) {
|
|
|
- if (this.passwordCallback) {
|
|
|
- return this.passwordCallback(updatePassword,
|
|
|
- PasswordResponses.NEED_PASSWORD);
|
|
|
+ var loadingTask = this.loadingTask;
|
|
|
+ if (loadingTask.onPassword) {
|
|
|
+ return loadingTask.onPassword(updatePassword,
|
|
|
+ PasswordResponses.NEED_PASSWORD);
|
|
|
}
|
|
|
- this.workerReadyCapability.reject(
|
|
|
+ loadingTask._capability.reject(
|
|
|
new PasswordException(exception.message, exception.code));
|
|
|
}, this);
|
|
|
|
|
|
messageHandler.on('IncorrectPassword',
|
|
|
function transportIncorrectPassword(exception) {
|
|
|
- if (this.passwordCallback) {
|
|
|
- return this.passwordCallback(updatePassword,
|
|
|
- PasswordResponses.INCORRECT_PASSWORD);
|
|
|
+ var loadingTask = this.loadingTask;
|
|
|
+ if (loadingTask.onPassword) {
|
|
|
+ return loadingTask.onPassword(updatePassword,
|
|
|
+ PasswordResponses.INCORRECT_PASSWORD);
|
|
|
}
|
|
|
- this.workerReadyCapability.reject(
|
|
|
+ loadingTask._capability.reject(
|
|
|
new PasswordException(exception.message, exception.code));
|
|
|
}, this);
|
|
|
|
|
|
messageHandler.on('InvalidPDF', function transportInvalidPDF(exception) {
|
|
|
- this.workerReadyCapability.reject(
|
|
|
+ this.loadingTask._capability.reject(
|
|
|
new InvalidPDFException(exception.message));
|
|
|
}, this);
|
|
|
|
|
|
messageHandler.on('MissingPDF', function transportMissingPDF(exception) {
|
|
|
- this.workerReadyCapability.reject(
|
|
|
+ this.loadingTask._capability.reject(
|
|
|
new MissingPDFException(exception.message));
|
|
|
}, this);
|
|
|
|
|
|
messageHandler.on('UnexpectedResponse',
|
|
|
function transportUnexpectedResponse(exception) {
|
|
|
- this.workerReadyCapability.reject(
|
|
|
+ this.loadingTask._capability.reject(
|
|
|
new UnexpectedResponseException(exception.message, exception.status));
|
|
|
}, this);
|
|
|
|
|
|
messageHandler.on('UnknownError',
|
|
|
function transportUnknownError(exception) {
|
|
|
- this.workerReadyCapability.reject(
|
|
|
+ this.loadingTask._capability.reject(
|
|
|
new UnknownErrorException(exception.message, exception.details));
|
|
|
}, this);
|
|
|
|
|
@@ -2559,8 +2711,9 @@ var WorkerTransport = (function WorkerTransportClosure() {
|
|
|
}, this);
|
|
|
|
|
|
messageHandler.on('DocProgress', function transportDocProgress(data) {
|
|
|
- if (this.progressCallback) {
|
|
|
- this.progressCallback({
|
|
|
+ var loadingTask = this.loadingTask;
|
|
|
+ if (loadingTask.onProgress) {
|
|
|
+ loadingTask.onProgress({
|
|
|
loaded: data.loaded,
|
|
|
total: data.total
|
|
|
});
|
|
@@ -2620,10 +2773,16 @@ var WorkerTransport = (function WorkerTransportClosure() {
|
|
|
});
|
|
|
},
|
|
|
|
|
|
- fetchDocument: function WorkerTransport_fetchDocument(source) {
|
|
|
+ fetchDocument: function WorkerTransport_fetchDocument(loadingTask, source) {
|
|
|
+ this.loadingTask = loadingTask;
|
|
|
+
|
|
|
source.disableAutoFetch = PDFJS.disableAutoFetch;
|
|
|
source.disableStream = PDFJS.disableStream;
|
|
|
source.chunkedViewerLoading = !!this.pdfDataRangeTransport;
|
|
|
+ if (this.pdfDataRangeTransport) {
|
|
|
+ source.length = this.pdfDataRangeTransport.length;
|
|
|
+ source.initialData = this.pdfDataRangeTransport.initialData;
|
|
|
+ }
|
|
|
this.messageHandler.send('GetDocRequest', {
|
|
|
source: source,
|
|
|
disableRange: PDFJS.disableRange,
|
|
@@ -2834,26 +2993,37 @@ var PDFObjects = (function PDFObjectsClosure() {
|
|
|
*/
|
|
|
var RenderTask = (function RenderTaskClosure() {
|
|
|
function RenderTask(internalRenderTask) {
|
|
|
- this.internalRenderTask = internalRenderTask;
|
|
|
+ this._internalRenderTask = internalRenderTask;
|
|
|
+
|
|
|
/**
|
|
|
- * Promise for rendering task completion.
|
|
|
- * @type {Promise}
|
|
|
+ * Callback for incremental rendering -- a function that will be called
|
|
|
+ * each time the rendering is paused. To continue rendering call the
|
|
|
+ * function that is the first argument to the callback.
|
|
|
+ * @type {function}
|
|
|
*/
|
|
|
- this.promise = this.internalRenderTask.capability.promise;
|
|
|
+ this.onContinue = null;
|
|
|
}
|
|
|
|
|
|
RenderTask.prototype = /** @lends RenderTask.prototype */ {
|
|
|
+ /**
|
|
|
+ * Promise for rendering task completion.
|
|
|
+ * @return {Promise}
|
|
|
+ */
|
|
|
+ get promise() {
|
|
|
+ return this._internalRenderTask.capability.promise;
|
|
|
+ },
|
|
|
+
|
|
|
/**
|
|
|
* Cancels the rendering task. If the task is currently rendering it will
|
|
|
* not be cancelled until graphics pauses with a timeout. The promise that
|
|
|
* this object extends will resolved when cancelled.
|
|
|
*/
|
|
|
cancel: function RenderTask_cancel() {
|
|
|
- this.internalRenderTask.cancel();
|
|
|
+ this._internalRenderTask.cancel();
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
- * Registers callback to indicate the rendering task completion.
|
|
|
+ * Registers callbacks to indicate the rendering task completion.
|
|
|
*
|
|
|
* @param {function} onFulfilled The callback for the rendering completion.
|
|
|
* @param {function} onRejected The callback for the rendering failure.
|
|
@@ -2861,7 +3031,7 @@ var RenderTask = (function RenderTaskClosure() {
|
|
|
* onRejected callback.
|
|
|
*/
|
|
|
then: function RenderTask_then(onFulfilled, onRejected) {
|
|
|
- return this.promise.then(onFulfilled, onRejected);
|
|
|
+ return this.promise.then.apply(this.promise, arguments);
|
|
|
}
|
|
|
};
|
|
|
|
|
@@ -2888,6 +3058,7 @@ var InternalRenderTask = (function InternalRenderTaskClosure() {
|
|
|
this.graphicsReady = false;
|
|
|
this.cancelled = false;
|
|
|
this.capability = createPromiseCapability();
|
|
|
+ this.task = new RenderTask(this);
|
|
|
// caching this-bound methods
|
|
|
this._continueBound = this._continue.bind(this);
|
|
|
this._scheduleNextBound = this._scheduleNext.bind(this);
|
|
@@ -2950,8 +3121,8 @@ var InternalRenderTask = (function InternalRenderTaskClosure() {
|
|
|
if (this.cancelled) {
|
|
|
return;
|
|
|
}
|
|
|
- if (this.params.continueCallback) {
|
|
|
- this.params.continueCallback(this._scheduleNextBound);
|
|
|
+ if (this.task.onContinue) {
|
|
|
+ this.task.onContinue.call(this.task, this._scheduleNextBound);
|
|
|
} else {
|
|
|
this._scheduleNext();
|
|
|
}
|