Browse Source

PDF.js version 1.0.197

master v1.0.197
Yury Delendik 11 years ago
parent
commit
b87f319e8e
  1. 2
      bower.json
  2. 400
      build/pdf.combined.js
  3. 297
      build/pdf.js
  4. 182
      build/pdf.worker.js
  5. 2
      package.json

2
bower.json

@ -1,6 +1,6 @@
{ {
"name": "pdfjs-dist", "name": "pdfjs-dist",
"version": "1.0.194", "version": "1.0.197",
"keywords": [ "keywords": [
"Mozilla", "Mozilla",
"pdf", "pdf",

400
build/pdf.combined.js

@ -21,8 +21,8 @@ if (typeof PDFJS === 'undefined') {
(typeof window !== 'undefined' ? window : this).PDFJS = {}; (typeof window !== 'undefined' ? window : this).PDFJS = {};
} }
PDFJS.version = '1.0.194'; PDFJS.version = '1.0.197';
PDFJS.build = '36c6bc2'; PDFJS.build = '44cd0f4';
(function pdfjsWrapper() { (function pdfjsWrapper() {
// Use strict in our context only - users might not want it // Use strict in our context only - users might not want it
@ -1439,7 +1439,7 @@ function MessageHandler(name, comObj) {
this.comObj = comObj; this.comObj = comObj;
this.callbackIndex = 1; this.callbackIndex = 1;
this.postMessageTransfers = true; this.postMessageTransfers = true;
var callbacks = this.callbacks = {}; var callbacksCapabilities = this.callbacksCapabilities = {};
var ah = this.actionHandler = {}; var ah = this.actionHandler = {};
ah['console_log'] = [function ahConsoleLog(data) { ah['console_log'] = [function ahConsoleLog(data) {
@ -1456,35 +1456,40 @@ function MessageHandler(name, comObj) {
var data = event.data; var data = event.data;
if (data.isReply) { if (data.isReply) {
var callbackId = data.callbackId; var callbackId = data.callbackId;
if (data.callbackId in callbacks) { if (data.callbackId in callbacksCapabilities) {
var callback = callbacks[callbackId]; var callback = callbacksCapabilities[callbackId];
delete callbacks[callbackId]; delete callbacksCapabilities[callbackId];
callback(data.data); if ('error' in data) {
callback.reject(data.error);
} else {
callback.resolve(data.data);
}
} else { } else {
error('Cannot resolve callback ' + callbackId); error('Cannot resolve callback ' + callbackId);
} }
} else if (data.action in ah) { } else if (data.action in ah) {
var action = ah[data.action]; var action = ah[data.action];
if (data.callbackId) { if (data.callbackId) {
var deferred = {}; Promise.resolve().then(function () {
var promise = new Promise(function (resolve, reject) { return action[0].call(action[1], data.data);
deferred.resolve = resolve; }).then(function (result) {
deferred.reject = reject;
});
deferred.promise = promise;
promise.then(function(resolvedData) {
comObj.postMessage({ comObj.postMessage({
isReply: true, isReply: true,
callbackId: data.callbackId, callbackId: data.callbackId,
data: resolvedData data: result
});
}, function (reason) {
comObj.postMessage({
isReply: true,
callbackId: data.callbackId,
error: reason
}); });
}); });
action[0].call(action[1], data.data, deferred);
} else { } else {
action[0].call(action[1], data.data); action[0].call(action[1], data.data);
} }
} else { } else {
error('Unkown action from worker: ' + data.action); error('Unknown action from worker: ' + data.action);
} }
}; };
} }
@ -1501,19 +1506,47 @@ MessageHandler.prototype = {
* Sends a message to the comObj to invoke the action with the supplied data. * Sends a message to the comObj to invoke the action with the supplied data.
* @param {String} actionName Action to call. * @param {String} actionName Action to call.
* @param {JSON} data JSON data to send. * @param {JSON} data JSON data to send.
* @param {function} [callback] Optional callback that will handle a reply.
* @param {Array} [transfers] Optional list of transfers/ArrayBuffers * @param {Array} [transfers] Optional list of transfers/ArrayBuffers
*/ */
send: function messageHandlerSend(actionName, data, callback, transfers) { send: function messageHandlerSend(actionName, data, transfers) {
var message = { var message = {
action: actionName, action: actionName,
data: data data: data
}; };
if (callback) { this.postMessage(message, transfers);
var callbackId = this.callbackIndex++; },
this.callbacks[callbackId] = callback; /**
message.callbackId = callbackId; * Sends a message to the comObj to invoke the action with the supplied data.
* Expects that other side will callback with the response.
* @param {String} actionName Action to call.
* @param {JSON} data JSON data to send.
* @param {Array} [transfers] Optional list of transfers/ArrayBuffers.
* @returns {Promise} Promise to be resolved with response data.
*/
sendWithPromise:
function messageHandlerSendWithPromise(actionName, data, transfers) {
var callbackId = this.callbackIndex++;
var message = {
action: actionName,
data: data,
callbackId: callbackId
};
var capability = createPromiseCapability();
this.callbacksCapabilities[callbackId] = capability;
try {
this.postMessage(message, transfers);
} catch (e) {
capability.reject(e);
} }
return capability.promise;
},
/**
* Sends raw message to the comObj.
* @private
* @param message {Object} Raw message.
* @param transfers List of transfers/ArrayBuffers, or undefined.
*/
postMessage: function (message, transfers) {
if (transfers && this.postMessageTransfers) { if (transfers && this.postMessageTransfers) {
this.comObj.postMessage(message, transfers); this.comObj.postMessage(message, transfers);
} else { } else {
@ -4326,7 +4359,8 @@ var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
* @class * @class
*/ */
var PDFPageProxy = (function PDFPageProxyClosure() { var PDFPageProxy = (function PDFPageProxyClosure() {
function PDFPageProxy(pageInfo, transport) { function PDFPageProxy(pageIndex, pageInfo, transport) {
this.pageIndex = pageIndex;
this.pageInfo = pageInfo; this.pageInfo = pageInfo;
this.transport = transport; this.transport = transport;
this.stats = new StatTimer(); this.stats = new StatTimer();
@ -4342,7 +4376,7 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
* @return {number} Page number of the page. First page is 1. * @return {number} Page number of the page. First page is 1.
*/ */
get pageNumber() { get pageNumber() {
return this.pageInfo.pageIndex + 1; return this.pageIndex + 1;
}, },
/** /**
* @return {number} The number of degrees the page is rotated clockwise. * @return {number} The number of degrees the page is rotated clockwise.
@ -4382,14 +4416,13 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
* annotation objects. * annotation objects.
*/ */
getAnnotations: function PDFPageProxy_getAnnotations() { getAnnotations: function PDFPageProxy_getAnnotations() {
if (this.annotationsCapability) { if (this.annotationsPromise) {
return this.annotationsCapability.promise; return this.annotationsPromise;
} }
var capability = createPromiseCapability(); var promise = this.transport.getAnnotations(this.pageIndex);
this.annotationsCapability = capability; this.annotationsPromise = promise;
this.transport.getAnnotations(this.pageInfo.pageIndex); return promise;
return capability.promise;
}, },
/** /**
* Begins the process of rendering a page to the desired context. * Begins the process of rendering a page to the desired context.
@ -4485,15 +4518,9 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
* object that represent the page text content. * object that represent the page text content.
*/ */
getTextContent: function PDFPageProxy_getTextContent() { getTextContent: function PDFPageProxy_getTextContent() {
return new Promise(function (resolve) { return this.transport.messageHandler.sendWithPromise('GetTextContent', {
this.transport.messageHandler.send('GetTextContent', { pageIndex: this.pageNumber - 1
pageIndex: this.pageNumber - 1 });
},
function textContentCallback(textContent) {
resolve(textContent);
}
);
}.bind(this));
}, },
/** /**
* Destroys resources allocated by the page. * Destroys resources allocated by the page.
@ -4521,6 +4548,7 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
delete this.intentStates[intent]; delete this.intentStates[intent];
}, this); }, this);
this.objs.clear(); this.objs.clear();
this.annotationsPromise = null;
this.pendingDestroy = false; this.pendingDestroy = false;
}, },
/** /**
@ -4576,7 +4604,7 @@ var WorkerTransport = (function WorkerTransportClosure() {
this.commonObjs = new PDFObjects(); this.commonObjs = new PDFObjects();
this.pageCache = []; this.pageCache = [];
this.pageCapabilities = []; this.pagePromises = [];
this.downloadInfoCapability = createPromiseCapability(); this.downloadInfoCapability = createPromiseCapability();
this.passwordCallback = null; this.passwordCallback = null;
@ -4596,9 +4624,9 @@ var WorkerTransport = (function WorkerTransportClosure() {
WorkerTransport.prototype = { WorkerTransport.prototype = {
destroy: function WorkerTransport_destroy() { destroy: function WorkerTransport_destroy() {
this.pageCache = []; this.pageCache = [];
this.pageCapabilities = []; this.pagePromises = [];
var self = this; var self = this;
this.messageHandler.send('Terminate', null, function () { this.messageHandler.sendWithPromise('Terminate', null).then(function () {
FontLoader.clear(); FontLoader.clear();
if (self.worker) { if (self.worker) {
self.worker.terminate(); self.worker.terminate();
@ -4708,20 +4736,6 @@ var WorkerTransport = (function WorkerTransportClosure() {
this.downloadInfoCapability.resolve(data); this.downloadInfoCapability.resolve(data);
}, this); }, this);
messageHandler.on('GetPage', function transportPage(data) {
var pageInfo = data.pageInfo;
var page = new PDFPageProxy(pageInfo, this);
this.pageCache[pageInfo.pageIndex] = page;
var promise = this.pageCapabilities[pageInfo.pageIndex];
promise.resolve(page);
}, this);
messageHandler.on('GetAnnotations', function transportAnnotations(data) {
var annotations = data.annotations;
var promise = this.pageCache[data.pageIndex].annotationsCapability;
promise.resolve(annotations);
}, this);
messageHandler.on('StartRenderPage', function transportRender(data) { messageHandler.on('StartRenderPage', function transportRender(data) {
var page = this.pageCache[data.pageIndex]; var page = this.pageCache[data.pageIndex];
@ -4815,9 +4829,9 @@ var WorkerTransport = (function WorkerTransportClosure() {
this.workerReadyCapability.reject(data); this.workerReadyCapability.reject(data);
}, this); }, this);
messageHandler.on('PageError', function transportError(data, intent) { messageHandler.on('PageError', function transportError(data) {
var page = this.pageCache[data.pageNum - 1]; var page = this.pageCache[data.pageNum - 1];
var intentState = page.intentStates[intent]; var intentState = page.intentStates[data.intent];
if (intentState.displayReadyCapability.promise) { if (intentState.displayReadyCapability.promise) {
intentState.displayReadyCapability.reject(data.error); intentState.displayReadyCapability.reject(data.error);
} else { } else {
@ -4825,40 +4839,46 @@ var WorkerTransport = (function WorkerTransportClosure() {
} }
}, this); }, this);
messageHandler.on('JpegDecode', function(data, deferred) { messageHandler.on('JpegDecode', function(data) {
var imageUrl = data[0]; var imageUrl = data[0];
var components = data[1]; var components = data[1];
if (components != 3 && components != 1) { if (components != 3 && components != 1) {
error('Only 3 component or 1 component can be returned'); return Promise.reject(
} new Error('Only 3 components or 1 component can be returned'));
}
var img = new Image();
img.onload = (function messageHandler_onloadClosure() { return new Promise(function (resolve, reject) {
var width = img.width; var img = new Image();
var height = img.height; img.onload = function () {
var size = width * height; var width = img.width;
var rgbaLength = size * 4; var height = img.height;
var buf = new Uint8Array(size * components); var size = width * height;
var tmpCanvas = createScratchCanvas(width, height); var rgbaLength = size * 4;
var tmpCtx = tmpCanvas.getContext('2d'); var buf = new Uint8Array(size * components);
tmpCtx.drawImage(img, 0, 0); var tmpCanvas = createScratchCanvas(width, height);
var data = tmpCtx.getImageData(0, 0, width, height).data; var tmpCtx = tmpCanvas.getContext('2d');
var i, j; tmpCtx.drawImage(img, 0, 0);
var data = tmpCtx.getImageData(0, 0, width, height).data;
if (components == 3) { var i, j;
for (i = 0, j = 0; i < rgbaLength; i += 4, j += 3) {
buf[j] = data[i]; if (components == 3) {
buf[j + 1] = data[i + 1]; for (i = 0, j = 0; i < rgbaLength; i += 4, j += 3) {
buf[j + 2] = data[i + 2]; buf[j] = data[i];
} buf[j + 1] = data[i + 1];
} else if (components == 1) { buf[j + 2] = data[i + 2];
for (i = 0, j = 0; i < rgbaLength; i += 4, j++) { }
buf[j] = data[i]; } else if (components == 1) {
for (i = 0, j = 0; i < rgbaLength; i += 4, j++) {
buf[j] = data[i];
}
} }
} resolve({ data: buf, width: width, height: height});
deferred.resolve({ data: buf, width: width, height: height}); };
}).bind(this); img.onerror = function () {
img.src = imageUrl; reject(new Error('JpegDecode failed to load image'));
};
img.src = imageUrl;
});
}); });
}, },
@ -4890,96 +4910,67 @@ var WorkerTransport = (function WorkerTransportClosure() {
} }
var pageIndex = pageNumber - 1; var pageIndex = pageNumber - 1;
if (pageIndex in this.pageCapabilities) { if (pageIndex in this.pagePromises) {
return this.pageCapabilities[pageIndex].promise; return this.pagePromises[pageIndex];
} }
capability = createPromiseCapability(); var promise = this.messageHandler.sendWithPromise('GetPage', {
this.pageCapabilities[pageIndex] = capability; pageIndex: pageIndex
this.messageHandler.send('GetPageRequest', { pageIndex: pageIndex }); }).then(function (pageInfo) {
return capability.promise; var page = new PDFPageProxy(pageIndex, pageInfo, this);
this.pageCache[pageIndex] = page;
return page;
}.bind(this));
this.pagePromises[pageIndex] = promise;
return promise;
}, },
getPageIndex: function WorkerTransport_getPageIndexByRef(ref) { getPageIndex: function WorkerTransport_getPageIndexByRef(ref) {
return new Promise(function (resolve) { return this.messageHandler.sendWithPromise('GetPageIndex', { ref: ref });
this.messageHandler.send('GetPageIndex', { ref: ref },
function (pageIndex) {
resolve(pageIndex);
}
);
}.bind(this));
}, },
getAnnotations: function WorkerTransport_getAnnotations(pageIndex) { getAnnotations: function WorkerTransport_getAnnotations(pageIndex) {
this.messageHandler.send('GetAnnotationsRequest', return this.messageHandler.sendWithPromise('GetAnnotations',
{ pageIndex: pageIndex }); { pageIndex: pageIndex });
}, },
getDestinations: function WorkerTransport_getDestinations() { getDestinations: function WorkerTransport_getDestinations() {
return new Promise(function (resolve) { return this.messageHandler.sendWithPromise('GetDestinations', null);
this.messageHandler.send('GetDestinations', null,
function transportDestinations(destinations) {
resolve(destinations);
}
);
}.bind(this));
}, },
getAttachments: function WorkerTransport_getAttachments() { getAttachments: function WorkerTransport_getAttachments() {
return new Promise(function (resolve) { return this.messageHandler.sendWithPromise('GetAttachments', null);
this.messageHandler.send('GetAttachments', null,
function transportAttachments(attachments) {
resolve(attachments);
}
);
}.bind(this));
}, },
getJavaScript: function WorkerTransport_getJavaScript() { getJavaScript: function WorkerTransport_getJavaScript() {
return new Promise(function (resolve) { return this.messageHandler.sendWithPromise('GetJavaScript', null);
this.messageHandler.send('GetJavaScript', null,
function transportJavaScript(js) {
resolve(js);
}
);
}.bind(this));
}, },
getOutline: function WorkerTransport_getOutline() { getOutline: function WorkerTransport_getOutline() {
return new Promise(function (resolve) { return this.messageHandler.sendWithPromise('GetOutline', null);
this.messageHandler.send('GetOutline', null,
function transportOutline(outline) {
resolve(outline);
}
);
}.bind(this));
}, },
getMetadata: function WorkerTransport_getMetadata() { getMetadata: function WorkerTransport_getMetadata() {
return new Promise(function (resolve) { return this.messageHandler.sendWithPromise('GetMetadata', null).
this.messageHandler.send('GetMetadata', null, then(function transportMetadata(results) {
function transportMetadata(results) { return {
resolve({ info: results[0],
info: results[0], metadata: (results[1] ? new PDFJS.Metadata(results[1]) : null)
metadata: (results[1] ? new PDFJS.Metadata(results[1]) : null) };
}); });
}
);
}.bind(this));
}, },
startCleanup: function WorkerTransport_startCleanup() { startCleanup: function WorkerTransport_startCleanup() {
this.messageHandler.send('Cleanup', null, this.messageHandler.sendWithPromise('Cleanup', null).
function endCleanup() { then(function endCleanup() {
for (var i = 0, ii = this.pageCache.length; i < ii; i++) { for (var i = 0, ii = this.pageCache.length; i < ii; i++) {
var page = this.pageCache[i]; var page = this.pageCache[i];
if (page) { if (page) {
page.destroy(); page.destroy();
}
} }
this.commonObjs.clear(); }
FontLoader.clear(); this.commonObjs.clear();
}.bind(this) FontLoader.clear();
); }.bind(this));
} }
}; };
return WorkerTransport; return WorkerTransport;
@ -20283,7 +20274,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
then(function(imageObj) { then(function(imageObj) {
var imgData = imageObj.createImageData(/* forceRGBA = */ false); var imgData = imageObj.createImageData(/* forceRGBA = */ false);
self.handler.send('obj', [objId, self.pageIndex, 'Image', imgData], self.handler.send('obj', [objId, self.pageIndex, 'Image', imgData],
null, [imgData.data.buffer]); [imgData.data.buffer]);
}).then(null, function (reason) { }).then(null, function (reason) {
warn('Unable to decode image: ' + reason); warn('Unable to decode image: ' + reason);
self.handler.send('obj', [objId, self.pageIndex, 'Image', null]); self.handler.send('obj', [objId, self.pageIndex, 'Image', null]);
@ -21681,7 +21672,7 @@ var OperatorList = (function OperatorListClosure() {
}, },
pageIndex: this.pageIndex, pageIndex: this.pageIndex,
intent: this.intent intent: this.intent
}, null, transfers); }, transfers);
this.dependencies = {}; this.dependencies = {};
this.fnArray.length = 0; this.fnArray.length = 0;
this.argsArray.length = 0; this.argsArray.length = 0;
@ -35022,14 +35013,11 @@ var PDFImage = (function PDFImageClosure() {
var colorSpace = dict.get('ColorSpace', 'CS'); var colorSpace = dict.get('ColorSpace', 'CS');
colorSpace = ColorSpace.parse(colorSpace, xref, res); colorSpace = ColorSpace.parse(colorSpace, xref, res);
var numComps = colorSpace.numComps; var numComps = colorSpace.numComps;
var resolvePromise; var decodePromise = handler.sendWithPromise('JpegDecode',
handler.send('JpegDecode', [image.getIR(), numComps], function(message) { [image.getIR(), numComps]);
return decodePromise.then(function (message) {
var data = message.data; var data = message.data;
var stream = new Stream(data, 0, data.length, image.dict); return new Stream(data, 0, data.length, image.dict);
resolvePromise(stream);
});
return new Promise(function (resolve) {
resolvePromise = resolve;
}); });
} else { } else {
return Promise.resolve(image); return Promise.resolve(image);
@ -42258,81 +42246,64 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
}, onFailure); }, onFailure);
}); });
handler.on('GetPageRequest', function wphSetupGetPage(data) { handler.on('GetPage', function wphSetupGetPage(data) {
var pageIndex = data.pageIndex; return pdfManager.getPage(data.pageIndex).then(function(page) {
pdfManager.getPage(pageIndex).then(function(page) {
var rotatePromise = pdfManager.ensure(page, 'rotate'); var rotatePromise = pdfManager.ensure(page, 'rotate');
var refPromise = pdfManager.ensure(page, 'ref'); var refPromise = pdfManager.ensure(page, 'ref');
var viewPromise = pdfManager.ensure(page, 'view'); var viewPromise = pdfManager.ensure(page, 'view');
Promise.all([rotatePromise, refPromise, viewPromise]).then( return Promise.all([rotatePromise, refPromise, viewPromise]).then(
function(results) { function(results) {
var page = { return {
pageIndex: data.pageIndex,
rotate: results[0], rotate: results[0],
ref: results[1], ref: results[1],
view: results[2] view: results[2]
}; };
handler.send('GetPage', { pageInfo: page });
}); });
}); });
}); });
handler.on('GetPageIndex', function wphSetupGetPageIndex(data, deferred) { handler.on('GetPageIndex', function wphSetupGetPageIndex(data) {
var ref = new Ref(data.ref.num, data.ref.gen); var ref = new Ref(data.ref.num, data.ref.gen);
var catalog = pdfManager.pdfDocument.catalog; var catalog = pdfManager.pdfDocument.catalog;
catalog.getPageIndex(ref).then(function (pageIndex) { return catalog.getPageIndex(ref);
deferred.resolve(pageIndex);
}, deferred.reject);
}); });
handler.on('GetDestinations', handler.on('GetDestinations',
function wphSetupGetDestinations(data, deferred) { function wphSetupGetDestinations(data) {
pdfManager.ensureCatalog('destinations').then(function(destinations) { return pdfManager.ensureCatalog('destinations');
deferred.resolve(destinations);
});
} }
); );
handler.on('GetAttachments', handler.on('GetAttachments',
function wphSetupGetAttachments(data, deferred) { function wphSetupGetAttachments(data) {
pdfManager.ensureCatalog('attachments').then(function(attachments) { return pdfManager.ensureCatalog('attachments');
deferred.resolve(attachments);
}, deferred.reject);
} }
); );
handler.on('GetJavaScript', handler.on('GetJavaScript',
function wphSetupGetJavaScript(data, deferred) { function wphSetupGetJavaScript(data) {
pdfManager.ensureCatalog('javaScript').then(function (js) { return pdfManager.ensureCatalog('javaScript');
deferred.resolve(js);
}, deferred.reject);
} }
); );
handler.on('GetOutline', handler.on('GetOutline',
function wphSetupGetOutline(data, deferred) { function wphSetupGetOutline(data) {
pdfManager.ensureCatalog('documentOutline').then(function (outline) { return pdfManager.ensureCatalog('documentOutline');
deferred.resolve(outline);
}, deferred.reject);
} }
); );
handler.on('GetMetadata', handler.on('GetMetadata',
function wphSetupGetMetadata(data, deferred) { function wphSetupGetMetadata(data) {
Promise.all([pdfManager.ensureDoc('documentInfo'), return Promise.all([pdfManager.ensureDoc('documentInfo'),
pdfManager.ensureCatalog('metadata')]).then( pdfManager.ensureCatalog('metadata')]);
function (results) {
deferred.resolve(results);
}, deferred.reject);
} }
); );
handler.on('GetData', function wphSetupGetData(data, deferred) { handler.on('GetData', function wphSetupGetData(data) {
pdfManager.requestLoadedStream(); pdfManager.requestLoadedStream();
pdfManager.onLoadedStream().then(function(stream) { return pdfManager.onLoadedStream().then(function(stream) {
deferred.resolve(stream.bytes); return stream.bytes;
}); });
}); });
@ -42340,16 +42311,9 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
pdfManager.updatePassword(data); pdfManager.updatePassword(data);
}); });
handler.on('GetAnnotationsRequest', function wphSetupGetAnnotations(data) { handler.on('GetAnnotations', function wphSetupGetAnnotations(data) {
pdfManager.getPage(data.pageIndex).then(function(page) { return pdfManager.getPage(data.pageIndex).then(function(page) {
pdfManager.ensure(page, 'getAnnotationsData', []).then( return pdfManager.ensure(page, 'getAnnotationsData', []);
function(annotationsData) {
handler.send('GetAnnotations', {
pageIndex: data.pageIndex,
annotations: annotationsData
});
}
);
}); });
}); });
@ -42398,29 +42362,25 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
}); });
}, this); }, this);
handler.on('GetTextContent', function wphExtractText(data, deferred) { handler.on('GetTextContent', function wphExtractText(data) {
pdfManager.getPage(data.pageIndex).then(function(page) { return pdfManager.getPage(data.pageIndex).then(function(page) {
var pageNum = data.pageIndex + 1; var pageNum = data.pageIndex + 1;
var start = Date.now(); var start = Date.now();
page.extractTextContent().then(function(textContent) { return page.extractTextContent().then(function(textContent) {
deferred.resolve(textContent);
info('text indexing: page=' + pageNum + ' - time=' + info('text indexing: page=' + pageNum + ' - time=' +
(Date.now() - start) + 'ms'); (Date.now() - start) + 'ms');
}, function (e) { return textContent;
// Skip errored pages
deferred.reject(e);
}); });
}); });
}); });
handler.on('Cleanup', function wphCleanup(data, deferred) { handler.on('Cleanup', function wphCleanup(data) {
pdfManager.cleanup(); pdfManager.cleanup();
deferred.resolve(true); return true;
}); });
handler.on('Terminate', function wphTerminate(data, deferred) { handler.on('Terminate', function wphTerminate(data) {
pdfManager.terminate(); pdfManager.terminate();
deferred.resolve();
}); });
} }
}; };

297
build/pdf.js

@ -21,8 +21,8 @@ if (typeof PDFJS === 'undefined') {
(typeof window !== 'undefined' ? window : this).PDFJS = {}; (typeof window !== 'undefined' ? window : this).PDFJS = {};
} }
PDFJS.version = '1.0.194'; PDFJS.version = '1.0.197';
PDFJS.build = '36c6bc2'; PDFJS.build = '44cd0f4';
(function pdfjsWrapper() { (function pdfjsWrapper() {
// Use strict in our context only - users might not want it // Use strict in our context only - users might not want it
@ -1439,7 +1439,7 @@ function MessageHandler(name, comObj) {
this.comObj = comObj; this.comObj = comObj;
this.callbackIndex = 1; this.callbackIndex = 1;
this.postMessageTransfers = true; this.postMessageTransfers = true;
var callbacks = this.callbacks = {}; var callbacksCapabilities = this.callbacksCapabilities = {};
var ah = this.actionHandler = {}; var ah = this.actionHandler = {};
ah['console_log'] = [function ahConsoleLog(data) { ah['console_log'] = [function ahConsoleLog(data) {
@ -1456,35 +1456,40 @@ function MessageHandler(name, comObj) {
var data = event.data; var data = event.data;
if (data.isReply) { if (data.isReply) {
var callbackId = data.callbackId; var callbackId = data.callbackId;
if (data.callbackId in callbacks) { if (data.callbackId in callbacksCapabilities) {
var callback = callbacks[callbackId]; var callback = callbacksCapabilities[callbackId];
delete callbacks[callbackId]; delete callbacksCapabilities[callbackId];
callback(data.data); if ('error' in data) {
callback.reject(data.error);
} else {
callback.resolve(data.data);
}
} else { } else {
error('Cannot resolve callback ' + callbackId); error('Cannot resolve callback ' + callbackId);
} }
} else if (data.action in ah) { } else if (data.action in ah) {
var action = ah[data.action]; var action = ah[data.action];
if (data.callbackId) { if (data.callbackId) {
var deferred = {}; Promise.resolve().then(function () {
var promise = new Promise(function (resolve, reject) { return action[0].call(action[1], data.data);
deferred.resolve = resolve; }).then(function (result) {
deferred.reject = reject; comObj.postMessage({
}); isReply: true,
deferred.promise = promise; callbackId: data.callbackId,
promise.then(function(resolvedData) { data: result
});
}, function (reason) {
comObj.postMessage({ comObj.postMessage({
isReply: true, isReply: true,
callbackId: data.callbackId, callbackId: data.callbackId,
data: resolvedData error: reason
}); });
}); });
action[0].call(action[1], data.data, deferred);
} else { } else {
action[0].call(action[1], data.data); action[0].call(action[1], data.data);
} }
} else { } else {
error('Unkown action from worker: ' + data.action); error('Unknown action from worker: ' + data.action);
} }
}; };
} }
@ -1501,19 +1506,47 @@ MessageHandler.prototype = {
* Sends a message to the comObj to invoke the action with the supplied data. * Sends a message to the comObj to invoke the action with the supplied data.
* @param {String} actionName Action to call. * @param {String} actionName Action to call.
* @param {JSON} data JSON data to send. * @param {JSON} data JSON data to send.
* @param {function} [callback] Optional callback that will handle a reply.
* @param {Array} [transfers] Optional list of transfers/ArrayBuffers * @param {Array} [transfers] Optional list of transfers/ArrayBuffers
*/ */
send: function messageHandlerSend(actionName, data, callback, transfers) { send: function messageHandlerSend(actionName, data, transfers) {
var message = { var message = {
action: actionName, action: actionName,
data: data data: data
}; };
if (callback) { this.postMessage(message, transfers);
var callbackId = this.callbackIndex++; },
this.callbacks[callbackId] = callback; /**
message.callbackId = callbackId; * Sends a message to the comObj to invoke the action with the supplied data.
} * Expects that other side will callback with the response.
* @param {String} actionName Action to call.
* @param {JSON} data JSON data to send.
* @param {Array} [transfers] Optional list of transfers/ArrayBuffers.
* @returns {Promise} Promise to be resolved with response data.
*/
sendWithPromise:
function messageHandlerSendWithPromise(actionName, data, transfers) {
var callbackId = this.callbackIndex++;
var message = {
action: actionName,
data: data,
callbackId: callbackId
};
var capability = createPromiseCapability();
this.callbacksCapabilities[callbackId] = capability;
try {
this.postMessage(message, transfers);
} catch (e) {
capability.reject(e);
}
return capability.promise;
},
/**
* Sends raw message to the comObj.
* @private
* @param message {Object} Raw message.
* @param transfers List of transfers/ArrayBuffers, or undefined.
*/
postMessage: function (message, transfers) {
if (transfers && this.postMessageTransfers) { if (transfers && this.postMessageTransfers) {
this.comObj.postMessage(message, transfers); this.comObj.postMessage(message, transfers);
} else { } else {
@ -4326,7 +4359,8 @@ var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
* @class * @class
*/ */
var PDFPageProxy = (function PDFPageProxyClosure() { var PDFPageProxy = (function PDFPageProxyClosure() {
function PDFPageProxy(pageInfo, transport) { function PDFPageProxy(pageIndex, pageInfo, transport) {
this.pageIndex = pageIndex;
this.pageInfo = pageInfo; this.pageInfo = pageInfo;
this.transport = transport; this.transport = transport;
this.stats = new StatTimer(); this.stats = new StatTimer();
@ -4342,7 +4376,7 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
* @return {number} Page number of the page. First page is 1. * @return {number} Page number of the page. First page is 1.
*/ */
get pageNumber() { get pageNumber() {
return this.pageInfo.pageIndex + 1; return this.pageIndex + 1;
}, },
/** /**
* @return {number} The number of degrees the page is rotated clockwise. * @return {number} The number of degrees the page is rotated clockwise.
@ -4382,14 +4416,13 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
* annotation objects. * annotation objects.
*/ */
getAnnotations: function PDFPageProxy_getAnnotations() { getAnnotations: function PDFPageProxy_getAnnotations() {
if (this.annotationsCapability) { if (this.annotationsPromise) {
return this.annotationsCapability.promise; return this.annotationsPromise;
} }
var capability = createPromiseCapability(); var promise = this.transport.getAnnotations(this.pageIndex);
this.annotationsCapability = capability; this.annotationsPromise = promise;
this.transport.getAnnotations(this.pageInfo.pageIndex); return promise;
return capability.promise;
}, },
/** /**
* Begins the process of rendering a page to the desired context. * Begins the process of rendering a page to the desired context.
@ -4485,15 +4518,9 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
* object that represent the page text content. * object that represent the page text content.
*/ */
getTextContent: function PDFPageProxy_getTextContent() { getTextContent: function PDFPageProxy_getTextContent() {
return new Promise(function (resolve) { return this.transport.messageHandler.sendWithPromise('GetTextContent', {
this.transport.messageHandler.send('GetTextContent', { pageIndex: this.pageNumber - 1
pageIndex: this.pageNumber - 1 });
},
function textContentCallback(textContent) {
resolve(textContent);
}
);
}.bind(this));
}, },
/** /**
* Destroys resources allocated by the page. * Destroys resources allocated by the page.
@ -4521,6 +4548,7 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
delete this.intentStates[intent]; delete this.intentStates[intent];
}, this); }, this);
this.objs.clear(); this.objs.clear();
this.annotationsPromise = null;
this.pendingDestroy = false; this.pendingDestroy = false;
}, },
/** /**
@ -4576,7 +4604,7 @@ var WorkerTransport = (function WorkerTransportClosure() {
this.commonObjs = new PDFObjects(); this.commonObjs = new PDFObjects();
this.pageCache = []; this.pageCache = [];
this.pageCapabilities = []; this.pagePromises = [];
this.downloadInfoCapability = createPromiseCapability(); this.downloadInfoCapability = createPromiseCapability();
this.passwordCallback = null; this.passwordCallback = null;
@ -4620,7 +4648,7 @@ var WorkerTransport = (function WorkerTransportClosure() {
// 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 {
messageHandler.send('test', testObj, null, [testObj.buffer]); messageHandler.send('test', testObj, [testObj.buffer]);
} catch (ex) { } catch (ex) {
info('Cannot use postMessage transfers'); info('Cannot use postMessage transfers');
testObj[0] = 0; testObj[0] = 0;
@ -4642,9 +4670,9 @@ var WorkerTransport = (function WorkerTransportClosure() {
WorkerTransport.prototype = { WorkerTransport.prototype = {
destroy: function WorkerTransport_destroy() { destroy: function WorkerTransport_destroy() {
this.pageCache = []; this.pageCache = [];
this.pageCapabilities = []; this.pagePromises = [];
var self = this; var self = this;
this.messageHandler.send('Terminate', null, function () { this.messageHandler.sendWithPromise('Terminate', null).then(function () {
FontLoader.clear(); FontLoader.clear();
if (self.worker) { if (self.worker) {
self.worker.terminate(); self.worker.terminate();
@ -4756,20 +4784,6 @@ var WorkerTransport = (function WorkerTransportClosure() {
this.downloadInfoCapability.resolve(data); this.downloadInfoCapability.resolve(data);
}, this); }, this);
messageHandler.on('GetPage', function transportPage(data) {
var pageInfo = data.pageInfo;
var page = new PDFPageProxy(pageInfo, this);
this.pageCache[pageInfo.pageIndex] = page;
var promise = this.pageCapabilities[pageInfo.pageIndex];
promise.resolve(page);
}, this);
messageHandler.on('GetAnnotations', function transportAnnotations(data) {
var annotations = data.annotations;
var promise = this.pageCache[data.pageIndex].annotationsCapability;
promise.resolve(annotations);
}, this);
messageHandler.on('StartRenderPage', function transportRender(data) { messageHandler.on('StartRenderPage', function transportRender(data) {
var page = this.pageCache[data.pageIndex]; var page = this.pageCache[data.pageIndex];
@ -4863,9 +4877,9 @@ var WorkerTransport = (function WorkerTransportClosure() {
this.workerReadyCapability.reject(data); this.workerReadyCapability.reject(data);
}, this); }, this);
messageHandler.on('PageError', function transportError(data, intent) { messageHandler.on('PageError', function transportError(data) {
var page = this.pageCache[data.pageNum - 1]; var page = this.pageCache[data.pageNum - 1];
var intentState = page.intentStates[intent]; var intentState = page.intentStates[data.intent];
if (intentState.displayReadyCapability.promise) { if (intentState.displayReadyCapability.promise) {
intentState.displayReadyCapability.reject(data.error); intentState.displayReadyCapability.reject(data.error);
} else { } else {
@ -4873,40 +4887,46 @@ var WorkerTransport = (function WorkerTransportClosure() {
} }
}, this); }, this);
messageHandler.on('JpegDecode', function(data, deferred) { messageHandler.on('JpegDecode', function(data) {
var imageUrl = data[0]; var imageUrl = data[0];
var components = data[1]; var components = data[1];
if (components != 3 && components != 1) { if (components != 3 && components != 1) {
error('Only 3 component or 1 component can be returned'); return Promise.reject(
new Error('Only 3 components or 1 component can be returned'));
} }
var img = new Image(); return new Promise(function (resolve, reject) {
img.onload = (function messageHandler_onloadClosure() { var img = new Image();
var width = img.width; img.onload = function () {
var height = img.height; var width = img.width;
var size = width * height; var height = img.height;
var rgbaLength = size * 4; var size = width * height;
var buf = new Uint8Array(size * components); var rgbaLength = size * 4;
var tmpCanvas = createScratchCanvas(width, height); var buf = new Uint8Array(size * components);
var tmpCtx = tmpCanvas.getContext('2d'); var tmpCanvas = createScratchCanvas(width, height);
tmpCtx.drawImage(img, 0, 0); var tmpCtx = tmpCanvas.getContext('2d');
var data = tmpCtx.getImageData(0, 0, width, height).data; tmpCtx.drawImage(img, 0, 0);
var i, j; var data = tmpCtx.getImageData(0, 0, width, height).data;
var i, j;
if (components == 3) {
for (i = 0, j = 0; i < rgbaLength; i += 4, j += 3) { if (components == 3) {
buf[j] = data[i]; for (i = 0, j = 0; i < rgbaLength; i += 4, j += 3) {
buf[j + 1] = data[i + 1]; buf[j] = data[i];
buf[j + 2] = data[i + 2]; buf[j + 1] = data[i + 1];
} buf[j + 2] = data[i + 2];
} else if (components == 1) { }
for (i = 0, j = 0; i < rgbaLength; i += 4, j++) { } else if (components == 1) {
buf[j] = data[i]; for (i = 0, j = 0; i < rgbaLength; i += 4, j++) {
buf[j] = data[i];
}
} }
} resolve({ data: buf, width: width, height: height});
deferred.resolve({ data: buf, width: width, height: height}); };
}).bind(this); img.onerror = function () {
img.src = imageUrl; reject(new Error('JpegDecode failed to load image'));
};
img.src = imageUrl;
});
}); });
}, },
@ -4938,96 +4958,67 @@ var WorkerTransport = (function WorkerTransportClosure() {
} }
var pageIndex = pageNumber - 1; var pageIndex = pageNumber - 1;
if (pageIndex in this.pageCapabilities) { if (pageIndex in this.pagePromises) {
return this.pageCapabilities[pageIndex].promise; return this.pagePromises[pageIndex];
} }
capability = createPromiseCapability(); var promise = this.messageHandler.sendWithPromise('GetPage', {
this.pageCapabilities[pageIndex] = capability; pageIndex: pageIndex
this.messageHandler.send('GetPageRequest', { pageIndex: pageIndex }); }).then(function (pageInfo) {
return capability.promise; var page = new PDFPageProxy(pageIndex, pageInfo, this);
this.pageCache[pageIndex] = page;
return page;
}.bind(this));
this.pagePromises[pageIndex] = promise;
return promise;
}, },
getPageIndex: function WorkerTransport_getPageIndexByRef(ref) { getPageIndex: function WorkerTransport_getPageIndexByRef(ref) {
return new Promise(function (resolve) { return this.messageHandler.sendWithPromise('GetPageIndex', { ref: ref });
this.messageHandler.send('GetPageIndex', { ref: ref },
function (pageIndex) {
resolve(pageIndex);
}
);
}.bind(this));
}, },
getAnnotations: function WorkerTransport_getAnnotations(pageIndex) { getAnnotations: function WorkerTransport_getAnnotations(pageIndex) {
this.messageHandler.send('GetAnnotationsRequest', return this.messageHandler.sendWithPromise('GetAnnotations',
{ pageIndex: pageIndex }); { pageIndex: pageIndex });
}, },
getDestinations: function WorkerTransport_getDestinations() { getDestinations: function WorkerTransport_getDestinations() {
return new Promise(function (resolve) { return this.messageHandler.sendWithPromise('GetDestinations', null);
this.messageHandler.send('GetDestinations', null,
function transportDestinations(destinations) {
resolve(destinations);
}
);
}.bind(this));
}, },
getAttachments: function WorkerTransport_getAttachments() { getAttachments: function WorkerTransport_getAttachments() {
return new Promise(function (resolve) { return this.messageHandler.sendWithPromise('GetAttachments', null);
this.messageHandler.send('GetAttachments', null,
function transportAttachments(attachments) {
resolve(attachments);
}
);
}.bind(this));
}, },
getJavaScript: function WorkerTransport_getJavaScript() { getJavaScript: function WorkerTransport_getJavaScript() {
return new Promise(function (resolve) { return this.messageHandler.sendWithPromise('GetJavaScript', null);
this.messageHandler.send('GetJavaScript', null,
function transportJavaScript(js) {
resolve(js);
}
);
}.bind(this));
}, },
getOutline: function WorkerTransport_getOutline() { getOutline: function WorkerTransport_getOutline() {
return new Promise(function (resolve) { return this.messageHandler.sendWithPromise('GetOutline', null);
this.messageHandler.send('GetOutline', null,
function transportOutline(outline) {
resolve(outline);
}
);
}.bind(this));
}, },
getMetadata: function WorkerTransport_getMetadata() { getMetadata: function WorkerTransport_getMetadata() {
return new Promise(function (resolve) { return this.messageHandler.sendWithPromise('GetMetadata', null).
this.messageHandler.send('GetMetadata', null, then(function transportMetadata(results) {
function transportMetadata(results) { return {
resolve({ info: results[0],
info: results[0], metadata: (results[1] ? new PDFJS.Metadata(results[1]) : null)
metadata: (results[1] ? new PDFJS.Metadata(results[1]) : null) };
}); });
}
);
}.bind(this));
}, },
startCleanup: function WorkerTransport_startCleanup() { startCleanup: function WorkerTransport_startCleanup() {
this.messageHandler.send('Cleanup', null, this.messageHandler.sendWithPromise('Cleanup', null).
function endCleanup() { then(function endCleanup() {
for (var i = 0, ii = this.pageCache.length; i < ii; i++) { for (var i = 0, ii = this.pageCache.length; i < ii; i++) {
var page = this.pageCache[i]; var page = this.pageCache[i];
if (page) { if (page) {
page.destroy(); page.destroy();
}
} }
this.commonObjs.clear(); }
FontLoader.clear(); this.commonObjs.clear();
}.bind(this) FontLoader.clear();
); }.bind(this));
} }
}; };
return WorkerTransport; return WorkerTransport;

182
build/pdf.worker.js vendored

@ -21,8 +21,8 @@ if (typeof PDFJS === 'undefined') {
(typeof window !== 'undefined' ? window : this).PDFJS = {}; (typeof window !== 'undefined' ? window : this).PDFJS = {};
} }
PDFJS.version = '1.0.194'; PDFJS.version = '1.0.197';
PDFJS.build = '36c6bc2'; PDFJS.build = '44cd0f4';
(function pdfjsWrapper() { (function pdfjsWrapper() {
// Use strict in our context only - users might not want it // Use strict in our context only - users might not want it
@ -1439,7 +1439,7 @@ function MessageHandler(name, comObj) {
this.comObj = comObj; this.comObj = comObj;
this.callbackIndex = 1; this.callbackIndex = 1;
this.postMessageTransfers = true; this.postMessageTransfers = true;
var callbacks = this.callbacks = {}; var callbacksCapabilities = this.callbacksCapabilities = {};
var ah = this.actionHandler = {}; var ah = this.actionHandler = {};
ah['console_log'] = [function ahConsoleLog(data) { ah['console_log'] = [function ahConsoleLog(data) {
@ -1456,35 +1456,40 @@ function MessageHandler(name, comObj) {
var data = event.data; var data = event.data;
if (data.isReply) { if (data.isReply) {
var callbackId = data.callbackId; var callbackId = data.callbackId;
if (data.callbackId in callbacks) { if (data.callbackId in callbacksCapabilities) {
var callback = callbacks[callbackId]; var callback = callbacksCapabilities[callbackId];
delete callbacks[callbackId]; delete callbacksCapabilities[callbackId];
callback(data.data); if ('error' in data) {
callback.reject(data.error);
} else {
callback.resolve(data.data);
}
} else { } else {
error('Cannot resolve callback ' + callbackId); error('Cannot resolve callback ' + callbackId);
} }
} else if (data.action in ah) { } else if (data.action in ah) {
var action = ah[data.action]; var action = ah[data.action];
if (data.callbackId) { if (data.callbackId) {
var deferred = {}; Promise.resolve().then(function () {
var promise = new Promise(function (resolve, reject) { return action[0].call(action[1], data.data);
deferred.resolve = resolve; }).then(function (result) {
deferred.reject = reject; comObj.postMessage({
}); isReply: true,
deferred.promise = promise; callbackId: data.callbackId,
promise.then(function(resolvedData) { data: result
});
}, function (reason) {
comObj.postMessage({ comObj.postMessage({
isReply: true, isReply: true,
callbackId: data.callbackId, callbackId: data.callbackId,
data: resolvedData error: reason
}); });
}); });
action[0].call(action[1], data.data, deferred);
} else { } else {
action[0].call(action[1], data.data); action[0].call(action[1], data.data);
} }
} else { } else {
error('Unkown action from worker: ' + data.action); error('Unknown action from worker: ' + data.action);
} }
}; };
} }
@ -1501,19 +1506,47 @@ MessageHandler.prototype = {
* Sends a message to the comObj to invoke the action with the supplied data. * Sends a message to the comObj to invoke the action with the supplied data.
* @param {String} actionName Action to call. * @param {String} actionName Action to call.
* @param {JSON} data JSON data to send. * @param {JSON} data JSON data to send.
* @param {function} [callback] Optional callback that will handle a reply.
* @param {Array} [transfers] Optional list of transfers/ArrayBuffers * @param {Array} [transfers] Optional list of transfers/ArrayBuffers
*/ */
send: function messageHandlerSend(actionName, data, callback, transfers) { send: function messageHandlerSend(actionName, data, transfers) {
var message = { var message = {
action: actionName, action: actionName,
data: data data: data
}; };
if (callback) { this.postMessage(message, transfers);
var callbackId = this.callbackIndex++; },
this.callbacks[callbackId] = callback; /**
message.callbackId = callbackId; * Sends a message to the comObj to invoke the action with the supplied data.
* Expects that other side will callback with the response.
* @param {String} actionName Action to call.
* @param {JSON} data JSON data to send.
* @param {Array} [transfers] Optional list of transfers/ArrayBuffers.
* @returns {Promise} Promise to be resolved with response data.
*/
sendWithPromise:
function messageHandlerSendWithPromise(actionName, data, transfers) {
var callbackId = this.callbackIndex++;
var message = {
action: actionName,
data: data,
callbackId: callbackId
};
var capability = createPromiseCapability();
this.callbacksCapabilities[callbackId] = capability;
try {
this.postMessage(message, transfers);
} catch (e) {
capability.reject(e);
} }
return capability.promise;
},
/**
* Sends raw message to the comObj.
* @private
* @param message {Object} Raw message.
* @param transfers List of transfers/ArrayBuffers, or undefined.
*/
postMessage: function (message, transfers) {
if (transfers && this.postMessageTransfers) { if (transfers && this.postMessageTransfers) {
this.comObj.postMessage(message, transfers); this.comObj.postMessage(message, transfers);
} else { } else {
@ -15644,7 +15677,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
then(function(imageObj) { then(function(imageObj) {
var imgData = imageObj.createImageData(/* forceRGBA = */ false); var imgData = imageObj.createImageData(/* forceRGBA = */ false);
self.handler.send('obj', [objId, self.pageIndex, 'Image', imgData], self.handler.send('obj', [objId, self.pageIndex, 'Image', imgData],
null, [imgData.data.buffer]); [imgData.data.buffer]);
}).then(null, function (reason) { }).then(null, function (reason) {
warn('Unable to decode image: ' + reason); warn('Unable to decode image: ' + reason);
self.handler.send('obj', [objId, self.pageIndex, 'Image', null]); self.handler.send('obj', [objId, self.pageIndex, 'Image', null]);
@ -17042,7 +17075,7 @@ var OperatorList = (function OperatorListClosure() {
}, },
pageIndex: this.pageIndex, pageIndex: this.pageIndex,
intent: this.intent intent: this.intent
}, null, transfers); }, transfers);
this.dependencies = {}; this.dependencies = {};
this.fnArray.length = 0; this.fnArray.length = 0;
this.argsArray.length = 0; this.argsArray.length = 0;
@ -30383,14 +30416,11 @@ var PDFImage = (function PDFImageClosure() {
var colorSpace = dict.get('ColorSpace', 'CS'); var colorSpace = dict.get('ColorSpace', 'CS');
colorSpace = ColorSpace.parse(colorSpace, xref, res); colorSpace = ColorSpace.parse(colorSpace, xref, res);
var numComps = colorSpace.numComps; var numComps = colorSpace.numComps;
var resolvePromise; var decodePromise = handler.sendWithPromise('JpegDecode',
handler.send('JpegDecode', [image.getIR(), numComps], function(message) { [image.getIR(), numComps]);
return decodePromise.then(function (message) {
var data = message.data; var data = message.data;
var stream = new Stream(data, 0, data.length, image.dict); return new Stream(data, 0, data.length, image.dict);
resolvePromise(stream);
});
return new Promise(function (resolve) {
resolvePromise = resolve;
}); });
} else { } else {
return Promise.resolve(image); return Promise.resolve(image);
@ -37619,81 +37649,64 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
}, onFailure); }, onFailure);
}); });
handler.on('GetPageRequest', function wphSetupGetPage(data) { handler.on('GetPage', function wphSetupGetPage(data) {
var pageIndex = data.pageIndex; return pdfManager.getPage(data.pageIndex).then(function(page) {
pdfManager.getPage(pageIndex).then(function(page) {
var rotatePromise = pdfManager.ensure(page, 'rotate'); var rotatePromise = pdfManager.ensure(page, 'rotate');
var refPromise = pdfManager.ensure(page, 'ref'); var refPromise = pdfManager.ensure(page, 'ref');
var viewPromise = pdfManager.ensure(page, 'view'); var viewPromise = pdfManager.ensure(page, 'view');
Promise.all([rotatePromise, refPromise, viewPromise]).then( return Promise.all([rotatePromise, refPromise, viewPromise]).then(
function(results) { function(results) {
var page = { return {
pageIndex: data.pageIndex,
rotate: results[0], rotate: results[0],
ref: results[1], ref: results[1],
view: results[2] view: results[2]
}; };
handler.send('GetPage', { pageInfo: page });
}); });
}); });
}); });
handler.on('GetPageIndex', function wphSetupGetPageIndex(data, deferred) { handler.on('GetPageIndex', function wphSetupGetPageIndex(data) {
var ref = new Ref(data.ref.num, data.ref.gen); var ref = new Ref(data.ref.num, data.ref.gen);
var catalog = pdfManager.pdfDocument.catalog; var catalog = pdfManager.pdfDocument.catalog;
catalog.getPageIndex(ref).then(function (pageIndex) { return catalog.getPageIndex(ref);
deferred.resolve(pageIndex);
}, deferred.reject);
}); });
handler.on('GetDestinations', handler.on('GetDestinations',
function wphSetupGetDestinations(data, deferred) { function wphSetupGetDestinations(data) {
pdfManager.ensureCatalog('destinations').then(function(destinations) { return pdfManager.ensureCatalog('destinations');
deferred.resolve(destinations);
});
} }
); );
handler.on('GetAttachments', handler.on('GetAttachments',
function wphSetupGetAttachments(data, deferred) { function wphSetupGetAttachments(data) {
pdfManager.ensureCatalog('attachments').then(function(attachments) { return pdfManager.ensureCatalog('attachments');
deferred.resolve(attachments);
}, deferred.reject);
} }
); );
handler.on('GetJavaScript', handler.on('GetJavaScript',
function wphSetupGetJavaScript(data, deferred) { function wphSetupGetJavaScript(data) {
pdfManager.ensureCatalog('javaScript').then(function (js) { return pdfManager.ensureCatalog('javaScript');
deferred.resolve(js);
}, deferred.reject);
} }
); );
handler.on('GetOutline', handler.on('GetOutline',
function wphSetupGetOutline(data, deferred) { function wphSetupGetOutline(data) {
pdfManager.ensureCatalog('documentOutline').then(function (outline) { return pdfManager.ensureCatalog('documentOutline');
deferred.resolve(outline);
}, deferred.reject);
} }
); );
handler.on('GetMetadata', handler.on('GetMetadata',
function wphSetupGetMetadata(data, deferred) { function wphSetupGetMetadata(data) {
Promise.all([pdfManager.ensureDoc('documentInfo'), return Promise.all([pdfManager.ensureDoc('documentInfo'),
pdfManager.ensureCatalog('metadata')]).then( pdfManager.ensureCatalog('metadata')]);
function (results) {
deferred.resolve(results);
}, deferred.reject);
} }
); );
handler.on('GetData', function wphSetupGetData(data, deferred) { handler.on('GetData', function wphSetupGetData(data) {
pdfManager.requestLoadedStream(); pdfManager.requestLoadedStream();
pdfManager.onLoadedStream().then(function(stream) { return pdfManager.onLoadedStream().then(function(stream) {
deferred.resolve(stream.bytes); return stream.bytes;
}); });
}); });
@ -37701,16 +37714,9 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
pdfManager.updatePassword(data); pdfManager.updatePassword(data);
}); });
handler.on('GetAnnotationsRequest', function wphSetupGetAnnotations(data) { handler.on('GetAnnotations', function wphSetupGetAnnotations(data) {
pdfManager.getPage(data.pageIndex).then(function(page) { return pdfManager.getPage(data.pageIndex).then(function(page) {
pdfManager.ensure(page, 'getAnnotationsData', []).then( return pdfManager.ensure(page, 'getAnnotationsData', []);
function(annotationsData) {
handler.send('GetAnnotations', {
pageIndex: data.pageIndex,
annotations: annotationsData
});
}
);
}); });
}); });
@ -37759,29 +37765,25 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
}); });
}, this); }, this);
handler.on('GetTextContent', function wphExtractText(data, deferred) { handler.on('GetTextContent', function wphExtractText(data) {
pdfManager.getPage(data.pageIndex).then(function(page) { return pdfManager.getPage(data.pageIndex).then(function(page) {
var pageNum = data.pageIndex + 1; var pageNum = data.pageIndex + 1;
var start = Date.now(); var start = Date.now();
page.extractTextContent().then(function(textContent) { return page.extractTextContent().then(function(textContent) {
deferred.resolve(textContent);
info('text indexing: page=' + pageNum + ' - time=' + info('text indexing: page=' + pageNum + ' - time=' +
(Date.now() - start) + 'ms'); (Date.now() - start) + 'ms');
}, function (e) { return textContent;
// Skip errored pages
deferred.reject(e);
}); });
}); });
}); });
handler.on('Cleanup', function wphCleanup(data, deferred) { handler.on('Cleanup', function wphCleanup(data) {
pdfManager.cleanup(); pdfManager.cleanup();
deferred.resolve(true); return true;
}); });
handler.on('Terminate', function wphTerminate(data, deferred) { handler.on('Terminate', function wphTerminate(data) {
pdfManager.terminate(); pdfManager.terminate();
deferred.resolve();
}); });
} }
}; };

2
package.json

@ -1,6 +1,6 @@
{ {
"name": "pdfjs-dist", "name": "pdfjs-dist",
"version": "1.0.194", "version": "1.0.197",
"description": "Generic build of Mozilla's PDF.js library.", "description": "Generic build of Mozilla's PDF.js library.",
"keywords": [ "keywords": [
"Mozilla", "Mozilla",

Loading…
Cancel
Save