Browse Source

PDF.js version 1.8.351 - See mozilla/pdf.js@63597cc55620d5816c59a673c3fa262bb87483c6

master v1.8.351
pdfjsbot 8 years ago
parent
commit
03b9ab01a1
  1. 2
      bower.json
  2. 12
      build/pdf.combined.js
  3. 2
      build/pdf.combined.js.map
  4. 15
      build/pdf.js
  5. 2
      build/pdf.js.map
  6. 6
      build/pdf.min.js
  7. 4
      build/pdf.worker.js
  8. 2
      build/pdf.worker.js.map
  9. 7
      lib/display/api.js
  10. 4
      lib/display/global.js
  11. 4
      lib/pdf.js
  12. 4
      lib/pdf.worker.js
  13. 227
      lib/test/unit/api_spec.js
  14. 20
      lib/test/unit/test_utils.js
  15. 2
      package.json

2
bower.json

@ -1,6 +1,6 @@
{ {
"name": "pdfjs-dist", "name": "pdfjs-dist",
"version": "1.8.349", "version": "1.8.351",
"main": [ "main": [
"build/pdf.js", "build/pdf.js",
"build/pdf.worker.js" "build/pdf.worker.js"

12
build/pdf.combined.js

@ -12822,8 +12822,8 @@ var _UnsupportedManager = function UnsupportedManagerClosure() {
}(); }();
var version, build; var version, build;
{ {
exports.version = version = '1.8.349'; exports.version = version = '1.8.351';
exports.build = build = '028d3421'; exports.build = build = '63597cc5';
} }
exports.getDocument = getDocument; exports.getDocument = getDocument;
exports.LoopbackPort = LoopbackPort; exports.LoopbackPort = LoopbackPort;
@ -28229,8 +28229,8 @@ if (!_util.globalScope.PDFJS) {
} }
var PDFJS = _util.globalScope.PDFJS; var PDFJS = _util.globalScope.PDFJS;
{ {
PDFJS.version = '1.8.349'; PDFJS.version = '1.8.351';
PDFJS.build = '028d3421'; PDFJS.build = '63597cc5';
} }
PDFJS.pdfBug = false; PDFJS.pdfBug = false;
if (PDFJS.verbosity !== undefined) { if (PDFJS.verbosity !== undefined) {
@ -43816,8 +43816,8 @@ exports.TilingPattern = TilingPattern;
"use strict"; "use strict";
var pdfjsVersion = '1.8.349'; var pdfjsVersion = '1.8.351';
var pdfjsBuild = '028d3421'; var pdfjsBuild = '63597cc5';
var pdfjsSharedUtil = __w_pdfjs_require__(0); var pdfjsSharedUtil = __w_pdfjs_require__(0);
var pdfjsDisplayGlobal = __w_pdfjs_require__(26); var pdfjsDisplayGlobal = __w_pdfjs_require__(26);
var pdfjsDisplayAPI = __w_pdfjs_require__(10); var pdfjsDisplayAPI = __w_pdfjs_require__(10);

2
build/pdf.combined.js.map

File diff suppressed because one or more lines are too long

15
build/pdf.js

@ -2175,7 +2175,8 @@ if (typeof __pdfjsdev_webpack__ === 'undefined') {
var dynamicLoaderSupported = typeof requirejs !== 'undefined' && requirejs.load; var dynamicLoaderSupported = typeof requirejs !== 'undefined' && requirejs.load;
fakeWorkerFilesLoader = useRequireEnsure ? function (callback) { fakeWorkerFilesLoader = useRequireEnsure ? function (callback) {
require.ensure([], function () { require.ensure([], function () {
var worker = require('./pdf.worker.js'); var worker;
worker = require('./pdf.worker.js');
callback(worker.WorkerMessageHandler); callback(worker.WorkerMessageHandler);
}); });
} : dynamicLoaderSupported ? function (callback) { } : dynamicLoaderSupported ? function (callback) {
@ -3529,8 +3530,8 @@ var _UnsupportedManager = function UnsupportedManagerClosure() {
}(); }();
var version, build; var version, build;
{ {
exports.version = version = '1.8.349'; exports.version = version = '1.8.351';
exports.build = build = '028d3421'; exports.build = build = '63597cc5';
} }
exports.getDocument = getDocument; exports.getDocument = getDocument;
exports.LoopbackPort = LoopbackPort; exports.LoopbackPort = LoopbackPort;
@ -5503,8 +5504,8 @@ if (!_util.globalScope.PDFJS) {
} }
var PDFJS = _util.globalScope.PDFJS; var PDFJS = _util.globalScope.PDFJS;
{ {
PDFJS.version = '1.8.349'; PDFJS.version = '1.8.351';
PDFJS.build = '028d3421'; PDFJS.build = '63597cc5';
} }
PDFJS.pdfBug = false; PDFJS.pdfBug = false;
if (PDFJS.verbosity !== undefined) { if (PDFJS.verbosity !== undefined) {
@ -7999,8 +8000,8 @@ exports.TilingPattern = TilingPattern;
"use strict"; "use strict";
var pdfjsVersion = '1.8.349'; var pdfjsVersion = '1.8.351';
var pdfjsBuild = '028d3421'; var pdfjsBuild = '63597cc5';
var pdfjsSharedUtil = __w_pdfjs_require__(0); var pdfjsSharedUtil = __w_pdfjs_require__(0);
var pdfjsDisplayGlobal = __w_pdfjs_require__(9); var pdfjsDisplayGlobal = __w_pdfjs_require__(9);
var pdfjsDisplayAPI = __w_pdfjs_require__(3); var pdfjsDisplayAPI = __w_pdfjs_require__(3);

2
build/pdf.js.map

File diff suppressed because one or more lines are too long

6
build/pdf.min.js vendored

File diff suppressed because one or more lines are too long

4
build/pdf.worker.js vendored

@ -37144,8 +37144,8 @@ exports.Type1Parser = Type1Parser;
"use strict"; "use strict";
var pdfjsVersion = '1.8.349'; var pdfjsVersion = '1.8.351';
var pdfjsBuild = '028d3421'; var pdfjsBuild = '63597cc5';
var pdfjsCoreWorker = __w_pdfjs_require__(8); var pdfjsCoreWorker = __w_pdfjs_require__(8);
{ {
__w_pdfjs_require__(19); __w_pdfjs_require__(19);

2
build/pdf.worker.js.map vendored

File diff suppressed because one or more lines are too long

7
lib/display/api.js

@ -58,7 +58,8 @@ if (typeof __pdfjsdev_webpack__ === 'undefined') {
var dynamicLoaderSupported = typeof requirejs !== 'undefined' && requirejs.load; var dynamicLoaderSupported = typeof requirejs !== 'undefined' && requirejs.load;
fakeWorkerFilesLoader = useRequireEnsure ? function (callback) { fakeWorkerFilesLoader = useRequireEnsure ? function (callback) {
require.ensure([], function () { require.ensure([], function () {
var worker = require('./pdf.worker.js'); var worker;
worker = require('../pdf.worker.js');
callback(worker.WorkerMessageHandler); callback(worker.WorkerMessageHandler);
}); });
} : dynamicLoaderSupported ? function (callback) { } : dynamicLoaderSupported ? function (callback) {
@ -1412,8 +1413,8 @@ var _UnsupportedManager = function UnsupportedManagerClosure() {
}(); }();
var version, build; var version, build;
{ {
exports.version = version = '1.8.349'; exports.version = version = '1.8.351';
exports.build = build = '028d3421'; exports.build = build = '63597cc5';
} }
exports.getDocument = getDocument; exports.getDocument = getDocument;
exports.LoopbackPort = LoopbackPort; exports.LoopbackPort = LoopbackPort;

4
lib/display/global.js

@ -39,8 +39,8 @@ if (!_util.globalScope.PDFJS) {
} }
var PDFJS = _util.globalScope.PDFJS; var PDFJS = _util.globalScope.PDFJS;
{ {
PDFJS.version = '1.8.349'; PDFJS.version = '1.8.351';
PDFJS.build = '028d3421'; PDFJS.build = '63597cc5';
} }
PDFJS.pdfBug = false; PDFJS.pdfBug = false;
if (PDFJS.verbosity !== undefined) { if (PDFJS.verbosity !== undefined) {

4
lib/pdf.js

@ -14,8 +14,8 @@
*/ */
'use strict'; 'use strict';
var pdfjsVersion = '1.8.349'; var pdfjsVersion = '1.8.351';
var pdfjsBuild = '028d3421'; var pdfjsBuild = '63597cc5';
var pdfjsSharedUtil = require('./shared/util.js'); var pdfjsSharedUtil = require('./shared/util.js');
var pdfjsDisplayGlobal = require('./display/global.js'); var pdfjsDisplayGlobal = require('./display/global.js');
var pdfjsDisplayAPI = require('./display/api.js'); var pdfjsDisplayAPI = require('./display/api.js');

4
lib/pdf.worker.js vendored

@ -14,8 +14,8 @@
*/ */
'use strict'; 'use strict';
var pdfjsVersion = '1.8.349'; var pdfjsVersion = '1.8.351';
var pdfjsBuild = '028d3421'; var pdfjsBuild = '63597cc5';
var pdfjsCoreWorker = require('./core/worker.js'); var pdfjsCoreWorker = require('./core/worker.js');
{ {
require('./core/network.js'); require('./core/network.js');

227
lib/test/unit/api_spec.js

@ -22,18 +22,42 @@ var _dom_utils = require('../../display/dom_utils');
var _api = require('../../display/api'); var _api = require('../../display/api');
var _test_utils = require('./test_utils');
var _global = require('../../display/global'); var _global = require('../../display/global');
var TEST_PDFS_PATH = {
dom: '../pdfs/',
node: './test/pdfs/'
};
function buildGetDocumentParams(filename, options) {
var params = Object.create(null);
if ((0, _util.isNodeJS)()) {
params.data = _test_utils.NodeFileReaderFactory.fetch({ path: TEST_PDFS_PATH.node + filename });
} else {
params.url = new URL(TEST_PDFS_PATH.dom + filename, window.location).href;
}
for (var option in options) {
params[option] = options[option];
}
return params;
}
describe('api', function () { describe('api', function () {
var basicApiUrl = new URL('../pdfs/basicapi.pdf', window.location).href; var basicApiFileName = 'basicapi.pdf';
var basicApiFileLength = 105779; var basicApiFileLength = 105779;
var CanvasFactory; var basicApiGetDocumentParams = buildGetDocumentParams(basicApiFileName);
var CanvasFactory = void 0;
beforeAll(function (done) { beforeAll(function (done) {
CanvasFactory = new _dom_utils.DOMCanvasFactory(); if ((0, _util.isNodeJS)()) {
_global.PDFJS.pdfjsNext = true;
} else {
CanvasFactory = new _dom_utils.DOMCanvasFactory();
}
done(); done();
}); });
afterAll(function () { afterAll(function (done) {
CanvasFactory = null; CanvasFactory = null;
done();
}); });
function waitSome(callback) { function waitSome(callback) {
var WAIT_TIMEOUT = 10; var WAIT_TIMEOUT = 10;
@ -44,7 +68,10 @@ describe('api', function () {
describe('PDFJS', function () { describe('PDFJS', function () {
describe('getDocument', function () { describe('getDocument', function () {
it('creates pdf doc from URL', function (done) { it('creates pdf doc from URL', function (done) {
var loadingTask = _global.PDFJS.getDocument(basicApiUrl); if ((0, _util.isNodeJS)()) {
pending('XMLHttpRequest is not supported in Node.js.');
}
var loadingTask = (0, _api.getDocument)(basicApiGetDocumentParams);
var isProgressReportedResolved = false; var isProgressReportedResolved = false;
var progressReportedCapability = (0, _util.createPromiseCapability)(); var progressReportedCapability = (0, _util.createPromiseCapability)();
loadingTask.onProgress = function (progressData) { loadingTask.onProgress = function (progressData) {
@ -64,7 +91,10 @@ describe('api', function () {
}); });
}); });
it('creates pdf doc from URL and aborts before worker initialized', function (done) { it('creates pdf doc from URL and aborts before worker initialized', function (done) {
var loadingTask = _global.PDFJS.getDocument(basicApiUrl); if ((0, _util.isNodeJS)()) {
pending('XMLHttpRequest is not supported in Node.js.');
}
var loadingTask = (0, _api.getDocument)(basicApiGetDocumentParams);
var destroyed = loadingTask.destroy(); var destroyed = loadingTask.destroy();
loadingTask.promise.then(function (reason) { loadingTask.promise.then(function (reason) {
done.fail('shall fail loading'); done.fail('shall fail loading');
@ -74,7 +104,10 @@ describe('api', function () {
}); });
}); });
it('creates pdf doc from URL and aborts loading after worker initialized', function (done) { it('creates pdf doc from URL and aborts loading after worker initialized', function (done) {
var loadingTask = _global.PDFJS.getDocument(basicApiUrl); if ((0, _util.isNodeJS)()) {
pending('XMLHttpRequest is not supported in Node.js.');
}
var loadingTask = (0, _api.getDocument)(basicApiGetDocumentParams);
var destroyed = loadingTask._worker.promise.then(function () { var destroyed = loadingTask._worker.promise.then(function () {
return loadingTask.destroy(); return loadingTask.destroy();
}); });
@ -86,32 +119,33 @@ describe('api', function () {
}); });
}); });
it('creates pdf doc from typed array', function (done) { it('creates pdf doc from typed array', function (done) {
var nonBinaryRequest = _global.PDFJS.disableWorker;
var request = new XMLHttpRequest();
request.open('GET', basicApiUrl, false);
if (!nonBinaryRequest) {
try {
request.responseType = 'arraybuffer';
nonBinaryRequest = request.responseType !== 'arraybuffer';
} catch (e) {
nonBinaryRequest = true;
}
}
if (nonBinaryRequest && request.overrideMimeType) {
request.overrideMimeType('text/plain; charset=x-user-defined');
}
request.send(null);
var typedArrayPdf; var typedArrayPdf;
if (nonBinaryRequest) { if ((0, _util.isNodeJS)()) {
var data = Array.prototype.map.call(request.responseText, function (ch) { typedArrayPdf = _test_utils.NodeFileReaderFactory.fetch({ path: TEST_PDFS_PATH.node + basicApiFileName });
return ch.charCodeAt(0) & 0xFF;
});
typedArrayPdf = new Uint8Array(data);
} else { } else {
typedArrayPdf = new Uint8Array(request.response); var nonBinaryRequest = _global.PDFJS.disableWorker;
var request = new XMLHttpRequest();
request.open('GET', TEST_PDFS_PATH.dom + basicApiFileName, false);
if (!nonBinaryRequest) {
try {
request.responseType = 'arraybuffer';
nonBinaryRequest = request.responseType !== 'arraybuffer';
} catch (e) {
nonBinaryRequest = true;
}
}
if (nonBinaryRequest && request.overrideMimeType) {
request.overrideMimeType('text/plain; charset=x-user-defined');
}
request.send(null);
if (nonBinaryRequest) {
typedArrayPdf = (0, _util.stringToBytes)(request.responseText);
} else {
typedArrayPdf = new Uint8Array(request.response);
}
} }
expect(typedArrayPdf.length).toEqual(basicApiFileLength); expect(typedArrayPdf.length).toEqual(basicApiFileLength);
var loadingTask = _global.PDFJS.getDocument(typedArrayPdf); var loadingTask = (0, _api.getDocument)(typedArrayPdf);
loadingTask.promise.then(function (data) { loadingTask.promise.then(function (data) {
expect(data instanceof _api.PDFDocumentProxy).toEqual(true); expect(data instanceof _api.PDFDocumentProxy).toEqual(true);
loadingTask.destroy().then(done); loadingTask.destroy().then(done);
@ -120,8 +154,7 @@ describe('api', function () {
}); });
}); });
it('creates pdf doc from invalid PDF file', function (done) { it('creates pdf doc from invalid PDF file', function (done) {
var url = new URL('../pdfs/bug1020226.pdf', window.location).href; var loadingTask = (0, _api.getDocument)(buildGetDocumentParams('bug1020226.pdf'));
var loadingTask = _global.PDFJS.getDocument(url);
loadingTask.promise.then(function () { loadingTask.promise.then(function () {
done.fail('shall fail loading'); done.fail('shall fail loading');
}).catch(function (error) { }).catch(function (error) {
@ -130,8 +163,10 @@ describe('api', function () {
}); });
}); });
it('creates pdf doc from non-existent URL', function (done) { it('creates pdf doc from non-existent URL', function (done) {
var nonExistentUrl = new URL('../pdfs/non-existent.pdf', window.location).href; if ((0, _util.isNodeJS)()) {
var loadingTask = _global.PDFJS.getDocument(nonExistentUrl); pending('XMLHttpRequest is not supported in Node.js.');
}
var loadingTask = (0, _api.getDocument)(buildGetDocumentParams('non-existent.pdf'));
loadingTask.promise.then(function (error) { loadingTask.promise.then(function (error) {
done.fail('shall fail loading'); done.fail('shall fail loading');
}).catch(function (error) { }).catch(function (error) {
@ -140,8 +175,7 @@ describe('api', function () {
}); });
}); });
it('creates pdf doc from PDF file protected with user and owner password', function (done) { it('creates pdf doc from PDF file protected with user and owner password', function (done) {
var url = new URL('../pdfs/pr6531_1.pdf', window.location).href; var loadingTask = (0, _api.getDocument)(buildGetDocumentParams('pr6531_1.pdf'));
var loadingTask = _global.PDFJS.getDocument(url);
var isPasswordNeededResolved = false; var isPasswordNeededResolved = false;
var passwordNeededCapability = (0, _util.createPromiseCapability)(); var passwordNeededCapability = (0, _util.createPromiseCapability)();
var isPasswordIncorrectResolved = false; var isPasswordIncorrectResolved = false;
@ -170,11 +204,8 @@ describe('api', function () {
}); });
}); });
it('creates pdf doc from PDF file protected with only a user password', function (done) { it('creates pdf doc from PDF file protected with only a user password', function (done) {
var url = new URL('../pdfs/pr6531_2.pdf', window.location).href; var filename = 'pr6531_2.pdf';
var passwordNeededLoadingTask = _global.PDFJS.getDocument({ var passwordNeededLoadingTask = (0, _api.getDocument)(buildGetDocumentParams(filename, { password: '' }));
url: url,
password: ''
});
var result1 = passwordNeededLoadingTask.promise.then(function () { var result1 = passwordNeededLoadingTask.promise.then(function () {
done.fail('shall fail with no password'); done.fail('shall fail with no password');
return Promise.reject(new Error('loadingTask should be rejected')); return Promise.reject(new Error('loadingTask should be rejected'));
@ -183,10 +214,7 @@ describe('api', function () {
expect(data.code).toEqual(_util.PasswordResponses.NEED_PASSWORD); expect(data.code).toEqual(_util.PasswordResponses.NEED_PASSWORD);
return passwordNeededLoadingTask.destroy(); return passwordNeededLoadingTask.destroy();
}); });
var passwordIncorrectLoadingTask = _global.PDFJS.getDocument({ var passwordIncorrectLoadingTask = (0, _api.getDocument)(buildGetDocumentParams(filename, { password: 'qwerty' }));
url: url,
password: 'qwerty'
});
var result2 = passwordIncorrectLoadingTask.promise.then(function () { var result2 = passwordIncorrectLoadingTask.promise.then(function () {
done.fail('shall fail with wrong password'); done.fail('shall fail with wrong password');
return Promise.reject(new Error('loadingTask should be rejected')); return Promise.reject(new Error('loadingTask should be rejected'));
@ -195,10 +223,7 @@ describe('api', function () {
expect(data.code).toEqual(_util.PasswordResponses.INCORRECT_PASSWORD); expect(data.code).toEqual(_util.PasswordResponses.INCORRECT_PASSWORD);
return passwordIncorrectLoadingTask.destroy(); return passwordIncorrectLoadingTask.destroy();
}); });
var passwordAcceptedLoadingTask = _global.PDFJS.getDocument({ var passwordAcceptedLoadingTask = (0, _api.getDocument)(buildGetDocumentParams(filename, { password: 'asdfasdf' }));
url: url,
password: 'asdfasdf'
});
var result3 = passwordAcceptedLoadingTask.promise.then(function (data) { var result3 = passwordAcceptedLoadingTask.promise.then(function (data) {
expect(data instanceof _api.PDFDocumentProxy).toEqual(true); expect(data instanceof _api.PDFDocumentProxy).toEqual(true);
return passwordAcceptedLoadingTask.destroy(); return passwordAcceptedLoadingTask.destroy();
@ -210,12 +235,9 @@ describe('api', function () {
}); });
}); });
it('creates pdf doc from password protected PDF file and aborts/throws ' + 'in the onPassword callback (issue 7806)', function (done) { it('creates pdf doc from password protected PDF file and aborts/throws ' + 'in the onPassword callback (issue 7806)', function (done) {
var url = new URL('../pdfs/issue3371.pdf', window.location).href; var filename = 'issue3371.pdf';
var passwordNeededLoadingTask = _global.PDFJS.getDocument(url); var passwordNeededLoadingTask = (0, _api.getDocument)(buildGetDocumentParams(filename));
var passwordIncorrectLoadingTask = _global.PDFJS.getDocument({ var passwordIncorrectLoadingTask = (0, _api.getDocument)(buildGetDocumentParams(filename, { password: 'qwerty' }));
url: url,
password: 'qwerty'
});
var passwordNeededDestroyed = void 0; var passwordNeededDestroyed = void 0;
passwordNeededLoadingTask.onPassword = function (callback, reason) { passwordNeededLoadingTask.onPassword = function (callback, reason) {
if (reason === _util.PasswordResponses.NEED_PASSWORD) { if (reason === _util.PasswordResponses.NEED_PASSWORD) {
@ -255,6 +277,9 @@ describe('api', function () {
}); });
}); });
describe('PDFWorker', function () { describe('PDFWorker', function () {
if ((0, _util.isNodeJS)()) {
pending('Worker is not supported in Node.js.');
}
it('worker created or destroyed', function (done) { it('worker created or destroyed', function (done) {
var worker = new _global.PDFJS.PDFWorker('test1'); var worker = new _global.PDFJS.PDFWorker('test1');
worker.promise.then(function () { worker.promise.then(function () {
@ -272,7 +297,7 @@ describe('api', function () {
}); });
}); });
it('worker created or destroyed by getDocument', function (done) { it('worker created or destroyed by getDocument', function (done) {
var loadingTask = _global.PDFJS.getDocument(basicApiUrl); var loadingTask = (0, _api.getDocument)(basicApiGetDocumentParams);
var worker; var worker;
loadingTask.promise.then(function () { loadingTask.promise.then(function () {
worker = loadingTask._worker; worker = loadingTask._worker;
@ -292,10 +317,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 _global.PDFJS.PDFWorker('test1'); var worker = new _global.PDFJS.PDFWorker('test1');
var loadingTask = _global.PDFJS.getDocument({ var loadingTask = (0, _api.getDocument)(buildGetDocumentParams(basicApiFileName, { worker: worker }));
url: basicApiUrl,
worker: worker
});
loadingTask.promise.then(function () { loadingTask.promise.then(function () {
var docWorker = loadingTask._worker; var docWorker = loadingTask._worker;
expect(!!docWorker).toEqual(false); expect(!!docWorker).toEqual(false);
@ -333,7 +355,7 @@ describe('api', function () {
var loadingTask; var loadingTask;
var doc; var doc;
beforeAll(function (done) { beforeAll(function (done) {
loadingTask = _global.PDFJS.getDocument(basicApiUrl); loadingTask = (0, _api.getDocument)(basicApiGetDocumentParams);
loadingTask.promise.then(function (data) { loadingTask.promise.then(function (data) {
doc = data; doc = data;
done(); done();
@ -447,8 +469,7 @@ describe('api', function () {
}); });
}); });
it('gets destinations, from /Names (NameTree) dictionary', function (done) { it('gets destinations, from /Names (NameTree) dictionary', function (done) {
var url = new URL('../pdfs/issue6204.pdf', window.location).href; var loadingTask = (0, _api.getDocument)(buildGetDocumentParams('issue6204.pdf'));
var loadingTask = _global.PDFJS.getDocument(url);
var promise = loadingTask.promise.then(function (pdfDocument) { var promise = loadingTask.promise.then(function (pdfDocument) {
return pdfDocument.getDestinations(); return pdfDocument.getDestinations();
}); });
@ -469,8 +490,7 @@ describe('api', function () {
}); });
}); });
it('gets a destination, from /Names (NameTree) dictionary', function (done) { it('gets a destination, from /Names (NameTree) dictionary', function (done) {
var url = new URL('../pdfs/issue6204.pdf', window.location).href; var loadingTask = (0, _api.getDocument)(buildGetDocumentParams('issue6204.pdf'));
var loadingTask = _global.PDFJS.getDocument(url);
var promise = loadingTask.promise.then(function (pdfDocument) { var promise = loadingTask.promise.then(function (pdfDocument) {
return pdfDocument.getDestination('Page.1'); return pdfDocument.getDestination('Page.1');
}); });
@ -485,8 +505,7 @@ describe('api', function () {
}); });
}); });
it('gets a non-existent destination, from /Names (NameTree) dictionary', function (done) { it('gets a non-existent destination, from /Names (NameTree) dictionary', function (done) {
var url = new URL('../pdfs/issue6204.pdf', window.location).href; var loadingTask = (0, _api.getDocument)(buildGetDocumentParams('issue6204.pdf'));
var loadingTask = _global.PDFJS.getDocument(url);
var promise = loadingTask.promise.then(function (pdfDocument) { var promise = loadingTask.promise.then(function (pdfDocument) {
return pdfDocument.getDestination('non-existent-named-destination'); return pdfDocument.getDestination('non-existent-named-destination');
}); });
@ -507,23 +526,19 @@ describe('api', function () {
}); });
}); });
it('gets page labels', function (done) { it('gets page labels', function (done) {
var url0 = new URL('../pdfs/bug793632.pdf', window.location).href; var loadingTask0 = (0, _api.getDocument)(buildGetDocumentParams('bug793632.pdf'));
var loadingTask0 = _global.PDFJS.getDocument(url0);
var promise0 = loadingTask0.promise.then(function (pdfDoc) { var promise0 = loadingTask0.promise.then(function (pdfDoc) {
return pdfDoc.getPageLabels(); return pdfDoc.getPageLabels();
}); });
var url1 = new URL('../pdfs/issue1453.pdf', window.location).href; var loadingTask1 = (0, _api.getDocument)(buildGetDocumentParams('issue1453.pdf'));
var loadingTask1 = _global.PDFJS.getDocument(url1);
var promise1 = loadingTask1.promise.then(function (pdfDoc) { var promise1 = loadingTask1.promise.then(function (pdfDoc) {
return pdfDoc.getPageLabels(); return pdfDoc.getPageLabels();
}); });
var url2 = new URL('../pdfs/rotation.pdf', window.location).href; var loadingTask2 = (0, _api.getDocument)(buildGetDocumentParams('rotation.pdf'));
var loadingTask2 = _global.PDFJS.getDocument(url2);
var promise2 = loadingTask2.promise.then(function (pdfDoc) { var promise2 = loadingTask2.promise.then(function (pdfDoc) {
return pdfDoc.getPageLabels(); return pdfDoc.getPageLabels();
}); });
var url3 = new URL('../pdfs/bad-PageLabels.pdf', window.location).href; var loadingTask3 = (0, _api.getDocument)(buildGetDocumentParams('bad-PageLabels.pdf'));
var loadingTask3 = _global.PDFJS.getDocument(url3);
var promise3 = loadingTask3.promise.then(function (pdfDoc) { var promise3 = loadingTask3.promise.then(function (pdfDoc) {
return pdfDoc.getPageLabels(); return pdfDoc.getPageLabels();
}); });
@ -547,8 +562,10 @@ describe('api', function () {
}); });
}); });
it('gets attachments', function (done) { it('gets attachments', function (done) {
var url = new URL('../pdfs/bug766138.pdf', window.location).href; if ((0, _util.isNodeJS)()) {
var loadingTask = _global.PDFJS.getDocument(url); pending('TODO: Use a non-linked test-case.');
}
var loadingTask = (0, _api.getDocument)(buildGetDocumentParams('bug766138.pdf'));
var promise = loadingTask.promise.then(function (pdfDoc) { var promise = loadingTask.promise.then(function (pdfDoc) {
return pdfDoc.getAttachments(); return pdfDoc.getAttachments();
}); });
@ -573,8 +590,7 @@ describe('api', function () {
}); });
var viewerPrintRegExp = /\bprint\s*\(/; var viewerPrintRegExp = /\bprint\s*\(/;
it('gets javascript with printing instructions (Print action)', function (done) { it('gets javascript with printing instructions (Print action)', function (done) {
var pdfUrl = new URL('../pdfs/bug1001080.pdf', window.location).href; var loadingTask = (0, _api.getDocument)(buildGetDocumentParams('bug1001080.pdf'));
var loadingTask = _global.PDFJS.getDocument(pdfUrl);
var promise = loadingTask.promise.then(function (doc) { var promise = loadingTask.promise.then(function (doc) {
return doc.getJavaScript(); return doc.getJavaScript();
}); });
@ -587,8 +603,7 @@ describe('api', function () {
}); });
}); });
it('gets javascript with printing instructions (JS action)', function (done) { it('gets javascript with printing instructions (JS action)', function (done) {
var pdfUrl = new URL('../pdfs/issue6106.pdf', window.location).href; var loadingTask = (0, _api.getDocument)(buildGetDocumentParams('issue6106.pdf'));
var loadingTask = _global.PDFJS.getDocument(pdfUrl);
var promise = loadingTask.promise.then(function (doc) { var promise = loadingTask.promise.then(function (doc) {
return doc.getJavaScript(); return doc.getJavaScript();
}); });
@ -601,8 +616,7 @@ describe('api', function () {
}); });
}); });
it('gets non-existent outline', function (done) { it('gets non-existent outline', function (done) {
var url = new URL('../pdfs/tracemonkey.pdf', window.location).href; var loadingTask = (0, _api.getDocument)(buildGetDocumentParams('tracemonkey.pdf'));
var loadingTask = _global.PDFJS.getDocument(url);
var promise = loadingTask.promise.then(function (pdfDocument) { var promise = loadingTask.promise.then(function (pdfDocument) {
return pdfDocument.getOutline(); return pdfDocument.getOutline();
}); });
@ -635,8 +649,7 @@ describe('api', function () {
}); });
}); });
it('gets outline containing a url', function (done) { it('gets outline containing a url', function (done) {
var pdfUrl = new URL('../pdfs/issue3214.pdf', window.location).href; var loadingTask = (0, _api.getDocument)(buildGetDocumentParams('issue3214.pdf'));
var loadingTask = _global.PDFJS.getDocument(pdfUrl);
loadingTask.promise.then(function (pdfDocument) { loadingTask.promise.then(function (pdfDocument) {
pdfDocument.getOutline().then(function (outline) { pdfDocument.getOutline().then(function (outline) {
expect(outline instanceof Array).toEqual(true); expect(outline instanceof Array).toEqual(true);
@ -658,6 +671,9 @@ describe('api', function () {
}); });
}); });
it('gets metadata', function (done) { it('gets metadata', function (done) {
if ((0, _util.isNodeJS)()) {
pending('Document is not supported in Node.js.');
}
var promise = doc.getMetadata(); var promise = doc.getMetadata();
promise.then(function (metadata) { promise.then(function (metadata) {
expect(metadata.info['Title']).toEqual('Basic API Test'); expect(metadata.info['Title']).toEqual('Basic API Test');
@ -700,10 +716,8 @@ describe('api', function () {
}); });
}); });
it('checks that fingerprints are unique', function (done) { it('checks that fingerprints are unique', function (done) {
var url1 = new URL('../pdfs/issue4436r.pdf', window.location).href; var loadingTask1 = (0, _api.getDocument)(buildGetDocumentParams('issue4436r.pdf'));
var loadingTask1 = _global.PDFJS.getDocument(url1); var loadingTask2 = (0, _api.getDocument)(buildGetDocumentParams('issue4575.pdf'));
var url2 = new URL('../pdfs/issue4575.pdf', window.location).href;
var loadingTask2 = _global.PDFJS.getDocument(url2);
var promises = [loadingTask1.promise, loadingTask2.promise]; var promises = [loadingTask1.promise, loadingTask2.promise];
Promise.all(promises).then(function (data) { Promise.all(promises).then(function (data) {
var fingerprint1 = data[0].fingerprint; var fingerprint1 = data[0].fingerprint;
@ -723,7 +737,7 @@ describe('api', function () {
var loadingTask; var loadingTask;
var pdfDocument, page; var pdfDocument, page;
beforeAll(function (done) { beforeAll(function (done) {
loadingTask = _global.PDFJS.getDocument(basicApiUrl); loadingTask = (0, _api.getDocument)(basicApiGetDocumentParams);
loadingTask.promise.then(function (doc) { loadingTask.promise.then(function (doc) {
pdfDocument = doc; pdfDocument = doc;
pdfDocument.getPage(1).then(function (data) { pdfDocument.getPage(1).then(function (data) {
@ -781,26 +795,20 @@ describe('api', function () {
}); });
}); });
it('gets annotations containing relative URLs (bug 766086)', function (done) { it('gets annotations containing relative URLs (bug 766086)', function (done) {
var url = new URL('../pdfs/bug766086.pdf', window.location).href; var filename = 'bug766086.pdf';
var defaultLoadingTask = _global.PDFJS.getDocument(url); var defaultLoadingTask = (0, _api.getDocument)(buildGetDocumentParams(filename));
var defaultPromise = defaultLoadingTask.promise.then(function (pdfDoc) { var defaultPromise = defaultLoadingTask.promise.then(function (pdfDoc) {
return pdfDoc.getPage(1).then(function (pdfPage) { return pdfDoc.getPage(1).then(function (pdfPage) {
return pdfPage.getAnnotations(); return pdfPage.getAnnotations();
}); });
}); });
var docBaseUrlLoadingTask = _global.PDFJS.getDocument({ var docBaseUrlLoadingTask = (0, _api.getDocument)(buildGetDocumentParams(filename, { docBaseUrl: 'http://www.example.com/test/pdfs/qwerty.pdf' }));
url: url,
docBaseUrl: 'http://www.example.com/test/pdfs/qwerty.pdf'
});
var docBaseUrlPromise = docBaseUrlLoadingTask.promise.then(function (pdfDoc) { var docBaseUrlPromise = docBaseUrlLoadingTask.promise.then(function (pdfDoc) {
return pdfDoc.getPage(1).then(function (pdfPage) { return pdfDoc.getPage(1).then(function (pdfPage) {
return pdfPage.getAnnotations(); return pdfPage.getAnnotations();
}); });
}); });
var invalidDocBaseUrlLoadingTask = _global.PDFJS.getDocument({ var invalidDocBaseUrlLoadingTask = (0, _api.getDocument)(buildGetDocumentParams(filename, { docBaseUrl: 'qwerty.pdf' }));
url: url,
docBaseUrl: 'qwerty.pdf'
});
var invalidDocBaseUrlPromise = invalidDocBaseUrlLoadingTask.promise.then(function (pdfDoc) { var invalidDocBaseUrlPromise = invalidDocBaseUrlLoadingTask.promise.then(function (pdfDoc) {
return pdfDoc.getPage(1).then(function (pdfPage) { return pdfDoc.getPage(1).then(function (pdfPage) {
return pdfPage.getAnnotations(); return pdfPage.getAnnotations();
@ -869,6 +877,9 @@ describe('api', function () {
}); });
}); });
it('cancels rendering of page', function (done) { it('cancels rendering of page', function (done) {
if ((0, _util.isNodeJS)()) {
pending('TODO: Support Canvas testing in Node.js.');
}
var viewport = page.getViewport(1); var viewport = page.getViewport(1);
var canvasAndCtx = CanvasFactory.create(viewport.width, viewport.height); var canvasAndCtx = CanvasFactory.create(viewport.width, viewport.height);
var renderTask = page.render({ var renderTask = page.render({
@ -887,13 +898,16 @@ describe('api', function () {
}); });
}); });
describe('Multiple PDFJS instances', function () { describe('Multiple PDFJS instances', function () {
var pdf1 = new URL('../pdfs/tracemonkey.pdf', window.location).href; if ((0, _util.isNodeJS)()) {
var pdf2 = new URL('../pdfs/TAMReview.pdf', window.location).href; pending('TODO: Support Canvas testing in Node.js.');
var pdf3 = new URL('../pdfs/issue6068.pdf', window.location).href; }
var pdf1 = buildGetDocumentParams('tracemonkey.pdf');
var pdf2 = buildGetDocumentParams('TAMReview.pdf');
var pdf3 = buildGetDocumentParams('issue6068.pdf');
var loadingTasks = []; var loadingTasks = [];
var pdfDocuments = []; var pdfDocuments = [];
function renderPDF(filename) { function renderPDF(filename) {
var loadingTask = _global.PDFJS.getDocument(filename); var loadingTask = (0, _api.getDocument)(filename);
loadingTasks.push(loadingTask); loadingTasks.push(loadingTask);
return loadingTask.promise.then(function (pdf) { return loadingTask.promise.then(function (pdf) {
pdfDocuments.push(pdf); pdfDocuments.push(pdf);
@ -947,6 +961,9 @@ describe('api', function () {
}); });
}); });
describe('PDFDataRangeTransport', function () { describe('PDFDataRangeTransport', function () {
if ((0, _util.isNodeJS)()) {
pending('XMLHttpRequest is not supported in Node.js.');
}
var pdfPath = new URL('../pdfs/tracemonkey.pdf', window.location).href; var pdfPath = new URL('../pdfs/tracemonkey.pdf', window.location).href;
var loadPromise; var loadPromise;
function getDocumentData() { function getDocumentData() {
@ -981,7 +998,7 @@ describe('api', function () {
transport.onDataRange(begin, data.subarray(begin, end)); transport.onDataRange(begin, data.subarray(begin, end));
}); });
}; };
var loadingTask = _global.PDFJS.getDocument(transport); var loadingTask = (0, _api.getDocument)(transport);
return loadingTask.promise; return loadingTask.promise;
}); });
var pdfDocument; var pdfDocument;
@ -1015,7 +1032,7 @@ describe('api', function () {
transport.onDataRange(begin, data.subarray(begin, end)); transport.onDataRange(begin, data.subarray(begin, end));
}); });
}; };
var loadingTask = _global.PDFJS.getDocument(transport); var loadingTask = (0, _api.getDocument)(transport);
return loadingTask.promise; return loadingTask.promise;
}); });
var pdfDocument; var pdfDocument;

20
lib/test/unit/test_utils.js

@ -17,7 +17,7 @@
Object.defineProperty(exports, "__esModule", { Object.defineProperty(exports, "__esModule", {
value: true value: true
}); });
exports.NodeCMapReaderFactory = undefined; exports.NodeCMapReaderFactory = exports.NodeFileReaderFactory = undefined;
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
@ -25,6 +25,23 @@ var _util = require('../../shared/util');
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var NodeFileReaderFactory = function () {
function NodeFileReaderFactory() {
_classCallCheck(this, NodeFileReaderFactory);
}
_createClass(NodeFileReaderFactory, null, [{
key: 'fetch',
value: function fetch(params) {
var fs = require('fs');
var file = fs.readFileSync(params.path);
return new Uint8Array(file);
}
}]);
return NodeFileReaderFactory;
}();
var NodeCMapReaderFactory = function () { var NodeCMapReaderFactory = function () {
function NodeCMapReaderFactory(_ref) { function NodeCMapReaderFactory(_ref) {
var _ref$baseUrl = _ref.baseUrl, var _ref$baseUrl = _ref.baseUrl,
@ -68,4 +85,5 @@ var NodeCMapReaderFactory = function () {
return NodeCMapReaderFactory; return NodeCMapReaderFactory;
}(); }();
exports.NodeFileReaderFactory = NodeFileReaderFactory;
exports.NodeCMapReaderFactory = NodeCMapReaderFactory; exports.NodeCMapReaderFactory = NodeCMapReaderFactory;

2
package.json

@ -1,6 +1,6 @@
{ {
"name": "pdfjs-dist", "name": "pdfjs-dist",
"version": "1.8.349", "version": "1.8.351",
"main": "build/pdf.js", "main": "build/pdf.js",
"description": "Generic build of Mozilla's PDF.js library.", "description": "Generic build of Mozilla's PDF.js library.",
"keywords": [ "keywords": [

Loading…
Cancel
Save