pdfjs-dist 2.0.487 → 2.1.266
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of pdfjs-dist might be problematic. Click here for more details.
- package/bower.json +1 -1
- package/build/pdf.js +15564 -9476
- package/build/pdf.js.map +1 -1
- package/build/pdf.min.js +1 -1
- package/build/pdf.worker.js +46644 -36309
- package/build/pdf.worker.js.map +1 -1
- package/build/pdf.worker.min.js +1 -1
- package/external/url/url-lib.js +627 -0
- package/image_decoders/pdf.image_decoders.js +11430 -0
- package/image_decoders/pdf.image_decoders.js.map +1 -0
- package/image_decoders/pdf.image_decoders.min.js +1 -0
- package/lib/core/annotation.js +406 -131
- package/lib/core/arithmetic_decoder.js +275 -245
- package/lib/core/bidi.js +65 -6
- package/lib/core/ccitt.js +173 -18
- package/lib/core/ccitt_stream.js +15 -6
- package/lib/core/cff_parser.js +376 -53
- package/lib/core/charsets.js +5 -4
- package/lib/core/chunked_stream.js +387 -149
- package/lib/core/cmap.js +310 -75
- package/lib/core/colorspace.js +874 -594
- package/lib/core/crypto.js +290 -45
- package/lib/core/document.js +545 -260
- package/lib/core/encodings.js +19 -10
- package/lib/core/evaluator.js +725 -147
- package/lib/core/font_renderer.js +360 -91
- package/lib/core/fonts.js +791 -186
- package/lib/core/function.js +284 -71
- package/lib/core/glyphlist.js +3 -2
- package/lib/core/image.js +168 -61
- package/lib/core/jbig2.js +479 -66
- package/lib/core/jbig2_stream.js +19 -8
- package/lib/core/jpeg_stream.js +38 -13
- package/lib/core/jpg.js +252 -29
- package/lib/core/jpx.js +396 -6
- package/lib/core/jpx_stream.js +18 -6
- package/lib/core/metrics.js +4 -4
- package/lib/core/murmurhash3.js +24 -6
- package/lib/core/obj.js +1137 -475
- package/lib/core/operator_list.js +108 -6
- package/lib/core/parser.js +321 -68
- package/lib/core/pattern.js +145 -13
- package/lib/core/pdf_manager.js +321 -133
- package/lib/core/primitives.js +75 -22
- package/lib/core/ps_parser.js +134 -45
- package/lib/core/standard_fonts.js +10 -10
- package/lib/core/stream.js +313 -34
- package/lib/core/type1_parser.js +143 -13
- package/lib/core/unicode.js +31 -4
- package/lib/core/worker.js +210 -66
- package/lib/display/annotation_layer.js +361 -123
- package/lib/display/api.js +1454 -729
- package/lib/display/api_compatibility.js +11 -13
- package/lib/display/canvas.js +324 -29
- package/lib/display/content_disposition.js +83 -32
- package/lib/display/dom_utils.js +226 -41
- package/lib/display/fetch_stream.js +208 -84
- package/lib/display/font_loader.js +465 -236
- package/lib/display/metadata.js +38 -16
- package/lib/display/network.js +216 -51
- package/lib/display/network_utils.js +32 -19
- package/lib/display/node_stream.js +352 -169
- package/lib/display/pattern_helper.js +58 -7
- package/lib/display/svg.js +242 -29
- package/lib/display/text_layer.js +132 -18
- package/lib/display/transport_stream.js +171 -42
- package/lib/display/webgl.js +64 -18
- package/lib/display/worker_options.js +5 -4
- package/lib/display/xml_parser.js +166 -53
- package/lib/examples/node/domstubs.js +57 -4
- package/lib/pdf.js +21 -4
- package/lib/pdf.worker.js +5 -3
- package/lib/shared/compatibility.js +158 -564
- package/lib/shared/global_scope.js +2 -2
- package/lib/shared/is_node.js +4 -4
- package/lib/shared/message_handler.js +521 -0
- package/lib/shared/streams_polyfill.js +21 -17
- package/lib/shared/url_polyfill.js +56 -0
- package/lib/shared/util.js +295 -650
- package/lib/test/unit/annotation_spec.js +629 -345
- package/lib/test/unit/api_spec.js +555 -253
- package/lib/test/unit/bidi_spec.js +7 -7
- package/lib/test/unit/cff_parser_spec.js +40 -11
- package/lib/test/unit/clitests_helper.js +9 -7
- package/lib/test/unit/cmap_spec.js +80 -26
- package/lib/test/unit/colorspace_spec.js +99 -52
- package/lib/test/unit/crypto_spec.js +17 -5
- package/lib/test/unit/custom_spec.js +41 -53
- package/lib/test/unit/display_svg_spec.js +33 -17
- package/lib/test/unit/document_spec.js +3 -3
- package/lib/test/unit/dom_utils_spec.js +9 -9
- package/lib/test/unit/encodings_spec.js +25 -45
- package/lib/test/unit/evaluator_spec.js +34 -9
- package/lib/test/unit/function_spec.js +17 -5
- package/lib/test/unit/jasmine-boot.js +31 -18
- package/lib/test/unit/{util_stream_spec.js → message_handler_spec.js} +41 -69
- package/lib/test/unit/metadata_spec.js +71 -11
- package/lib/test/unit/murmurhash3_spec.js +3 -3
- package/lib/test/unit/network_spec.js +20 -5
- package/lib/test/unit/network_utils_spec.js +41 -14
- package/lib/test/unit/node_stream_spec.js +51 -27
- package/lib/test/unit/parser_spec.js +35 -8
- package/lib/test/unit/pdf_find_controller_spec.js +230 -0
- package/lib/test/unit/pdf_find_utils_spec.js +63 -0
- package/lib/test/unit/pdf_history_spec.js +21 -9
- package/lib/test/unit/primitives_spec.js +24 -4
- package/lib/test/unit/stream_spec.js +12 -4
- package/lib/test/unit/test_utils.js +90 -27
- package/lib/test/unit/testreporter.js +21 -3
- package/lib/test/unit/type1_parser_spec.js +8 -6
- package/lib/test/unit/ui_utils_spec.js +452 -14
- package/lib/test/unit/unicode_spec.js +14 -11
- package/lib/test/unit/util_spec.js +131 -9
- package/lib/web/annotation_layer_builder.js +39 -22
- package/lib/web/app.js +1240 -582
- package/lib/web/app_options.js +71 -41
- package/lib/web/base_viewer.js +508 -179
- package/lib/web/chromecom.js +261 -117
- package/lib/web/debugger.js +166 -22
- package/lib/web/download_manager.js +31 -13
- package/lib/web/firefox_print_service.js +17 -9
- package/lib/web/firefoxcom.js +283 -79
- package/lib/web/genericcom.js +89 -30
- package/lib/web/genericl10n.js +142 -30
- package/lib/web/grab_to_pan.js +26 -4
- package/lib/web/interfaces.js +170 -47
- package/lib/web/overlay_manager.js +235 -85
- package/lib/web/password_prompt.js +21 -13
- package/lib/web/pdf_attachment_viewer.js +38 -18
- package/lib/web/pdf_cursor_tools.js +39 -16
- package/lib/web/pdf_document_properties.js +80 -30
- package/lib/web/pdf_find_bar.js +84 -40
- package/lib/web/pdf_find_controller.js +495 -184
- package/lib/web/pdf_find_utils.js +111 -0
- package/lib/web/pdf_history.js +190 -53
- package/lib/web/pdf_link_service.js +137 -76
- package/lib/web/pdf_outline_viewer.js +73 -22
- package/lib/web/pdf_page_view.js +196 -63
- package/lib/web/pdf_presentation_mode.js +99 -34
- package/lib/web/pdf_print_service.js +57 -11
- package/lib/web/pdf_rendering_queue.js +27 -5
- package/lib/web/pdf_sidebar.js +120 -67
- package/lib/web/pdf_sidebar_resizer.js +42 -16
- package/lib/web/pdf_single_page_viewer.js +74 -66
- package/lib/web/pdf_thumbnail_view.js +103 -32
- package/lib/web/pdf_thumbnail_viewer.js +64 -24
- package/lib/web/pdf_viewer.component.js +112 -32
- package/lib/web/pdf_viewer.js +91 -52
- package/lib/web/preferences.js +275 -80
- package/lib/web/secondary_toolbar.js +165 -40
- package/lib/web/text_layer_builder.js +162 -65
- package/lib/web/toolbar.js +78 -43
- package/lib/web/ui_utils.js +462 -136
- package/lib/web/view_history.js +215 -67
- package/lib/web/viewer_compatibility.js +4 -13
- package/package.json +5 -4
- package/web/pdf_viewer.css +58 -1
- package/web/pdf_viewer.js +6346 -3919
- package/web/pdf_viewer.js.map +1 -1
- package/lib/test/unit/fonts_spec.js +0 -81
- package/lib/web/dom_events.js +0 -137
@@ -2,7 +2,7 @@
|
|
2
2
|
* @licstart The following is the entire license notice for the
|
3
3
|
* Javascript code in this page
|
4
4
|
*
|
5
|
-
* Copyright
|
5
|
+
* Copyright 2018 Mozilla Foundation
|
6
6
|
*
|
7
7
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
8
8
|
* you may not use this file except in compliance with the License.
|
@@ -19,67 +19,84 @@
|
|
19
19
|
* @licend The above is the entire license notice for the
|
20
20
|
* Javascript code in this page
|
21
21
|
*/
|
22
|
-
|
22
|
+
"use strict";
|
23
23
|
|
24
|
-
var
|
24
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
25
25
|
|
26
|
-
var _test_utils = require(
|
26
|
+
var _test_utils = require("./test_utils");
|
27
27
|
|
28
|
-
var _util = require(
|
28
|
+
var _util = require("../../shared/util");
|
29
29
|
|
30
|
-
var _dom_utils = require(
|
30
|
+
var _dom_utils = require("../../display/dom_utils");
|
31
31
|
|
32
|
-
var _api = require(
|
32
|
+
var _api = require("../../display/api");
|
33
33
|
|
34
|
-
var _worker_options = require(
|
34
|
+
var _worker_options = require("../../display/worker_options");
|
35
35
|
|
36
|
-
var _is_node = require(
|
36
|
+
var _is_node = _interopRequireDefault(require("../../shared/is_node"));
|
37
37
|
|
38
|
-
var
|
38
|
+
var _metadata = require("../../display/metadata");
|
39
39
|
|
40
40
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
41
41
|
|
42
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
43
|
+
|
44
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
45
|
+
|
46
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
|
47
|
+
|
48
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
|
49
|
+
|
50
|
+
function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
51
|
+
|
52
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
53
|
+
|
54
|
+
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
55
|
+
|
42
56
|
describe('api', function () {
|
43
57
|
var basicApiFileName = 'basicapi.pdf';
|
44
58
|
var basicApiFileLength = 105779;
|
45
59
|
var basicApiGetDocumentParams = (0, _test_utils.buildGetDocumentParams)(basicApiFileName);
|
46
|
-
var CanvasFactory
|
60
|
+
var CanvasFactory;
|
47
61
|
beforeAll(function (done) {
|
48
|
-
if ((0,
|
62
|
+
if ((0, _is_node.default)()) {
|
63
|
+
CanvasFactory = new _test_utils.NodeCanvasFactory();
|
64
|
+
} else {
|
49
65
|
CanvasFactory = new _dom_utils.DOMCanvasFactory();
|
50
66
|
}
|
67
|
+
|
51
68
|
done();
|
52
69
|
});
|
53
70
|
afterAll(function (done) {
|
54
71
|
CanvasFactory = null;
|
55
72
|
done();
|
56
73
|
});
|
74
|
+
|
57
75
|
function waitSome(callback) {
|
58
76
|
var WAIT_TIMEOUT = 10;
|
59
77
|
setTimeout(function () {
|
60
78
|
callback();
|
61
79
|
}, WAIT_TIMEOUT);
|
62
80
|
}
|
81
|
+
|
63
82
|
describe('getDocument', function () {
|
64
83
|
it('creates pdf doc from URL', function (done) {
|
65
84
|
var loadingTask = (0, _api.getDocument)(basicApiGetDocumentParams);
|
66
|
-
var isProgressReportedResolved = false;
|
67
85
|
var progressReportedCapability = (0, _util.createPromiseCapability)();
|
86
|
+
|
68
87
|
loadingTask.onProgress = function (progressData) {
|
69
|
-
if (!
|
70
|
-
isProgressReportedResolved = true;
|
88
|
+
if (!progressReportedCapability.settled) {
|
71
89
|
progressReportedCapability.resolve(progressData);
|
72
90
|
}
|
73
91
|
};
|
92
|
+
|
74
93
|
var promises = [progressReportedCapability.promise, loadingTask.promise];
|
75
94
|
Promise.all(promises).then(function (data) {
|
76
|
-
expect(data[0].loaded / data[0].total
|
95
|
+
expect(data[0].loaded / data[0].total >= 0).toEqual(true);
|
77
96
|
expect(data[1] instanceof _api.PDFDocumentProxy).toEqual(true);
|
78
97
|
expect(loadingTask).toEqual(data[1].loadingTask);
|
79
98
|
loadingTask.destroy().then(done);
|
80
|
-
}).catch(
|
81
|
-
done.fail(reason);
|
82
|
-
});
|
99
|
+
}).catch(done.fail);
|
83
100
|
});
|
84
101
|
it('creates pdf doc from URL and aborts before worker initialized', function (done) {
|
85
102
|
var loadingTask = (0, _api.getDocument)(basicApiGetDocumentParams);
|
@@ -93,48 +110,61 @@ describe('api', function () {
|
|
93
110
|
});
|
94
111
|
it('creates pdf doc from URL and aborts loading after worker initialized', function (done) {
|
95
112
|
var loadingTask = (0, _api.getDocument)(basicApiGetDocumentParams);
|
113
|
+
|
96
114
|
var destroyed = loadingTask._worker.promise.then(function () {
|
97
115
|
return loadingTask.destroy();
|
98
116
|
});
|
117
|
+
|
99
118
|
destroyed.then(function (data) {
|
100
119
|
expect(true).toEqual(true);
|
101
120
|
done();
|
102
|
-
}).catch(
|
103
|
-
done.fail(reason);
|
104
|
-
});
|
121
|
+
}).catch(done.fail);
|
105
122
|
});
|
106
123
|
it('creates pdf doc from typed array', function (done) {
|
107
124
|
var typedArrayPdf;
|
108
|
-
|
109
|
-
|
125
|
+
|
126
|
+
if ((0, _is_node.default)()) {
|
127
|
+
typedArrayPdf = _test_utils.NodeFileReaderFactory.fetch({
|
128
|
+
path: _test_utils.TEST_PDFS_PATH.node + basicApiFileName
|
129
|
+
});
|
110
130
|
} else {
|
111
131
|
var nonBinaryRequest = false;
|
112
132
|
var request = new XMLHttpRequest();
|
113
133
|
request.open('GET', _test_utils.TEST_PDFS_PATH.dom + basicApiFileName, false);
|
134
|
+
|
114
135
|
try {
|
115
136
|
request.responseType = 'arraybuffer';
|
116
137
|
nonBinaryRequest = request.responseType !== 'arraybuffer';
|
117
138
|
} catch (e) {
|
118
139
|
nonBinaryRequest = true;
|
119
140
|
}
|
141
|
+
|
120
142
|
if (nonBinaryRequest && request.overrideMimeType) {
|
121
143
|
request.overrideMimeType('text/plain; charset=x-user-defined');
|
122
144
|
}
|
145
|
+
|
123
146
|
request.send(null);
|
147
|
+
|
124
148
|
if (nonBinaryRequest) {
|
125
149
|
typedArrayPdf = (0, _util.stringToBytes)(request.responseText);
|
126
150
|
} else {
|
127
151
|
typedArrayPdf = new Uint8Array(request.response);
|
128
152
|
}
|
129
153
|
}
|
154
|
+
|
130
155
|
expect(typedArrayPdf.length).toEqual(basicApiFileLength);
|
131
156
|
var loadingTask = (0, _api.getDocument)(typedArrayPdf);
|
132
|
-
|
133
|
-
|
157
|
+
var progressReportedCapability = (0, _util.createPromiseCapability)();
|
158
|
+
|
159
|
+
loadingTask.onProgress = function (data) {
|
160
|
+
progressReportedCapability.resolve(data);
|
161
|
+
};
|
162
|
+
|
163
|
+
Promise.all([loadingTask.promise, progressReportedCapability.promise]).then(function (data) {
|
164
|
+
expect(data[0] instanceof _api.PDFDocumentProxy).toEqual(true);
|
165
|
+
expect(data[1].loaded / data[1].total).toEqual(1);
|
134
166
|
loadingTask.destroy().then(done);
|
135
|
-
}).catch(
|
136
|
-
done.fail(reason);
|
137
|
-
});
|
167
|
+
}).catch(done.fail);
|
138
168
|
});
|
139
169
|
it('creates pdf doc from invalid PDF file', function (done) {
|
140
170
|
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('bug1020226.pdf'));
|
@@ -146,9 +176,6 @@ describe('api', function () {
|
|
146
176
|
});
|
147
177
|
});
|
148
178
|
it('creates pdf doc from non-existent URL', function (done) {
|
149
|
-
if ((0, _is_node2.default)()) {
|
150
|
-
pending('XMLHttpRequest is not supported in Node.js.');
|
151
|
-
}
|
152
179
|
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('non-existent.pdf'));
|
153
180
|
loadingTask.promise.then(function (error) {
|
154
181
|
done.fail('shall fail loading');
|
@@ -159,36 +186,36 @@ describe('api', function () {
|
|
159
186
|
});
|
160
187
|
it('creates pdf doc from PDF file protected with user and owner password', function (done) {
|
161
188
|
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('pr6531_1.pdf'));
|
162
|
-
var isPasswordNeededResolved = false;
|
163
189
|
var passwordNeededCapability = (0, _util.createPromiseCapability)();
|
164
|
-
var isPasswordIncorrectResolved = false;
|
165
190
|
var passwordIncorrectCapability = (0, _util.createPromiseCapability)();
|
191
|
+
|
166
192
|
loadingTask.onPassword = function (updatePassword, reason) {
|
167
|
-
if (reason === _util.PasswordResponses.NEED_PASSWORD && !
|
168
|
-
isPasswordNeededResolved = true;
|
193
|
+
if (reason === _util.PasswordResponses.NEED_PASSWORD && !passwordNeededCapability.settled) {
|
169
194
|
passwordNeededCapability.resolve();
|
170
195
|
updatePassword('qwerty');
|
171
196
|
return;
|
172
197
|
}
|
173
|
-
|
174
|
-
|
198
|
+
|
199
|
+
if (reason === _util.PasswordResponses.INCORRECT_PASSWORD && !passwordIncorrectCapability.settled) {
|
175
200
|
passwordIncorrectCapability.resolve();
|
176
201
|
updatePassword('asdfasdf');
|
177
202
|
return;
|
178
203
|
}
|
204
|
+
|
179
205
|
expect(false).toEqual(true);
|
180
206
|
};
|
207
|
+
|
181
208
|
var promises = [passwordNeededCapability.promise, passwordIncorrectCapability.promise, loadingTask.promise];
|
182
209
|
Promise.all(promises).then(function (data) {
|
183
210
|
expect(data[2] instanceof _api.PDFDocumentProxy).toEqual(true);
|
184
211
|
loadingTask.destroy().then(done);
|
185
|
-
}).catch(
|
186
|
-
done.fail(reason);
|
187
|
-
});
|
212
|
+
}).catch(done.fail);
|
188
213
|
});
|
189
214
|
it('creates pdf doc from PDF file protected with only a user password', function (done) {
|
190
215
|
var filename = 'pr6531_2.pdf';
|
191
|
-
var passwordNeededLoadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(filename, {
|
216
|
+
var passwordNeededLoadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(filename, {
|
217
|
+
password: ''
|
218
|
+
}));
|
192
219
|
var result1 = passwordNeededLoadingTask.promise.then(function () {
|
193
220
|
done.fail('shall fail with no password');
|
194
221
|
return Promise.reject(new Error('loadingTask should be rejected'));
|
@@ -197,7 +224,9 @@ describe('api', function () {
|
|
197
224
|
expect(data.code).toEqual(_util.PasswordResponses.NEED_PASSWORD);
|
198
225
|
return passwordNeededLoadingTask.destroy();
|
199
226
|
});
|
200
|
-
var passwordIncorrectLoadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(filename, {
|
227
|
+
var passwordIncorrectLoadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(filename, {
|
228
|
+
password: 'qwerty'
|
229
|
+
}));
|
201
230
|
var result2 = passwordIncorrectLoadingTask.promise.then(function () {
|
202
231
|
done.fail('shall fail with wrong password');
|
203
232
|
return Promise.reject(new Error('loadingTask should be rejected'));
|
@@ -206,29 +235,34 @@ describe('api', function () {
|
|
206
235
|
expect(data.code).toEqual(_util.PasswordResponses.INCORRECT_PASSWORD);
|
207
236
|
return passwordIncorrectLoadingTask.destroy();
|
208
237
|
});
|
209
|
-
var passwordAcceptedLoadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(filename, {
|
238
|
+
var passwordAcceptedLoadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(filename, {
|
239
|
+
password: 'asdfasdf'
|
240
|
+
}));
|
210
241
|
var result3 = passwordAcceptedLoadingTask.promise.then(function (data) {
|
211
242
|
expect(data instanceof _api.PDFDocumentProxy).toEqual(true);
|
212
243
|
return passwordAcceptedLoadingTask.destroy();
|
213
244
|
});
|
214
245
|
Promise.all([result1, result2, result3]).then(function () {
|
215
246
|
done();
|
216
|
-
}).catch(
|
217
|
-
done.fail(reason);
|
218
|
-
});
|
247
|
+
}).catch(done.fail);
|
219
248
|
});
|
220
249
|
it('creates pdf doc from password protected PDF file and aborts/throws ' + 'in the onPassword callback (issue 7806)', function (done) {
|
221
250
|
var filename = 'issue3371.pdf';
|
222
251
|
var passwordNeededLoadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(filename));
|
223
|
-
var passwordIncorrectLoadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(filename, {
|
224
|
-
|
252
|
+
var passwordIncorrectLoadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(filename, {
|
253
|
+
password: 'qwerty'
|
254
|
+
}));
|
255
|
+
var passwordNeededDestroyed;
|
256
|
+
|
225
257
|
passwordNeededLoadingTask.onPassword = function (callback, reason) {
|
226
258
|
if (reason === _util.PasswordResponses.NEED_PASSWORD) {
|
227
259
|
passwordNeededDestroyed = passwordNeededLoadingTask.destroy();
|
228
260
|
return;
|
229
261
|
}
|
262
|
+
|
230
263
|
expect(false).toEqual(true);
|
231
264
|
};
|
265
|
+
|
232
266
|
var result1 = passwordNeededLoadingTask.promise.then(function () {
|
233
267
|
done.fail('shall fail since the loadingTask should be destroyed');
|
234
268
|
return Promise.reject(new Error('loadingTask should be rejected'));
|
@@ -237,12 +271,15 @@ describe('api', function () {
|
|
237
271
|
expect(reason.code).toEqual(_util.PasswordResponses.NEED_PASSWORD);
|
238
272
|
return passwordNeededDestroyed;
|
239
273
|
});
|
274
|
+
|
240
275
|
passwordIncorrectLoadingTask.onPassword = function (callback, reason) {
|
241
276
|
if (reason === _util.PasswordResponses.INCORRECT_PASSWORD) {
|
242
277
|
throw new Error('Incorrect password');
|
243
278
|
}
|
279
|
+
|
244
280
|
expect(false).toEqual(true);
|
245
281
|
};
|
282
|
+
|
246
283
|
var result2 = passwordIncorrectLoadingTask.promise.then(function () {
|
247
284
|
done.fail('shall fail since the onPassword callback should throw');
|
248
285
|
return Promise.reject(new Error('loadingTask should be rejected'));
|
@@ -253,17 +290,18 @@ describe('api', function () {
|
|
253
290
|
});
|
254
291
|
Promise.all([result1, result2]).then(function () {
|
255
292
|
done();
|
256
|
-
}).catch(
|
257
|
-
done.fail(reason);
|
258
|
-
});
|
293
|
+
}).catch(done.fail);
|
259
294
|
});
|
260
295
|
});
|
261
296
|
describe('PDFWorker', function () {
|
262
297
|
it('worker created or destroyed', function (done) {
|
263
|
-
if ((0,
|
298
|
+
if ((0, _is_node.default)()) {
|
264
299
|
pending('Worker is not supported in Node.js.');
|
265
300
|
}
|
266
|
-
|
301
|
+
|
302
|
+
var worker = new _api.PDFWorker({
|
303
|
+
name: 'test1'
|
304
|
+
});
|
267
305
|
worker.promise.then(function () {
|
268
306
|
expect(worker.name).toEqual('test1');
|
269
307
|
expect(!!worker.port).toEqual(true);
|
@@ -274,14 +312,13 @@ describe('api', function () {
|
|
274
312
|
expect(!!worker.port).toEqual(false);
|
275
313
|
expect(worker.destroyed).toEqual(true);
|
276
314
|
done();
|
277
|
-
}).catch(
|
278
|
-
done.fail(reason);
|
279
|
-
});
|
315
|
+
}).catch(done.fail);
|
280
316
|
});
|
281
317
|
it('worker created or destroyed by getDocument', function (done) {
|
282
|
-
if ((0,
|
318
|
+
if ((0, _is_node.default)()) {
|
283
319
|
pending('Worker is not supported in Node.js.');
|
284
320
|
}
|
321
|
+
|
285
322
|
var loadingTask = (0, _api.getDocument)(basicApiGetDocumentParams);
|
286
323
|
var worker;
|
287
324
|
loadingTask.promise.then(function () {
|
@@ -296,16 +333,19 @@ describe('api', function () {
|
|
296
333
|
expect(!!destroyedWorker).toEqual(false);
|
297
334
|
expect(worker.destroyed).toEqual(true);
|
298
335
|
done();
|
299
|
-
}).catch(
|
300
|
-
done.fail(reason);
|
301
|
-
});
|
336
|
+
}).catch(done.fail);
|
302
337
|
});
|
303
338
|
it('worker created and can be used in getDocument', function (done) {
|
304
|
-
if ((0,
|
339
|
+
if ((0, _is_node.default)()) {
|
305
340
|
pending('Worker is not supported in Node.js.');
|
306
341
|
}
|
307
|
-
|
308
|
-
var
|
342
|
+
|
343
|
+
var worker = new _api.PDFWorker({
|
344
|
+
name: 'test1'
|
345
|
+
});
|
346
|
+
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(basicApiFileName, {
|
347
|
+
worker: worker
|
348
|
+
}));
|
309
349
|
loadingTask.promise.then(function () {
|
310
350
|
var docWorker = loadingTask._worker;
|
311
351
|
expect(!!docWorker).toEqual(false);
|
@@ -319,17 +359,22 @@ describe('api', function () {
|
|
319
359
|
expect(worker.destroyed).toEqual(false);
|
320
360
|
worker.destroy();
|
321
361
|
done();
|
322
|
-
}).catch(
|
323
|
-
done.fail(reason);
|
324
|
-
});
|
362
|
+
}).catch(done.fail);
|
325
363
|
});
|
326
364
|
it('creates more than one worker', function (done) {
|
327
|
-
if ((0,
|
365
|
+
if ((0, _is_node.default)()) {
|
328
366
|
pending('Worker is not supported in Node.js.');
|
329
367
|
}
|
330
|
-
|
331
|
-
var
|
332
|
-
|
368
|
+
|
369
|
+
var worker1 = new _api.PDFWorker({
|
370
|
+
name: 'test1'
|
371
|
+
});
|
372
|
+
var worker2 = new _api.PDFWorker({
|
373
|
+
name: 'test2'
|
374
|
+
});
|
375
|
+
var worker3 = new _api.PDFWorker({
|
376
|
+
name: 'test3'
|
377
|
+
});
|
333
378
|
var ready = Promise.all([worker1.promise, worker2.promise, worker3.promise]);
|
334
379
|
ready.then(function () {
|
335
380
|
expect(worker1.port !== worker2.port && worker1.port !== worker3.port && worker2.port !== worker3.port).toEqual(true);
|
@@ -337,16 +382,16 @@ describe('api', function () {
|
|
337
382
|
worker2.destroy();
|
338
383
|
worker3.destroy();
|
339
384
|
done();
|
340
|
-
}).catch(
|
341
|
-
done.fail(reason);
|
342
|
-
});
|
385
|
+
}).catch(done.fail);
|
343
386
|
});
|
344
387
|
it('gets current workerSrc', function () {
|
345
|
-
if ((0,
|
388
|
+
if ((0, _is_node.default)()) {
|
346
389
|
pending('Worker is not supported in Node.js.');
|
347
390
|
}
|
391
|
+
|
348
392
|
var workerSrc = _api.PDFWorker.getWorkerSrc();
|
349
|
-
|
393
|
+
|
394
|
+
expect(_typeof(workerSrc)).toEqual('string');
|
350
395
|
expect(workerSrc).toEqual(_worker_options.GlobalWorkerOptions.workerSrc);
|
351
396
|
});
|
352
397
|
});
|
@@ -368,7 +413,7 @@ describe('api', function () {
|
|
368
413
|
});
|
369
414
|
it('gets fingerprint', function () {
|
370
415
|
var fingerprint = doc.fingerprint;
|
371
|
-
expect(
|
416
|
+
expect(_typeof(fingerprint)).toEqual('string');
|
372
417
|
expect(fingerprint.length > 0).toEqual(true);
|
373
418
|
});
|
374
419
|
it('gets page', function (done) {
|
@@ -377,9 +422,7 @@ describe('api', function () {
|
|
377
422
|
expect(data instanceof _api.PDFPageProxy).toEqual(true);
|
378
423
|
expect(data.pageIndex).toEqual(0);
|
379
424
|
done();
|
380
|
-
}).catch(
|
381
|
-
done.fail(reason);
|
382
|
-
});
|
425
|
+
}).catch(done.fail);
|
383
426
|
});
|
384
427
|
it('gets non-existent page', function (done) {
|
385
428
|
var outOfRangePromise = doc.getPage(100);
|
@@ -402,9 +445,7 @@ describe('api', function () {
|
|
402
445
|
});
|
403
446
|
Promise.all([outOfRangePromise, nonIntegerPromise, nonNumberPromise]).then(function () {
|
404
447
|
done();
|
405
|
-
}).catch(
|
406
|
-
done.fail(reason);
|
407
|
-
});
|
448
|
+
}).catch(done.fail);
|
408
449
|
});
|
409
450
|
it('gets page index', function (done) {
|
410
451
|
var ref = {
|
@@ -415,9 +456,7 @@ describe('api', function () {
|
|
415
456
|
promise.then(function (pageIndex) {
|
416
457
|
expect(pageIndex).toEqual(1);
|
417
458
|
done();
|
418
|
-
}).catch(
|
419
|
-
done.fail(reason);
|
420
|
-
});
|
459
|
+
}).catch(done.fail);
|
421
460
|
});
|
422
461
|
it('gets invalid page index', function (done) {
|
423
462
|
var ref = {
|
@@ -439,12 +478,12 @@ describe('api', function () {
|
|
439
478
|
chapter1: [{
|
440
479
|
gen: 0,
|
441
480
|
num: 17
|
442
|
-
}, {
|
481
|
+
}, {
|
482
|
+
name: 'XYZ'
|
483
|
+
}, 0, 841.89, null]
|
443
484
|
});
|
444
485
|
done();
|
445
|
-
}).catch(
|
446
|
-
done.fail(reason);
|
447
|
-
});
|
486
|
+
}).catch(done.fail);
|
448
487
|
});
|
449
488
|
it('gets a destination, from /Dests dictionary', function (done) {
|
450
489
|
var promise = doc.getDestination('chapter1');
|
@@ -452,20 +491,18 @@ describe('api', function () {
|
|
452
491
|
expect(data).toEqual([{
|
453
492
|
gen: 0,
|
454
493
|
num: 17
|
455
|
-
}, {
|
494
|
+
}, {
|
495
|
+
name: 'XYZ'
|
496
|
+
}, 0, 841.89, null]);
|
456
497
|
done();
|
457
|
-
}).catch(
|
458
|
-
done.fail(reason);
|
459
|
-
});
|
498
|
+
}).catch(done.fail);
|
460
499
|
});
|
461
500
|
it('gets a non-existent destination, from /Dests dictionary', function (done) {
|
462
501
|
var promise = doc.getDestination('non-existent-named-destination');
|
463
502
|
promise.then(function (data) {
|
464
503
|
expect(data).toEqual(null);
|
465
504
|
done();
|
466
|
-
}).catch(
|
467
|
-
done.fail(reason);
|
468
|
-
});
|
505
|
+
}).catch(done.fail);
|
469
506
|
});
|
470
507
|
it('gets destinations, from /Names (NameTree) dictionary', function (done) {
|
471
508
|
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue6204.pdf'));
|
@@ -477,16 +514,18 @@ describe('api', function () {
|
|
477
514
|
'Page.1': [{
|
478
515
|
num: 1,
|
479
516
|
gen: 0
|
480
|
-
}, {
|
517
|
+
}, {
|
518
|
+
name: 'XYZ'
|
519
|
+
}, 0, 375, null],
|
481
520
|
'Page.2': [{
|
482
521
|
num: 6,
|
483
522
|
gen: 0
|
484
|
-
}, {
|
523
|
+
}, {
|
524
|
+
name: 'XYZ'
|
525
|
+
}, 0, 375, null]
|
485
526
|
});
|
486
527
|
loadingTask.destroy().then(done);
|
487
|
-
}).catch(
|
488
|
-
done.fail(reason);
|
489
|
-
});
|
528
|
+
}).catch(done.fail);
|
490
529
|
});
|
491
530
|
it('gets a destination, from /Names (NameTree) dictionary', function (done) {
|
492
531
|
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue6204.pdf'));
|
@@ -497,11 +536,11 @@ describe('api', function () {
|
|
497
536
|
expect(destination).toEqual([{
|
498
537
|
num: 1,
|
499
538
|
gen: 0
|
500
|
-
}, {
|
539
|
+
}, {
|
540
|
+
name: 'XYZ'
|
541
|
+
}, 0, 375, null]);
|
501
542
|
loadingTask.destroy().then(done);
|
502
|
-
}).catch(
|
503
|
-
done.fail(reason);
|
504
|
-
});
|
543
|
+
}).catch(done.fail);
|
505
544
|
});
|
506
545
|
it('gets a non-existent destination, from /Names (NameTree) dictionary', function (done) {
|
507
546
|
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue6204.pdf'));
|
@@ -511,18 +550,40 @@ describe('api', function () {
|
|
511
550
|
promise.then(function (destination) {
|
512
551
|
expect(destination).toEqual(null);
|
513
552
|
loadingTask.destroy().then(done);
|
514
|
-
}).catch(
|
515
|
-
|
553
|
+
}).catch(done.fail);
|
554
|
+
});
|
555
|
+
it('gets non-string destination', function (done) {
|
556
|
+
var numberPromise = doc.getDestination(4.3);
|
557
|
+
var booleanPromise = doc.getDestination(true);
|
558
|
+
var arrayPromise = doc.getDestination([{
|
559
|
+
num: 17,
|
560
|
+
gen: 0
|
561
|
+
}, {
|
562
|
+
name: 'XYZ'
|
563
|
+
}, 0, 841.89, null]);
|
564
|
+
numberPromise = numberPromise.then(function () {
|
565
|
+
throw new Error('shall fail for non-string destination.');
|
566
|
+
}, function (reason) {
|
567
|
+
expect(reason instanceof Error).toEqual(true);
|
516
568
|
});
|
569
|
+
booleanPromise = booleanPromise.then(function () {
|
570
|
+
throw new Error('shall fail for non-string destination.');
|
571
|
+
}, function (reason) {
|
572
|
+
expect(reason instanceof Error).toEqual(true);
|
573
|
+
});
|
574
|
+
arrayPromise = arrayPromise.then(function () {
|
575
|
+
throw new Error('shall fail for non-string destination.');
|
576
|
+
}, function (reason) {
|
577
|
+
expect(reason instanceof Error).toEqual(true);
|
578
|
+
});
|
579
|
+
Promise.all([numberPromise, booleanPromise, arrayPromise]).then(done, done.fail);
|
517
580
|
});
|
518
581
|
it('gets non-existent page labels', function (done) {
|
519
582
|
var promise = doc.getPageLabels();
|
520
583
|
promise.then(function (data) {
|
521
584
|
expect(data).toEqual(null);
|
522
585
|
done();
|
523
|
-
}).catch(
|
524
|
-
done.fail(reason);
|
525
|
-
});
|
586
|
+
}).catch(done.fail);
|
526
587
|
});
|
527
588
|
it('gets page labels', function (done) {
|
528
589
|
var loadingTask0 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('bug793632.pdf'));
|
@@ -547,9 +608,7 @@ describe('api', function () {
|
|
547
608
|
expect(pageLabels[2]).toEqual(['1', '2']);
|
548
609
|
expect(pageLabels[3]).toEqual(['X3']);
|
549
610
|
Promise.all([loadingTask0.destroy(), loadingTask1.destroy(), loadingTask2.destroy(), loadingTask3.destroy()]).then(done);
|
550
|
-
}).catch(
|
551
|
-
done.fail(reason);
|
552
|
-
});
|
611
|
+
}).catch(done.fail);
|
553
612
|
});
|
554
613
|
it('gets default page mode', function (done) {
|
555
614
|
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('tracemonkey.pdf'));
|
@@ -558,31 +617,46 @@ describe('api', function () {
|
|
558
617
|
}).then(function (mode) {
|
559
618
|
expect(mode).toEqual('UseNone');
|
560
619
|
loadingTask.destroy().then(done);
|
561
|
-
}).catch(
|
562
|
-
done.fail(reason);
|
563
|
-
});
|
620
|
+
}).catch(done.fail);
|
564
621
|
});
|
565
622
|
it('gets non-default page mode', function (done) {
|
566
623
|
doc.getPageMode().then(function (mode) {
|
567
624
|
expect(mode).toEqual('UseOutlines');
|
568
625
|
done();
|
569
|
-
}).catch(
|
570
|
-
|
571
|
-
|
626
|
+
}).catch(done.fail);
|
627
|
+
});
|
628
|
+
it('gets default open action destination', function (done) {
|
629
|
+
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('tracemonkey.pdf'));
|
630
|
+
loadingTask.promise.then(function (pdfDocument) {
|
631
|
+
return pdfDocument.getOpenActionDestination();
|
632
|
+
}).then(function (dest) {
|
633
|
+
expect(dest).toEqual(null);
|
634
|
+
loadingTask.destroy().then(done);
|
635
|
+
}).catch(done.fail);
|
636
|
+
});
|
637
|
+
it('gets non-default open action destination', function (done) {
|
638
|
+
doc.getOpenActionDestination().then(function (dest) {
|
639
|
+
expect(dest).toEqual([{
|
640
|
+
num: 15,
|
641
|
+
gen: 0
|
642
|
+
}, {
|
643
|
+
name: 'FitH'
|
644
|
+
}, null]);
|
645
|
+
done();
|
646
|
+
}).catch(done.fail);
|
572
647
|
});
|
573
648
|
it('gets non-existent attachments', function (done) {
|
574
649
|
var promise = doc.getAttachments();
|
575
650
|
promise.then(function (data) {
|
576
651
|
expect(data).toEqual(null);
|
577
652
|
done();
|
578
|
-
}).catch(
|
579
|
-
done.fail(reason);
|
580
|
-
});
|
653
|
+
}).catch(done.fail);
|
581
654
|
});
|
582
655
|
it('gets attachments', function (done) {
|
583
|
-
if ((0,
|
656
|
+
if ((0, _is_node.default)()) {
|
584
657
|
pending('TODO: Use a non-linked test-case.');
|
585
658
|
}
|
659
|
+
|
586
660
|
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('bug766138.pdf'));
|
587
661
|
var promise = loadingTask.promise.then(function (pdfDoc) {
|
588
662
|
return pdfDoc.getAttachments();
|
@@ -593,18 +667,14 @@ describe('api', function () {
|
|
593
667
|
expect(attachment.content instanceof Uint8Array).toBeTruthy();
|
594
668
|
expect(attachment.content.length).toEqual(30098);
|
595
669
|
loadingTask.destroy().then(done);
|
596
|
-
}).catch(
|
597
|
-
done.fail(reason);
|
598
|
-
});
|
670
|
+
}).catch(done.fail);
|
599
671
|
});
|
600
672
|
it('gets javascript', function (done) {
|
601
673
|
var promise = doc.getJavaScript();
|
602
674
|
promise.then(function (data) {
|
603
675
|
expect(data).toEqual(null);
|
604
676
|
done();
|
605
|
-
}).catch(
|
606
|
-
done.fail(reason);
|
607
|
-
});
|
677
|
+
}).catch(done.fail);
|
608
678
|
});
|
609
679
|
var viewerPrintRegExp = /\bprint\s*\(/;
|
610
680
|
it('gets javascript with printing instructions (Print action)', function (done) {
|
@@ -616,9 +686,7 @@ describe('api', function () {
|
|
616
686
|
expect(data).toEqual(['print({});']);
|
617
687
|
expect(data[0]).toMatch(viewerPrintRegExp);
|
618
688
|
loadingTask.destroy().then(done);
|
619
|
-
}).catch(
|
620
|
-
done.fail(reason);
|
621
|
-
});
|
689
|
+
}).catch(done.fail);
|
622
690
|
});
|
623
691
|
it('gets javascript with printing instructions (JS action)', function (done) {
|
624
692
|
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue6106.pdf'));
|
@@ -629,9 +697,7 @@ describe('api', function () {
|
|
629
697
|
expect(data).toEqual(['this.print({bUI:true,bSilent:false,bShrinkToFit:true});']);
|
630
698
|
expect(data[0]).toMatch(viewerPrintRegExp);
|
631
699
|
loadingTask.destroy().then(done);
|
632
|
-
}).catch(
|
633
|
-
done.fail(reason);
|
634
|
-
});
|
700
|
+
}).catch(done.fail);
|
635
701
|
});
|
636
702
|
it('gets non-existent outline', function (done) {
|
637
703
|
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('tracemonkey.pdf'));
|
@@ -641,36 +707,32 @@ describe('api', function () {
|
|
641
707
|
promise.then(function (outline) {
|
642
708
|
expect(outline).toEqual(null);
|
643
709
|
loadingTask.destroy().then(done);
|
644
|
-
}).catch(
|
645
|
-
done.fail(reason);
|
646
|
-
});
|
710
|
+
}).catch(done.fail);
|
647
711
|
});
|
648
712
|
it('gets outline', function (done) {
|
649
713
|
var promise = doc.getOutline();
|
650
714
|
promise.then(function (outline) {
|
651
|
-
expect(outline
|
715
|
+
expect(Array.isArray(outline)).toEqual(true);
|
652
716
|
expect(outline.length).toEqual(2);
|
653
717
|
var outlineItem = outline[1];
|
654
718
|
expect(outlineItem.title).toEqual('Chapter 1');
|
655
|
-
expect(outlineItem.dest
|
719
|
+
expect(Array.isArray(outlineItem.dest)).toEqual(true);
|
656
720
|
expect(outlineItem.url).toEqual(null);
|
657
721
|
expect(outlineItem.unsafeUrl).toBeUndefined();
|
658
722
|
expect(outlineItem.newWindow).toBeUndefined();
|
659
723
|
expect(outlineItem.bold).toEqual(true);
|
660
724
|
expect(outlineItem.italic).toEqual(false);
|
661
|
-
expect(outlineItem.color).toEqual(new
|
725
|
+
expect(outlineItem.color).toEqual(new Uint8ClampedArray([0, 64, 128]));
|
662
726
|
expect(outlineItem.items.length).toEqual(1);
|
663
727
|
expect(outlineItem.items[0].title).toEqual('Paragraph 1.1');
|
664
728
|
done();
|
665
|
-
}).catch(
|
666
|
-
done.fail(reason);
|
667
|
-
});
|
729
|
+
}).catch(done.fail);
|
668
730
|
});
|
669
731
|
it('gets outline containing a url', function (done) {
|
670
732
|
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue3214.pdf'));
|
671
733
|
loadingTask.promise.then(function (pdfDocument) {
|
672
734
|
pdfDocument.getOutline().then(function (outline) {
|
673
|
-
expect(outline
|
735
|
+
expect(Array.isArray(outline)).toEqual(true);
|
674
736
|
expect(outline.length).toEqual(5);
|
675
737
|
var outlineItemTwo = outline[2];
|
676
738
|
expect(_typeof(outlineItemTwo.title)).toEqual('string');
|
@@ -681,24 +743,82 @@ describe('api', function () {
|
|
681
743
|
var outlineItemOne = outline[1];
|
682
744
|
expect(outlineItemOne.bold).toEqual(false);
|
683
745
|
expect(outlineItemOne.italic).toEqual(true);
|
684
|
-
expect(outlineItemOne.color).toEqual(new
|
746
|
+
expect(outlineItemOne.color).toEqual(new Uint8ClampedArray([0, 0, 0]));
|
685
747
|
loadingTask.destroy().then(done);
|
686
748
|
});
|
687
|
-
}).catch(
|
688
|
-
|
689
|
-
|
749
|
+
}).catch(done.fail);
|
750
|
+
});
|
751
|
+
it('gets non-existent permissions', function (done) {
|
752
|
+
doc.getPermissions().then(function (permissions) {
|
753
|
+
expect(permissions).toEqual(null);
|
754
|
+
done();
|
755
|
+
}).catch(done.fail);
|
756
|
+
});
|
757
|
+
it('gets permissions', function (done) {
|
758
|
+
var loadingTask0 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue9972-1.pdf'));
|
759
|
+
var promise0 = loadingTask0.promise.then(function (pdfDocument) {
|
760
|
+
return pdfDocument.getPermissions();
|
761
|
+
});
|
762
|
+
var loadingTask1 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue9972-2.pdf'));
|
763
|
+
var promise1 = loadingTask1.promise.then(function (pdfDocument) {
|
764
|
+
return pdfDocument.getPermissions();
|
765
|
+
});
|
766
|
+
var loadingTask2 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue9972-3.pdf'));
|
767
|
+
var promise2 = loadingTask2.promise.then(function (pdfDocument) {
|
768
|
+
return pdfDocument.getPermissions();
|
769
|
+
});
|
770
|
+
var totalPermissionCount = Object.keys(_util.PermissionFlag).length;
|
771
|
+
Promise.all([promise0, promise1, promise2]).then(function (permissions) {
|
772
|
+
expect(permissions[0].length).toEqual(totalPermissionCount - 1);
|
773
|
+
expect(permissions[0].includes(_util.PermissionFlag.MODIFY_CONTENTS)).toBeFalsy();
|
774
|
+
expect(permissions[1].length).toEqual(totalPermissionCount - 2);
|
775
|
+
expect(permissions[1].includes(_util.PermissionFlag.PRINT)).toBeFalsy();
|
776
|
+
expect(permissions[1].includes(_util.PermissionFlag.PRINT_HIGH_QUALITY)).toBeFalsy();
|
777
|
+
expect(permissions[2].length).toEqual(totalPermissionCount - 1);
|
778
|
+
expect(permissions[2].includes(_util.PermissionFlag.COPY)).toBeFalsy();
|
779
|
+
Promise.all([loadingTask0.destroy(), loadingTask1.destroy(), loadingTask2.destroy()]).then(done);
|
780
|
+
}).catch(done.fail);
|
690
781
|
});
|
691
782
|
it('gets metadata', function (done) {
|
692
783
|
var promise = doc.getMetadata();
|
693
|
-
promise.then(function (
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
expect(
|
784
|
+
promise.then(function (_ref) {
|
785
|
+
var info = _ref.info,
|
786
|
+
metadata = _ref.metadata,
|
787
|
+
contentDispositionFilename = _ref.contentDispositionFilename;
|
788
|
+
expect(info['Title']).toEqual('Basic API Test');
|
789
|
+
expect(info['Custom']).toEqual(undefined);
|
790
|
+
expect(info['PDFFormatVersion']).toEqual('1.7');
|
791
|
+
expect(info['IsLinearized']).toEqual(false);
|
792
|
+
expect(info['IsAcroFormPresent']).toEqual(false);
|
793
|
+
expect(info['IsXFAPresent']).toEqual(false);
|
794
|
+
expect(metadata instanceof _metadata.Metadata).toEqual(true);
|
795
|
+
expect(metadata.get('dc:title')).toEqual('Basic API Test');
|
796
|
+
expect(contentDispositionFilename).toEqual(null);
|
698
797
|
done();
|
699
|
-
}).catch(
|
700
|
-
|
701
|
-
|
798
|
+
}).catch(done.fail);
|
799
|
+
});
|
800
|
+
it('gets metadata, with custom info dict entries', function (done) {
|
801
|
+
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('tracemonkey.pdf'));
|
802
|
+
loadingTask.promise.then(function (pdfDocument) {
|
803
|
+
return pdfDocument.getMetadata();
|
804
|
+
}).then(function (_ref2) {
|
805
|
+
var info = _ref2.info,
|
806
|
+
metadata = _ref2.metadata,
|
807
|
+
contentDispositionFilename = _ref2.contentDispositionFilename;
|
808
|
+
expect(info['Creator']).toEqual('TeX');
|
809
|
+
expect(info['Producer']).toEqual('pdfeTeX-1.21a');
|
810
|
+
expect(info['CreationDate']).toEqual('D:20090401163925-07\'00\'');
|
811
|
+
var custom = info['Custom'];
|
812
|
+
expect(_typeof(custom) === 'object' && custom !== null).toEqual(true);
|
813
|
+
expect(custom['PTEX.Fullbanner']).toEqual('This is pdfeTeX, ' + 'Version 3.141592-1.21a-2.2 (Web2C 7.5.4) kpathsea version 3.5.6');
|
814
|
+
expect(info['PDFFormatVersion']).toEqual('1.4');
|
815
|
+
expect(info['IsLinearized']).toEqual(false);
|
816
|
+
expect(info['IsAcroFormPresent']).toEqual(false);
|
817
|
+
expect(info['IsXFAPresent']).toEqual(false);
|
818
|
+
expect(metadata).toEqual(null);
|
819
|
+
expect(contentDispositionFilename).toEqual(null);
|
820
|
+
loadingTask.destroy().then(done);
|
821
|
+
}).catch(done.fail);
|
702
822
|
});
|
703
823
|
it('gets data', function (done) {
|
704
824
|
var promise = doc.getData();
|
@@ -706,20 +826,18 @@ describe('api', function () {
|
|
706
826
|
expect(data instanceof Uint8Array).toEqual(true);
|
707
827
|
expect(data.length).toEqual(basicApiFileLength);
|
708
828
|
done();
|
709
|
-
}).catch(
|
710
|
-
done.fail(reason);
|
711
|
-
});
|
829
|
+
}).catch(done.fail);
|
712
830
|
});
|
713
831
|
it('gets download info', function (done) {
|
714
832
|
var promise = doc.getDownloadInfo();
|
715
833
|
promise.then(function (data) {
|
716
|
-
expect(data).toEqual({
|
834
|
+
expect(data).toEqual({
|
835
|
+
length: basicApiFileLength
|
836
|
+
});
|
717
837
|
done();
|
718
|
-
}).catch(
|
719
|
-
done.fail(reason);
|
720
|
-
});
|
838
|
+
}).catch(done.fail);
|
721
839
|
});
|
722
|
-
it('gets stats', function (done) {
|
840
|
+
it('gets document stats', function (done) {
|
723
841
|
var promise = doc.getStats();
|
724
842
|
promise.then(function (stats) {
|
725
843
|
expect(stats).toEqual({
|
@@ -727,9 +845,7 @@ describe('api', function () {
|
|
727
845
|
fontTypes: []
|
728
846
|
});
|
729
847
|
done();
|
730
|
-
}).catch(
|
731
|
-
done.fail(reason);
|
732
|
-
});
|
848
|
+
}).catch(done.fail);
|
733
849
|
});
|
734
850
|
it('checks that fingerprints are unique', function (done) {
|
735
851
|
var loadingTask1 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue4436r.pdf'));
|
@@ -737,25 +853,26 @@ describe('api', function () {
|
|
737
853
|
var promises = [loadingTask1.promise, loadingTask2.promise];
|
738
854
|
Promise.all(promises).then(function (data) {
|
739
855
|
var fingerprint1 = data[0].fingerprint;
|
740
|
-
expect(
|
856
|
+
expect(_typeof(fingerprint1)).toEqual('string');
|
741
857
|
expect(fingerprint1.length > 0).toEqual(true);
|
742
858
|
var fingerprint2 = data[1].fingerprint;
|
743
|
-
expect(
|
859
|
+
expect(_typeof(fingerprint2)).toEqual('string');
|
744
860
|
expect(fingerprint2.length > 0).toEqual(true);
|
745
861
|
expect(fingerprint1).not.toEqual(fingerprint2);
|
746
862
|
Promise.all([loadingTask1.destroy(), loadingTask2.destroy()]).then(done);
|
747
|
-
}).catch(
|
748
|
-
done.fail(reason);
|
749
|
-
});
|
863
|
+
}).catch(done.fail);
|
750
864
|
});
|
751
865
|
describe('Cross-origin', function () {
|
752
866
|
var loadingTask;
|
867
|
+
|
753
868
|
function _checkCanLoad(expectSuccess, filename, options) {
|
754
|
-
if ((0,
|
869
|
+
if ((0, _is_node.default)()) {
|
755
870
|
pending('Cannot simulate cross-origin requests in Node.js');
|
756
871
|
}
|
872
|
+
|
757
873
|
var params = (0, _test_utils.buildGetDocumentParams)(filename, options);
|
758
874
|
var url = new URL(params.url);
|
875
|
+
|
759
876
|
if (url.hostname === 'localhost') {
|
760
877
|
url.hostname = '127.0.0.1';
|
761
878
|
} else if (params.url.hostname === '127.0.0.1') {
|
@@ -763,6 +880,7 @@ describe('api', function () {
|
|
763
880
|
} else {
|
764
881
|
pending('Can only run cross-origin test on localhost!');
|
765
882
|
}
|
883
|
+
|
766
884
|
params.url = url.href;
|
767
885
|
loadingTask = (0, _api.getDocument)(params);
|
768
886
|
return loadingTask.promise.then(function (pdf) {
|
@@ -773,15 +891,19 @@ describe('api', function () {
|
|
773
891
|
if (expectSuccess) {
|
774
892
|
expect(error).toEqual('There should not be any error');
|
775
893
|
}
|
894
|
+
|
776
895
|
expect(expectSuccess).toEqual(false);
|
777
896
|
});
|
778
897
|
}
|
898
|
+
|
779
899
|
function testCanLoad(filename, options) {
|
780
900
|
return _checkCanLoad(true, filename, options);
|
781
901
|
}
|
902
|
+
|
782
903
|
function testCannotLoad(filename, options) {
|
783
904
|
return _checkCanLoad(false, filename, options);
|
784
905
|
}
|
906
|
+
|
785
907
|
afterEach(function (done) {
|
786
908
|
if (loadingTask) {
|
787
909
|
loadingTask.destroy().then(done);
|
@@ -796,16 +918,24 @@ describe('api', function () {
|
|
796
918
|
testCanLoad('basicapi.pdf?cors=withoutCredentials').then(done);
|
797
919
|
});
|
798
920
|
it('server allows cors without credentials, and withCredentials=false', function (done) {
|
799
|
-
testCanLoad('basicapi.pdf?cors=withoutCredentials', {
|
921
|
+
testCanLoad('basicapi.pdf?cors=withoutCredentials', {
|
922
|
+
withCredentials: false
|
923
|
+
}).then(done);
|
800
924
|
});
|
801
925
|
it('server allows cors without credentials, but withCredentials=true', function (done) {
|
802
|
-
testCannotLoad('basicapi.pdf?cors=withoutCredentials', {
|
926
|
+
testCannotLoad('basicapi.pdf?cors=withoutCredentials', {
|
927
|
+
withCredentials: true
|
928
|
+
}).then(done);
|
803
929
|
});
|
804
930
|
it('server allows cors with credentials, and withCredentials=true', function (done) {
|
805
|
-
testCanLoad('basicapi.pdf?cors=withCredentials', {
|
931
|
+
testCanLoad('basicapi.pdf?cors=withCredentials', {
|
932
|
+
withCredentials: true
|
933
|
+
}).then(done);
|
806
934
|
});
|
807
935
|
it('server allows cors with credentials, and withCredentials=false', function (done) {
|
808
|
-
testCanLoad('basicapi.pdf?cors=withCredentials', {
|
936
|
+
testCanLoad('basicapi.pdf?cors=withCredentials', {
|
937
|
+
withCredentials: false
|
938
|
+
}).then(done);
|
809
939
|
});
|
810
940
|
});
|
811
941
|
});
|
@@ -820,9 +950,7 @@ describe('api', function () {
|
|
820
950
|
page = data;
|
821
951
|
done();
|
822
952
|
});
|
823
|
-
}).catch(
|
824
|
-
done.fail(reason);
|
825
|
-
});
|
953
|
+
}).catch(done.fail);
|
826
954
|
});
|
827
955
|
afterAll(function (done) {
|
828
956
|
loadingTask.destroy().then(done);
|
@@ -846,7 +974,10 @@ describe('api', function () {
|
|
846
974
|
expect(page.view).toEqual([0, 0, 595.28, 841.89]);
|
847
975
|
});
|
848
976
|
it('gets viewport', function () {
|
849
|
-
var viewport = page.getViewport(
|
977
|
+
var viewport = page.getViewport({
|
978
|
+
scale: 1.5,
|
979
|
+
rotation: 90
|
980
|
+
});
|
850
981
|
expect(viewport.viewBox).toEqual(page.view);
|
851
982
|
expect(viewport.scale).toEqual(1.5);
|
852
983
|
expect(viewport.rotation).toEqual(90);
|
@@ -857,10 +988,19 @@ describe('api', function () {
|
|
857
988
|
it('gets viewport respecting "dontFlip" argument', function () {
|
858
989
|
var scale = 1;
|
859
990
|
var rotation = 135;
|
860
|
-
var viewport = page.getViewport(
|
861
|
-
|
991
|
+
var viewport = page.getViewport({
|
992
|
+
scale: scale,
|
993
|
+
rotation: rotation
|
994
|
+
});
|
995
|
+
var dontFlipViewport = page.getViewport({
|
996
|
+
scale: scale,
|
997
|
+
rotation: rotation,
|
998
|
+
dontFlip: true
|
999
|
+
});
|
862
1000
|
expect(dontFlipViewport).not.toEqual(viewport);
|
863
|
-
expect(dontFlipViewport).toEqual(viewport.clone({
|
1001
|
+
expect(dontFlipViewport).toEqual(viewport.clone({
|
1002
|
+
dontFlip: true
|
1003
|
+
}));
|
864
1004
|
expect(viewport.transform).toEqual([1, 0, 0, -1, 0, 841.89]);
|
865
1005
|
expect(dontFlipViewport.transform).toEqual([1, 0, -0, 1, 0, 0]);
|
866
1006
|
});
|
@@ -868,17 +1008,19 @@ describe('api', function () {
|
|
868
1008
|
var defaultPromise = page.getAnnotations().then(function (data) {
|
869
1009
|
expect(data.length).toEqual(4);
|
870
1010
|
});
|
871
|
-
var displayPromise = page.getAnnotations({
|
1011
|
+
var displayPromise = page.getAnnotations({
|
1012
|
+
intent: 'display'
|
1013
|
+
}).then(function (data) {
|
872
1014
|
expect(data.length).toEqual(4);
|
873
1015
|
});
|
874
|
-
var printPromise = page.getAnnotations({
|
1016
|
+
var printPromise = page.getAnnotations({
|
1017
|
+
intent: 'print'
|
1018
|
+
}).then(function (data) {
|
875
1019
|
expect(data.length).toEqual(4);
|
876
1020
|
});
|
877
1021
|
Promise.all([defaultPromise, displayPromise, printPromise]).then(function () {
|
878
1022
|
done();
|
879
|
-
}).catch(
|
880
|
-
done.fail(reason);
|
881
|
-
});
|
1023
|
+
}).catch(done.fail);
|
882
1024
|
});
|
883
1025
|
it('gets annotations containing relative URLs (bug 766086)', function (done) {
|
884
1026
|
var filename = 'bug766086.pdf';
|
@@ -888,13 +1030,17 @@ describe('api', function () {
|
|
888
1030
|
return pdfPage.getAnnotations();
|
889
1031
|
});
|
890
1032
|
});
|
891
|
-
var docBaseUrlLoadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(filename, {
|
1033
|
+
var docBaseUrlLoadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(filename, {
|
1034
|
+
docBaseUrl: 'http://www.example.com/test/pdfs/qwerty.pdf'
|
1035
|
+
}));
|
892
1036
|
var docBaseUrlPromise = docBaseUrlLoadingTask.promise.then(function (pdfDoc) {
|
893
1037
|
return pdfDoc.getPage(1).then(function (pdfPage) {
|
894
1038
|
return pdfPage.getAnnotations();
|
895
1039
|
});
|
896
1040
|
});
|
897
|
-
var invalidDocBaseUrlLoadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(filename, {
|
1041
|
+
var invalidDocBaseUrlLoadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(filename, {
|
1042
|
+
docBaseUrl: 'qwerty.pdf'
|
1043
|
+
}));
|
898
1044
|
var invalidDocBaseUrlPromise = invalidDocBaseUrlLoadingTask.promise.then(function (pdfDoc) {
|
899
1045
|
return pdfDoc.getPage(1).then(function (pdfPage) {
|
900
1046
|
return pdfPage.getAnnotations();
|
@@ -911,9 +1057,7 @@ describe('api', function () {
|
|
911
1057
|
expect(invalidDocBaseUrlAnnotations[0].url).toBeUndefined();
|
912
1058
|
expect(invalidDocBaseUrlAnnotations[0].unsafeUrl).toEqual('../../0021/002156/215675E.pdf#15');
|
913
1059
|
Promise.all([defaultLoadingTask.destroy(), docBaseUrlLoadingTask.destroy(), invalidDocBaseUrlLoadingTask.destroy()]).then(done);
|
914
|
-
}).catch(
|
915
|
-
done.fail(reason);
|
916
|
-
});
|
1060
|
+
}).catch(done.fail);
|
917
1061
|
});
|
918
1062
|
it('gets text content', function (done) {
|
919
1063
|
var defaultPromise = page.getTextContent();
|
@@ -928,9 +1072,35 @@ describe('api', function () {
|
|
928
1072
|
expect(!!data[0].styles).toEqual(true);
|
929
1073
|
expect(JSON.stringify(data[0])).toEqual(JSON.stringify(data[1]));
|
930
1074
|
done();
|
931
|
-
}).catch(
|
932
|
-
|
933
|
-
|
1075
|
+
}).catch(done.fail);
|
1076
|
+
});
|
1077
|
+
it('gets text content, with correct properties (issue 8276)', function (done) {
|
1078
|
+
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue8276_reduced.pdf'));
|
1079
|
+
loadingTask.promise.then(function (pdfDoc) {
|
1080
|
+
pdfDoc.getPage(1).then(function (pdfPage) {
|
1081
|
+
pdfPage.getTextContent().then(function (_ref3) {
|
1082
|
+
var items = _ref3.items,
|
1083
|
+
styles = _ref3.styles;
|
1084
|
+
expect(items.length).toEqual(1);
|
1085
|
+
expect(Object.keys(styles)).toEqual(['Times']);
|
1086
|
+
expect(items[0]).toEqual({
|
1087
|
+
dir: 'ltr',
|
1088
|
+
fontName: 'Times',
|
1089
|
+
height: 18,
|
1090
|
+
str: 'Issue 8276',
|
1091
|
+
transform: [18, 0, 0, 18, 441.81, 708.4499999999999],
|
1092
|
+
width: 77.49
|
1093
|
+
});
|
1094
|
+
expect(styles.Times).toEqual({
|
1095
|
+
fontFamily: 'serif',
|
1096
|
+
ascent: NaN,
|
1097
|
+
descent: NaN,
|
1098
|
+
vertical: false
|
1099
|
+
});
|
1100
|
+
loadingTask.destroy().then(done);
|
1101
|
+
});
|
1102
|
+
});
|
1103
|
+
}).catch(done.fail);
|
934
1104
|
});
|
935
1105
|
it('gets operator list', function (done) {
|
936
1106
|
var promise = page.getOperatorList();
|
@@ -939,9 +1109,7 @@ describe('api', function () {
|
|
939
1109
|
expect(!!oplist.argsArray).toEqual(true);
|
940
1110
|
expect(oplist.lastChunk).toEqual(true);
|
941
1111
|
done();
|
942
|
-
}).catch(
|
943
|
-
done.fail(reason);
|
944
|
-
});
|
1112
|
+
}).catch(done.fail);
|
945
1113
|
});
|
946
1114
|
it('gets operatorList with JPEG image (issue 4888)', function (done) {
|
947
1115
|
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('cmykjpeg.pdf'));
|
@@ -952,18 +1120,16 @@ describe('api', function () {
|
|
952
1120
|
var imgArgs = opList.argsArray[imgIndex];
|
953
1121
|
|
954
1122
|
var _pdfPage$objs$get = pdfPage.objs.get(imgArgs[0]),
|
955
|
-
|
1123
|
+
data = _pdfPage$objs$get.data;
|
956
1124
|
|
957
|
-
expect(
|
958
|
-
expect(
|
959
|
-
|
1125
|
+
expect(data instanceof Uint8ClampedArray).toEqual(true);
|
1126
|
+
expect(data.length).toEqual(90000);
|
1127
|
+
loadingTask.destroy().then(done);
|
960
1128
|
});
|
961
1129
|
});
|
962
|
-
}).catch(
|
963
|
-
done.fail(reason);
|
964
|
-
});
|
1130
|
+
}).catch(done.fail);
|
965
1131
|
});
|
966
|
-
it('gets stats after parsing page', function (done) {
|
1132
|
+
it('gets document stats after parsing page', function (done) {
|
967
1133
|
var promise = page.getOperatorList().then(function () {
|
968
1134
|
return pdfDocument.getStats();
|
969
1135
|
});
|
@@ -978,18 +1144,85 @@ describe('api', function () {
|
|
978
1144
|
fontTypes: expectedFontTypes
|
979
1145
|
});
|
980
1146
|
done();
|
981
|
-
}).catch(
|
982
|
-
|
983
|
-
|
1147
|
+
}).catch(done.fail);
|
1148
|
+
});
|
1149
|
+
it('gets page stats after parsing page, without `pdfBug` set', function (done) {
|
1150
|
+
page.getOperatorList().then(function (opList) {
|
1151
|
+
return page.stats;
|
1152
|
+
}).then(function (stats) {
|
1153
|
+
expect(stats).toEqual(null);
|
1154
|
+
done();
|
1155
|
+
}, done.fail);
|
1156
|
+
});
|
1157
|
+
it('gets page stats after parsing page, with `pdfBug` set', function (done) {
|
1158
|
+
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(basicApiFileName, {
|
1159
|
+
pdfBug: true
|
1160
|
+
}));
|
1161
|
+
loadingTask.promise.then(function (pdfDoc) {
|
1162
|
+
return pdfDoc.getPage(1).then(function (pdfPage) {
|
1163
|
+
return pdfPage.getOperatorList().then(function (opList) {
|
1164
|
+
return pdfPage.stats;
|
1165
|
+
});
|
1166
|
+
});
|
1167
|
+
}).then(function (stats) {
|
1168
|
+
expect(stats instanceof _dom_utils.StatTimer).toEqual(true);
|
1169
|
+
expect(stats.times.length).toEqual(1);
|
1170
|
+
|
1171
|
+
var _stats$times = _slicedToArray(stats.times, 1),
|
1172
|
+
statEntry = _stats$times[0];
|
1173
|
+
|
1174
|
+
expect(statEntry.name).toEqual('Page Request');
|
1175
|
+
expect(statEntry.end - statEntry.start).toBeGreaterThan(0);
|
1176
|
+
loadingTask.destroy().then(done);
|
1177
|
+
}, done.fail);
|
1178
|
+
});
|
1179
|
+
it('gets page stats after rendering page, with `pdfBug` set', function (done) {
|
1180
|
+
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(basicApiFileName, {
|
1181
|
+
pdfBug: true
|
1182
|
+
}));
|
1183
|
+
var canvasAndCtx;
|
1184
|
+
loadingTask.promise.then(function (pdfDoc) {
|
1185
|
+
return pdfDoc.getPage(1).then(function (pdfPage) {
|
1186
|
+
var viewport = pdfPage.getViewport({
|
1187
|
+
scale: 1
|
1188
|
+
});
|
1189
|
+
canvasAndCtx = CanvasFactory.create(viewport.width, viewport.height);
|
1190
|
+
var renderTask = pdfPage.render({
|
1191
|
+
canvasContext: canvasAndCtx.context,
|
1192
|
+
canvasFactory: CanvasFactory,
|
1193
|
+
viewport: viewport
|
1194
|
+
});
|
1195
|
+
return renderTask.promise.then(function () {
|
1196
|
+
return pdfPage.stats;
|
1197
|
+
});
|
1198
|
+
});
|
1199
|
+
}).then(function (stats) {
|
1200
|
+
expect(stats instanceof _dom_utils.StatTimer).toEqual(true);
|
1201
|
+
expect(stats.times.length).toEqual(3);
|
1202
|
+
|
1203
|
+
var _stats$times2 = _slicedToArray(stats.times, 3),
|
1204
|
+
statEntryOne = _stats$times2[0],
|
1205
|
+
statEntryTwo = _stats$times2[1],
|
1206
|
+
statEntryThree = _stats$times2[2];
|
1207
|
+
|
1208
|
+
expect(statEntryOne.name).toEqual('Page Request');
|
1209
|
+
expect(statEntryOne.end - statEntryOne.start).toBeGreaterThan(0);
|
1210
|
+
expect(statEntryTwo.name).toEqual('Rendering');
|
1211
|
+
expect(statEntryTwo.end - statEntryTwo.start).toBeGreaterThan(0);
|
1212
|
+
expect(statEntryThree.name).toEqual('Overall');
|
1213
|
+
expect(statEntryThree.end - statEntryThree.start).toBeGreaterThan(0);
|
1214
|
+
CanvasFactory.destroy(canvasAndCtx);
|
1215
|
+
loadingTask.destroy().then(done);
|
1216
|
+
}, done.fail);
|
984
1217
|
});
|
985
1218
|
it('cancels rendering of page', function (done) {
|
986
|
-
|
987
|
-
|
988
|
-
}
|
989
|
-
var viewport = page.getViewport(1);
|
1219
|
+
var viewport = page.getViewport({
|
1220
|
+
scale: 1
|
1221
|
+
});
|
990
1222
|
var canvasAndCtx = CanvasFactory.create(viewport.width, viewport.height);
|
991
1223
|
var renderTask = page.render({
|
992
1224
|
canvasContext: canvasAndCtx.context,
|
1225
|
+
canvasFactory: CanvasFactory,
|
993
1226
|
viewport: viewport
|
994
1227
|
});
|
995
1228
|
renderTask.cancel();
|
@@ -1002,18 +1235,46 @@ describe('api', function () {
|
|
1002
1235
|
done();
|
1003
1236
|
});
|
1004
1237
|
});
|
1238
|
+
it('re-render page, using the same canvas, after cancelling rendering', function (done) {
|
1239
|
+
var viewport = page.getViewport({
|
1240
|
+
scale: 1
|
1241
|
+
});
|
1242
|
+
var canvasAndCtx = CanvasFactory.create(viewport.width, viewport.height);
|
1243
|
+
var renderTask = page.render({
|
1244
|
+
canvasContext: canvasAndCtx.context,
|
1245
|
+
canvasFactory: CanvasFactory,
|
1246
|
+
viewport: viewport
|
1247
|
+
});
|
1248
|
+
renderTask.cancel();
|
1249
|
+
renderTask.promise.then(function () {
|
1250
|
+
throw new Error('shall cancel rendering');
|
1251
|
+
}, function (reason) {
|
1252
|
+
expect(reason instanceof _dom_utils.RenderingCancelledException).toEqual(true);
|
1253
|
+
}).then(function () {
|
1254
|
+
var reRenderTask = page.render({
|
1255
|
+
canvasContext: canvasAndCtx.context,
|
1256
|
+
canvasFactory: CanvasFactory,
|
1257
|
+
viewport: viewport
|
1258
|
+
});
|
1259
|
+
return reRenderTask.promise;
|
1260
|
+
}).then(function () {
|
1261
|
+
CanvasFactory.destroy(canvasAndCtx);
|
1262
|
+
done();
|
1263
|
+
}, done.fail);
|
1264
|
+
});
|
1005
1265
|
it('multiple render() on the same canvas', function (done) {
|
1006
|
-
|
1007
|
-
|
1008
|
-
}
|
1009
|
-
var viewport = page.getViewport(1);
|
1266
|
+
var viewport = page.getViewport({
|
1267
|
+
scale: 1
|
1268
|
+
});
|
1010
1269
|
var canvasAndCtx = CanvasFactory.create(viewport.width, viewport.height);
|
1011
1270
|
var renderTask1 = page.render({
|
1012
1271
|
canvasContext: canvasAndCtx.context,
|
1272
|
+
canvasFactory: CanvasFactory,
|
1013
1273
|
viewport: viewport
|
1014
1274
|
});
|
1015
1275
|
var renderTask2 = page.render({
|
1016
1276
|
canvasContext: canvasAndCtx.context,
|
1277
|
+
canvasFactory: CanvasFactory,
|
1017
1278
|
viewport: viewport
|
1018
1279
|
});
|
1019
1280
|
Promise.all([renderTask1.promise, renderTask2.promise.then(function () {
|
@@ -1029,25 +1290,60 @@ describe('api', function () {
|
|
1029
1290
|
var pdf3 = (0, _test_utils.buildGetDocumentParams)('issue6068.pdf');
|
1030
1291
|
var loadingTasks = [];
|
1031
1292
|
var pdfDocuments = [];
|
1032
|
-
|
1033
|
-
|
1034
|
-
|
1035
|
-
|
1036
|
-
|
1037
|
-
|
1038
|
-
|
1039
|
-
|
1040
|
-
|
1041
|
-
|
1042
|
-
|
1043
|
-
|
1044
|
-
|
1045
|
-
|
1046
|
-
|
1047
|
-
|
1048
|
-
|
1049
|
-
|
1293
|
+
|
1294
|
+
function renderPDF(_x) {
|
1295
|
+
return _renderPDF.apply(this, arguments);
|
1296
|
+
}
|
1297
|
+
|
1298
|
+
function _renderPDF() {
|
1299
|
+
_renderPDF = _asyncToGenerator(
|
1300
|
+
/*#__PURE__*/
|
1301
|
+
_regenerator.default.mark(function _callee(filename) {
|
1302
|
+
var loadingTask, pdf, page, viewport, canvasAndCtx, renderTask, data;
|
1303
|
+
return _regenerator.default.wrap(function _callee$(_context) {
|
1304
|
+
while (1) {
|
1305
|
+
switch (_context.prev = _context.next) {
|
1306
|
+
case 0:
|
1307
|
+
loadingTask = (0, _api.getDocument)(filename);
|
1308
|
+
loadingTasks.push(loadingTask);
|
1309
|
+
_context.next = 4;
|
1310
|
+
return loadingTask.promise;
|
1311
|
+
|
1312
|
+
case 4:
|
1313
|
+
pdf = _context.sent;
|
1314
|
+
pdfDocuments.push(pdf);
|
1315
|
+
_context.next = 8;
|
1316
|
+
return pdf.getPage(1);
|
1317
|
+
|
1318
|
+
case 8:
|
1319
|
+
page = _context.sent;
|
1320
|
+
viewport = page.getViewport({
|
1321
|
+
scale: 1.2
|
1322
|
+
});
|
1323
|
+
canvasAndCtx = CanvasFactory.create(viewport.width, viewport.height);
|
1324
|
+
renderTask = page.render({
|
1325
|
+
canvasContext: canvasAndCtx.context,
|
1326
|
+
canvasFactory: CanvasFactory,
|
1327
|
+
viewport: viewport
|
1328
|
+
});
|
1329
|
+
_context.next = 14;
|
1330
|
+
return renderTask.promise;
|
1331
|
+
|
1332
|
+
case 14:
|
1333
|
+
data = canvasAndCtx.canvas.toDataURL();
|
1334
|
+
CanvasFactory.destroy(canvasAndCtx);
|
1335
|
+
return _context.abrupt("return", data);
|
1336
|
+
|
1337
|
+
case 17:
|
1338
|
+
case "end":
|
1339
|
+
return _context.stop();
|
1340
|
+
}
|
1341
|
+
}
|
1342
|
+
}, _callee, this);
|
1343
|
+
}));
|
1344
|
+
return _renderPDF.apply(this, arguments);
|
1050
1345
|
}
|
1346
|
+
|
1051
1347
|
afterEach(function (done) {
|
1052
1348
|
var destroyPromises = pdfDocuments.map(function (pdfDocument) {
|
1053
1349
|
return pdfDocument.destroy();
|
@@ -1060,9 +1356,6 @@ describe('api', function () {
|
|
1060
1356
|
});
|
1061
1357
|
});
|
1062
1358
|
it('should correctly render PDFs in parallel', function (done) {
|
1063
|
-
if ((0, _is_node2.default)()) {
|
1064
|
-
pending('TODO: Support Canvas testing in Node.js.');
|
1065
|
-
}
|
1066
1359
|
var baseline1, baseline2, baseline3;
|
1067
1360
|
var promiseDone = renderPDF(pdf1).then(function (data1) {
|
1068
1361
|
baseline1 = data1;
|
@@ -1081,42 +1374,49 @@ describe('api', function () {
|
|
1081
1374
|
});
|
1082
1375
|
promiseDone.then(function () {
|
1083
1376
|
done();
|
1084
|
-
}).catch(
|
1085
|
-
done.fail(reason);
|
1086
|
-
});
|
1377
|
+
}).catch(done.fail);
|
1087
1378
|
});
|
1088
1379
|
});
|
1089
1380
|
describe('PDFDataRangeTransport', function () {
|
1090
1381
|
var loadPromise;
|
1382
|
+
|
1091
1383
|
function getDocumentData() {
|
1092
1384
|
var pdfPath = new URL('../pdfs/tracemonkey.pdf', window.location).href;
|
1385
|
+
|
1093
1386
|
if (loadPromise) {
|
1094
1387
|
return loadPromise;
|
1095
1388
|
}
|
1389
|
+
|
1096
1390
|
loadPromise = new Promise(function (resolve, reject) {
|
1097
1391
|
var xhr = new XMLHttpRequest(pdfPath);
|
1098
1392
|
xhr.open('GET', pdfPath);
|
1099
1393
|
xhr.responseType = 'arraybuffer';
|
1394
|
+
|
1100
1395
|
xhr.onload = function () {
|
1101
1396
|
resolve(new Uint8Array(xhr.response));
|
1102
1397
|
};
|
1398
|
+
|
1103
1399
|
xhr.onerror = function () {
|
1104
1400
|
reject(new Error('PDF is not loaded'));
|
1105
1401
|
};
|
1402
|
+
|
1106
1403
|
xhr.send();
|
1107
1404
|
});
|
1108
1405
|
return loadPromise;
|
1109
1406
|
}
|
1407
|
+
|
1110
1408
|
it('should fetch document info and page using ranges', function (done) {
|
1111
|
-
if ((0,
|
1409
|
+
if ((0, _is_node.default)()) {
|
1112
1410
|
pending('XMLHttpRequest is not supported in Node.js.');
|
1113
1411
|
}
|
1412
|
+
|
1114
1413
|
var transport;
|
1115
1414
|
var initialDataLength = 4000;
|
1116
1415
|
var fetches = 0;
|
1117
1416
|
var getDocumentPromise = getDocumentData().then(function (data) {
|
1118
1417
|
var initialData = data.subarray(0, initialDataLength);
|
1119
1418
|
transport = new _api.PDFDataRangeTransport(data.length, initialData);
|
1419
|
+
|
1120
1420
|
transport.requestDataRange = function (begin, end) {
|
1121
1421
|
fetches++;
|
1122
1422
|
waitSome(function () {
|
@@ -1124,6 +1424,7 @@ describe('api', function () {
|
|
1124
1424
|
transport.onDataRange(begin, data.subarray(begin, end));
|
1125
1425
|
});
|
1126
1426
|
};
|
1427
|
+
|
1127
1428
|
var loadingTask = (0, _api.getDocument)(transport);
|
1128
1429
|
return loadingTask.promise;
|
1129
1430
|
});
|
@@ -1138,29 +1439,32 @@ describe('api', function () {
|
|
1138
1439
|
expect(page.rotate).toEqual(0);
|
1139
1440
|
expect(fetches).toBeGreaterThan(2);
|
1140
1441
|
done();
|
1141
|
-
}).catch(
|
1142
|
-
done.fail(reason);
|
1143
|
-
});
|
1442
|
+
}).catch(done.fail);
|
1144
1443
|
});
|
1145
1444
|
it('should fetch document info and page using range and streaming', function (done) {
|
1146
|
-
if ((0,
|
1445
|
+
if ((0, _is_node.default)()) {
|
1147
1446
|
pending('XMLHttpRequest is not supported in Node.js.');
|
1148
1447
|
}
|
1448
|
+
|
1149
1449
|
var transport;
|
1150
1450
|
var initialDataLength = 4000;
|
1151
1451
|
var fetches = 0;
|
1152
1452
|
var getDocumentPromise = getDocumentData().then(function (data) {
|
1153
1453
|
var initialData = data.subarray(0, initialDataLength);
|
1154
1454
|
transport = new _api.PDFDataRangeTransport(data.length, initialData);
|
1455
|
+
|
1155
1456
|
transport.requestDataRange = function (begin, end) {
|
1156
1457
|
fetches++;
|
1458
|
+
|
1157
1459
|
if (fetches === 1) {
|
1158
1460
|
transport.onDataProgressiveRead(data.subarray(initialDataLength));
|
1159
1461
|
}
|
1462
|
+
|
1160
1463
|
waitSome(function () {
|
1161
1464
|
transport.onDataRange(begin, data.subarray(begin, end));
|
1162
1465
|
});
|
1163
1466
|
};
|
1467
|
+
|
1164
1468
|
var loadingTask = (0, _api.getDocument)(transport);
|
1165
1469
|
return loadingTask.promise;
|
1166
1470
|
});
|
@@ -1175,9 +1479,7 @@ describe('api', function () {
|
|
1175
1479
|
expect(page.rotate).toEqual(0);
|
1176
1480
|
expect(fetches).toEqual(1);
|
1177
1481
|
done();
|
1178
|
-
}).catch(
|
1179
|
-
done.fail(reason);
|
1180
|
-
});
|
1482
|
+
}).catch(done.fail);
|
1181
1483
|
});
|
1182
1484
|
});
|
1183
1485
|
});
|