pdfjs-dist 2.3.200 → 2.4.456
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/README.md +4 -0
- package/bower.json +1 -1
- package/build/pdf.js +6499 -17971
- package/build/pdf.js.map +1 -1
- package/build/pdf.min.js +22 -1
- package/build/pdf.worker.entry.js +5 -3
- package/build/pdf.worker.js +19303 -29896
- package/build/pdf.worker.js.map +1 -1
- package/build/pdf.worker.min.js +22 -1
- package/es5/build/pdf.js +25473 -0
- package/es5/build/pdf.js.map +1 -0
- package/{lib/shared/global_scope.js → es5/build/pdf.worker.entry.js} +5 -10
- package/es5/build/pdf.worker.js +57878 -0
- package/es5/build/pdf.worker.js.map +1 -0
- package/es5/web/images/annotation-check.svg +11 -0
- package/es5/web/images/annotation-comment.svg +16 -0
- package/es5/web/images/annotation-help.svg +26 -0
- package/es5/web/images/annotation-insert.svg +10 -0
- package/es5/web/images/annotation-key.svg +11 -0
- package/es5/web/images/annotation-newparagraph.svg +11 -0
- package/es5/web/images/annotation-noicon.svg +7 -0
- package/es5/web/images/annotation-note.svg +42 -0
- package/es5/web/images/annotation-paragraph.svg +16 -0
- package/es5/web/images/loading-icon.gif +0 -0
- package/es5/web/images/shadow.png +0 -0
- package/es5/web/images/texture.png +0 -0
- package/es5/web/pdf_viewer.css +407 -0
- package/es5/web/pdf_viewer.js +7757 -0
- package/es5/web/pdf_viewer.js.map +1 -0
- package/image_decoders/pdf.image_decoders.js +1333 -4839
- package/image_decoders/pdf.image_decoders.js.map +1 -1
- package/image_decoders/pdf.image_decoders.min.js +22 -1
- package/lib/README.md +7 -0
- package/lib/core/annotation.js +683 -1066
- package/lib/core/arithmetic_decoder.js +81 -97
- package/lib/core/bidi.js +54 -46
- package/lib/core/ccitt.js +88 -81
- package/lib/core/ccitt_stream.js +15 -14
- package/lib/core/cff_parser.js +196 -193
- package/lib/core/charsets.js +4 -4
- package/lib/core/chunked_stream.js +441 -569
- package/lib/core/cmap.js +220 -279
- package/lib/core/colorspace.js +699 -863
- package/lib/core/core_utils.js +59 -80
- package/lib/core/crypto.js +379 -437
- package/lib/core/document.js +564 -673
- package/lib/core/encodings.js +15 -15
- package/lib/core/evaluator.js +983 -889
- package/lib/core/font_renderer.js +128 -171
- package/lib/core/fonts.js +451 -400
- package/lib/core/function.js +289 -285
- package/lib/core/glyphlist.js +4527 -4527
- package/lib/core/image.js +138 -117
- package/lib/core/image_utils.js +46 -63
- package/lib/core/jbig2.js +324 -332
- package/lib/core/jbig2_stream.js +18 -17
- package/lib/core/jpeg_stream.js +133 -24
- package/lib/core/jpg.js +238 -210
- package/lib/core/jpx.js +158 -157
- package/lib/core/jpx_stream.js +28 -28
- package/lib/core/metrics.js +2928 -2928
- package/lib/core/murmurhash3.js +87 -102
- package/lib/core/obj.js +1111 -1302
- package/lib/core/operator_list.js +55 -42
- package/lib/core/parser.js +956 -987
- package/lib/core/pattern.js +69 -69
- package/lib/core/pdf_manager.js +149 -316
- package/lib/core/primitives.js +45 -77
- package/lib/core/ps_parser.js +175 -214
- package/lib/core/standard_fonts.js +237 -236
- package/lib/core/stream.js +83 -77
- package/lib/core/type1_parser.js +78 -68
- package/lib/core/unicode.js +1654 -1654
- package/lib/core/worker.js +148 -196
- package/lib/core/worker_stream.js +101 -210
- package/lib/display/annotation_layer.js +733 -1155
- package/lib/display/api.js +1539 -1928
- package/lib/display/api_compatibility.js +10 -8
- package/lib/display/canvas.js +159 -158
- package/lib/display/content_disposition.js +36 -55
- package/lib/display/display_utils.js +298 -551
- package/lib/display/fetch_stream.js +181 -305
- package/lib/display/font_loader.js +273 -416
- package/lib/display/metadata.js +86 -98
- package/lib/display/network.js +376 -511
- package/lib/display/network_utils.js +20 -19
- package/lib/display/node_stream.js +276 -460
- package/lib/display/pattern_helper.js +76 -44
- package/lib/display/svg.js +1137 -1405
- package/lib/display/text_layer.js +75 -82
- package/lib/display/transport_stream.js +236 -374
- package/lib/display/webgl.js +70 -83
- package/lib/display/worker_options.js +3 -3
- package/lib/display/xml_parser.js +303 -392
- package/lib/examples/node/domstubs.js +37 -37
- package/lib/pdf.js +22 -21
- package/lib/pdf.worker.js +5 -5
- package/lib/shared/compatibility.js +2 -251
- package/lib/shared/is_node.js +7 -6
- package/lib/shared/message_handler.js +222 -194
- package/lib/shared/util.js +269 -405
- package/lib/test/unit/annotation_spec.js +1089 -1014
- package/lib/test/unit/api_spec.js +617 -544
- package/lib/test/unit/bidi_spec.js +7 -7
- package/lib/test/unit/cff_parser_spec.js +63 -62
- package/lib/test/unit/clitests_helper.js +7 -9
- package/lib/test/unit/cmap_spec.js +84 -86
- package/lib/test/unit/colorspace_spec.js +154 -154
- package/lib/test/unit/core_utils_spec.js +125 -105
- package/lib/test/unit/crypto_spec.js +181 -181
- package/lib/test/unit/custom_spec.js +22 -24
- package/lib/test/unit/display_svg_spec.js +35 -36
- package/lib/test/unit/display_utils_spec.js +139 -149
- package/lib/test/unit/document_spec.js +16 -16
- package/lib/test/unit/encodings_spec.js +12 -34
- package/lib/test/unit/evaluator_spec.js +81 -95
- package/lib/test/unit/fetch_stream_spec.js +30 -30
- package/lib/test/unit/function_spec.js +206 -204
- package/lib/test/unit/jasmine-boot.js +48 -32
- package/lib/test/unit/message_handler_spec.js +172 -162
- package/lib/test/unit/metadata_spec.js +69 -69
- package/lib/test/unit/murmurhash3_spec.js +12 -12
- package/lib/test/unit/network_spec.js +12 -12
- package/lib/test/unit/network_utils_spec.js +152 -152
- package/lib/test/unit/node_stream_spec.js +74 -90
- package/lib/test/unit/parser_spec.js +107 -113
- package/lib/test/unit/pdf_find_controller_spec.js +55 -86
- package/lib/test/unit/pdf_find_utils_spec.js +32 -32
- package/lib/test/unit/pdf_history_spec.js +32 -32
- package/lib/test/unit/primitives_spec.js +117 -115
- package/lib/test/unit/stream_spec.js +16 -14
- package/lib/test/unit/test_utils.js +119 -285
- package/lib/test/unit/testreporter.js +19 -19
- package/lib/test/unit/type1_parser_spec.js +41 -41
- package/lib/test/unit/ui_utils_spec.js +318 -426
- package/lib/test/unit/unicode_spec.js +42 -42
- package/lib/test/unit/util_spec.js +122 -143
- package/lib/web/annotation_layer_builder.js +66 -103
- package/lib/web/app.js +1166 -1196
- package/lib/web/app_options.js +61 -77
- package/lib/web/base_viewer.js +804 -850
- package/lib/web/chromecom.js +164 -249
- package/lib/web/debugger.js +149 -205
- package/lib/web/download_manager.js +38 -57
- package/lib/web/firefox_print_service.js +35 -30
- package/lib/web/firefoxcom.js +175 -374
- package/lib/web/genericcom.js +26 -108
- package/lib/web/genericl10n.js +24 -153
- package/lib/web/grab_to_pan.js +30 -30
- package/lib/web/interfaces.js +80 -258
- package/lib/web/overlay_manager.js +70 -246
- package/lib/web/password_prompt.js +38 -64
- package/lib/web/pdf_attachment_viewer.js +105 -130
- package/lib/web/pdf_cursor_tools.js +75 -102
- package/lib/web/pdf_document_properties.js +227 -376
- package/lib/web/pdf_find_bar.js +137 -171
- package/lib/web/pdf_find_controller.js +492 -549
- package/lib/web/pdf_find_utils.js +13 -13
- package/lib/web/pdf_history.js +395 -406
- package/lib/web/pdf_link_service.js +302 -349
- package/lib/web/pdf_outline_viewer.js +148 -209
- package/lib/web/pdf_page_view.js +449 -507
- package/lib/web/pdf_presentation_mode.js +304 -357
- package/lib/web/pdf_print_service.js +90 -104
- package/lib/web/pdf_rendering_queue.js +87 -108
- package/lib/web/pdf_sidebar.js +264 -304
- package/lib/web/pdf_sidebar_resizer.js +92 -119
- package/lib/web/pdf_single_page_viewer.js +77 -126
- package/lib/web/pdf_thumbnail_view.js +276 -297
- package/lib/web/pdf_thumbnail_viewer.js +186 -206
- package/lib/web/pdf_viewer.component.js +20 -21
- package/lib/web/pdf_viewer.js +55 -115
- package/lib/web/preferences.js +66 -273
- package/lib/web/secondary_toolbar.js +164 -196
- package/lib/web/text_layer_builder.js +284 -317
- package/lib/web/toolbar.js +216 -211
- package/lib/web/ui_utils.js +303 -404
- package/lib/web/view_history.js +49 -222
- package/lib/web/viewer_compatibility.js +7 -5
- package/package.json +2 -9
- package/web/pdf_viewer.css +25 -18
- package/web/pdf_viewer.js +3481 -4764
- package/web/pdf_viewer.js.map +1 -1
- package/webpack.js +14 -5
- package/lib/shared/streams_polyfill.js +0 -43
@@ -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 2020 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.
|
@@ -21,45 +21,29 @@
|
|
21
21
|
*/
|
22
22
|
"use strict";
|
23
23
|
|
24
|
-
var
|
24
|
+
var _test_utils = require("./test_utils.js");
|
25
25
|
|
26
|
-
var
|
26
|
+
var _util = require("../../shared/util.js");
|
27
27
|
|
28
|
-
var
|
28
|
+
var _display_utils = require("../../display/display_utils.js");
|
29
29
|
|
30
|
-
var
|
30
|
+
var _api = require("../../display/api.js");
|
31
31
|
|
32
|
-
var
|
32
|
+
var _ui_utils = require("../../web/ui_utils.js");
|
33
33
|
|
34
|
-
var _worker_options = require("../../display/worker_options");
|
34
|
+
var _worker_options = require("../../display/worker_options.js");
|
35
35
|
|
36
|
-
var _is_node =
|
36
|
+
var _is_node = require("../../shared/is_node.js");
|
37
37
|
|
38
|
-
var _metadata = require("../../display/metadata");
|
38
|
+
var _metadata = require("../../display/metadata.js");
|
39
39
|
|
40
|
-
function
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
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) { if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) { return; } 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
|
-
|
56
|
-
describe('api', function () {
|
57
|
-
var basicApiFileName = 'basicapi.pdf';
|
58
|
-
var basicApiFileLength = 105779;
|
59
|
-
var basicApiGetDocumentParams = (0, _test_utils.buildGetDocumentParams)(basicApiFileName);
|
60
|
-
var CanvasFactory;
|
40
|
+
describe("api", function () {
|
41
|
+
const basicApiFileName = "basicapi.pdf";
|
42
|
+
const basicApiFileLength = 105779;
|
43
|
+
const basicApiGetDocumentParams = (0, _test_utils.buildGetDocumentParams)(basicApiFileName);
|
44
|
+
let CanvasFactory;
|
61
45
|
beforeAll(function (done) {
|
62
|
-
if (
|
46
|
+
if (_is_node.isNodeJS) {
|
63
47
|
CanvasFactory = new _test_utils.NodeCanvasFactory();
|
64
48
|
} else {
|
65
49
|
CanvasFactory = new _display_utils.DOMCanvasFactory();
|
@@ -79,8 +63,8 @@ describe('api', function () {
|
|
79
63
|
}, WAIT_TIMEOUT);
|
80
64
|
}
|
81
65
|
|
82
|
-
describe(
|
83
|
-
it(
|
66
|
+
describe("getDocument", function () {
|
67
|
+
it("creates pdf doc from URL", function (done) {
|
84
68
|
var loadingTask = (0, _api.getDocument)(basicApiGetDocumentParams);
|
85
69
|
var progressReportedCapability = (0, _util.createPromiseCapability)();
|
86
70
|
|
@@ -96,19 +80,19 @@ describe('api', function () {
|
|
96
80
|
expect(data[1] instanceof _api.PDFDocumentProxy).toEqual(true);
|
97
81
|
expect(loadingTask).toEqual(data[1].loadingTask);
|
98
82
|
loadingTask.destroy().then(done);
|
99
|
-
})
|
83
|
+
}).catch(done.fail);
|
100
84
|
});
|
101
|
-
it(
|
85
|
+
it("creates pdf doc from URL and aborts before worker initialized", function (done) {
|
102
86
|
var loadingTask = (0, _api.getDocument)(basicApiGetDocumentParams);
|
103
|
-
|
87
|
+
const destroyed = loadingTask.destroy();
|
104
88
|
loadingTask.promise.then(function (reason) {
|
105
|
-
done.fail(
|
106
|
-
})
|
89
|
+
done.fail("shall fail loading");
|
90
|
+
}).catch(function (reason) {
|
107
91
|
expect(true).toEqual(true);
|
108
92
|
destroyed.then(done);
|
109
93
|
});
|
110
94
|
});
|
111
|
-
it(
|
95
|
+
it("creates pdf doc from URL and aborts loading after worker initialized", function (done) {
|
112
96
|
var loadingTask = (0, _api.getDocument)(basicApiGetDocumentParams);
|
113
97
|
|
114
98
|
var destroyed = loadingTask._worker.promise.then(function () {
|
@@ -118,12 +102,12 @@ describe('api', function () {
|
|
118
102
|
destroyed.then(function (data) {
|
119
103
|
expect(true).toEqual(true);
|
120
104
|
done();
|
121
|
-
})
|
105
|
+
}).catch(done.fail);
|
122
106
|
});
|
123
|
-
it(
|
124
|
-
|
107
|
+
it("creates pdf doc from typed array", function (done) {
|
108
|
+
let typedArrayPdfPromise;
|
125
109
|
|
126
|
-
if (
|
110
|
+
if (_is_node.isNodeJS) {
|
127
111
|
typedArrayPdfPromise = _test_utils.NodeFileReaderFactory.fetch({
|
128
112
|
path: _test_utils.TEST_PDFS_PATH.node + basicApiFileName
|
129
113
|
});
|
@@ -133,10 +117,10 @@ describe('api', function () {
|
|
133
117
|
});
|
134
118
|
}
|
135
119
|
|
136
|
-
typedArrayPdfPromise.then(
|
120
|
+
typedArrayPdfPromise.then(typedArrayPdf => {
|
137
121
|
expect(typedArrayPdf.length).toEqual(basicApiFileLength);
|
138
|
-
|
139
|
-
|
122
|
+
const loadingTask = (0, _api.getDocument)(typedArrayPdf);
|
123
|
+
const progressReportedCapability = (0, _util.createPromiseCapability)();
|
140
124
|
|
141
125
|
loadingTask.onProgress = function (data) {
|
142
126
|
progressReportedCapability.resolve(data);
|
@@ -147,41 +131,42 @@ describe('api', function () {
|
|
147
131
|
expect(data[1].loaded / data[1].total).toEqual(1);
|
148
132
|
loadingTask.destroy().then(done);
|
149
133
|
});
|
150
|
-
})
|
134
|
+
}).catch(done.fail);
|
151
135
|
});
|
152
|
-
it(
|
153
|
-
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(
|
136
|
+
it("creates pdf doc from invalid PDF file", function (done) {
|
137
|
+
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("bug1020226.pdf"));
|
154
138
|
loadingTask.promise.then(function () {
|
155
|
-
done.fail(
|
156
|
-
})
|
157
|
-
expect(
|
139
|
+
done.fail("shall fail loading");
|
140
|
+
}).catch(function (reason) {
|
141
|
+
expect(reason instanceof _util.InvalidPDFException).toEqual(true);
|
142
|
+
expect(reason.message).toEqual("Invalid PDF structure.");
|
158
143
|
loadingTask.destroy().then(done);
|
159
144
|
});
|
160
145
|
});
|
161
|
-
it(
|
162
|
-
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(
|
146
|
+
it("creates pdf doc from non-existent URL", function (done) {
|
147
|
+
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("non-existent.pdf"));
|
163
148
|
loadingTask.promise.then(function (error) {
|
164
|
-
done.fail(
|
165
|
-
})
|
149
|
+
done.fail("shall fail loading");
|
150
|
+
}).catch(function (error) {
|
166
151
|
expect(error instanceof _util.MissingPDFException).toEqual(true);
|
167
152
|
loadingTask.destroy().then(done);
|
168
153
|
});
|
169
154
|
});
|
170
|
-
it(
|
171
|
-
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(
|
155
|
+
it("creates pdf doc from PDF file protected with user and owner password", function (done) {
|
156
|
+
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("pr6531_1.pdf"));
|
172
157
|
var passwordNeededCapability = (0, _util.createPromiseCapability)();
|
173
158
|
var passwordIncorrectCapability = (0, _util.createPromiseCapability)();
|
174
159
|
|
175
160
|
loadingTask.onPassword = function (updatePassword, reason) {
|
176
161
|
if (reason === _util.PasswordResponses.NEED_PASSWORD && !passwordNeededCapability.settled) {
|
177
162
|
passwordNeededCapability.resolve();
|
178
|
-
updatePassword(
|
163
|
+
updatePassword("qwerty");
|
179
164
|
return;
|
180
165
|
}
|
181
166
|
|
182
167
|
if (reason === _util.PasswordResponses.INCORRECT_PASSWORD && !passwordIncorrectCapability.settled) {
|
183
168
|
passwordIncorrectCapability.resolve();
|
184
|
-
updatePassword(
|
169
|
+
updatePassword("asdfasdf");
|
185
170
|
return;
|
186
171
|
}
|
187
172
|
|
@@ -192,34 +177,34 @@ describe('api', function () {
|
|
192
177
|
Promise.all(promises).then(function (data) {
|
193
178
|
expect(data[2] instanceof _api.PDFDocumentProxy).toEqual(true);
|
194
179
|
loadingTask.destroy().then(done);
|
195
|
-
})
|
180
|
+
}).catch(done.fail);
|
196
181
|
});
|
197
|
-
it(
|
198
|
-
var filename =
|
182
|
+
it("creates pdf doc from PDF file protected with only a user password", function (done) {
|
183
|
+
var filename = "pr6531_2.pdf";
|
199
184
|
var passwordNeededLoadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(filename, {
|
200
|
-
password:
|
185
|
+
password: ""
|
201
186
|
}));
|
202
187
|
var result1 = passwordNeededLoadingTask.promise.then(function () {
|
203
|
-
done.fail(
|
204
|
-
return Promise.reject(new Error(
|
188
|
+
done.fail("shall fail with no password");
|
189
|
+
return Promise.reject(new Error("loadingTask should be rejected"));
|
205
190
|
}, function (data) {
|
206
191
|
expect(data instanceof _util.PasswordException).toEqual(true);
|
207
192
|
expect(data.code).toEqual(_util.PasswordResponses.NEED_PASSWORD);
|
208
193
|
return passwordNeededLoadingTask.destroy();
|
209
194
|
});
|
210
195
|
var passwordIncorrectLoadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(filename, {
|
211
|
-
password:
|
196
|
+
password: "qwerty"
|
212
197
|
}));
|
213
198
|
var result2 = passwordIncorrectLoadingTask.promise.then(function () {
|
214
|
-
done.fail(
|
215
|
-
return Promise.reject(new Error(
|
199
|
+
done.fail("shall fail with wrong password");
|
200
|
+
return Promise.reject(new Error("loadingTask should be rejected"));
|
216
201
|
}, function (data) {
|
217
202
|
expect(data instanceof _util.PasswordException).toEqual(true);
|
218
203
|
expect(data.code).toEqual(_util.PasswordResponses.INCORRECT_PASSWORD);
|
219
204
|
return passwordIncorrectLoadingTask.destroy();
|
220
205
|
});
|
221
206
|
var passwordAcceptedLoadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(filename, {
|
222
|
-
password:
|
207
|
+
password: "asdfasdf"
|
223
208
|
}));
|
224
209
|
var result3 = passwordAcceptedLoadingTask.promise.then(function (data) {
|
225
210
|
expect(data instanceof _api.PDFDocumentProxy).toEqual(true);
|
@@ -227,15 +212,15 @@ describe('api', function () {
|
|
227
212
|
});
|
228
213
|
Promise.all([result1, result2, result3]).then(function () {
|
229
214
|
done();
|
230
|
-
})
|
215
|
+
}).catch(done.fail);
|
231
216
|
});
|
232
|
-
it(
|
233
|
-
var filename =
|
217
|
+
it("creates pdf doc from password protected PDF file and aborts/throws " + "in the onPassword callback (issue 7806)", function (done) {
|
218
|
+
var filename = "issue3371.pdf";
|
234
219
|
var passwordNeededLoadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(filename));
|
235
220
|
var passwordIncorrectLoadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(filename, {
|
236
|
-
password:
|
221
|
+
password: "qwerty"
|
237
222
|
}));
|
238
|
-
|
223
|
+
let passwordNeededDestroyed;
|
239
224
|
|
240
225
|
passwordNeededLoadingTask.onPassword = function (callback, reason) {
|
241
226
|
if (reason === _util.PasswordResponses.NEED_PASSWORD) {
|
@@ -247,8 +232,8 @@ describe('api', function () {
|
|
247
232
|
};
|
248
233
|
|
249
234
|
var result1 = passwordNeededLoadingTask.promise.then(function () {
|
250
|
-
done.fail(
|
251
|
-
return Promise.reject(new Error(
|
235
|
+
done.fail("shall fail since the loadingTask should be destroyed");
|
236
|
+
return Promise.reject(new Error("loadingTask should be rejected"));
|
252
237
|
}, function (reason) {
|
253
238
|
expect(reason instanceof _util.PasswordException).toEqual(true);
|
254
239
|
expect(reason.code).toEqual(_util.PasswordResponses.NEED_PASSWORD);
|
@@ -257,15 +242,15 @@ describe('api', function () {
|
|
257
242
|
|
258
243
|
passwordIncorrectLoadingTask.onPassword = function (callback, reason) {
|
259
244
|
if (reason === _util.PasswordResponses.INCORRECT_PASSWORD) {
|
260
|
-
throw new Error(
|
245
|
+
throw new Error("Incorrect password");
|
261
246
|
}
|
262
247
|
|
263
248
|
expect(false).toEqual(true);
|
264
249
|
};
|
265
250
|
|
266
251
|
var result2 = passwordIncorrectLoadingTask.promise.then(function () {
|
267
|
-
done.fail(
|
268
|
-
return Promise.reject(new Error(
|
252
|
+
done.fail("shall fail since the onPassword callback should throw");
|
253
|
+
return Promise.reject(new Error("loadingTask should be rejected"));
|
269
254
|
}, function (reason) {
|
270
255
|
expect(reason instanceof _util.PasswordException).toEqual(true);
|
271
256
|
expect(reason.code).toEqual(_util.PasswordResponses.INCORRECT_PASSWORD);
|
@@ -273,20 +258,30 @@ describe('api', function () {
|
|
273
258
|
});
|
274
259
|
Promise.all([result1, result2]).then(function () {
|
275
260
|
done();
|
276
|
-
})
|
261
|
+
}).catch(done.fail);
|
262
|
+
});
|
263
|
+
it("creates pdf doc from empty typed array", function (done) {
|
264
|
+
const loadingTask = (0, _api.getDocument)(new Uint8Array(0));
|
265
|
+
loadingTask.promise.then(function () {
|
266
|
+
done.fail("shall not open empty file");
|
267
|
+
}, function (reason) {
|
268
|
+
expect(reason instanceof _util.InvalidPDFException);
|
269
|
+
expect(reason.message).toEqual("The PDF file is empty, i.e. its size is zero bytes.");
|
270
|
+
loadingTask.destroy().then(done);
|
271
|
+
});
|
277
272
|
});
|
278
273
|
});
|
279
|
-
describe(
|
280
|
-
it(
|
281
|
-
if (
|
282
|
-
pending(
|
274
|
+
describe("PDFWorker", function () {
|
275
|
+
it("worker created or destroyed", function (done) {
|
276
|
+
if (_is_node.isNodeJS) {
|
277
|
+
pending("Worker is not supported in Node.js.");
|
283
278
|
}
|
284
279
|
|
285
280
|
var worker = new _api.PDFWorker({
|
286
|
-
name:
|
281
|
+
name: "test1"
|
287
282
|
});
|
288
283
|
worker.promise.then(function () {
|
289
|
-
expect(worker.name).toEqual(
|
284
|
+
expect(worker.name).toEqual("test1");
|
290
285
|
expect(!!worker.port).toEqual(true);
|
291
286
|
expect(worker.destroyed).toEqual(false);
|
292
287
|
expect(!!worker._webWorker).toEqual(true);
|
@@ -295,11 +290,11 @@ describe('api', function () {
|
|
295
290
|
expect(!!worker.port).toEqual(false);
|
296
291
|
expect(worker.destroyed).toEqual(true);
|
297
292
|
done();
|
298
|
-
})
|
293
|
+
}).catch(done.fail);
|
299
294
|
});
|
300
|
-
it(
|
301
|
-
if (
|
302
|
-
pending(
|
295
|
+
it("worker created or destroyed by getDocument", function (done) {
|
296
|
+
if (_is_node.isNodeJS) {
|
297
|
+
pending("Worker is not supported in Node.js.");
|
303
298
|
}
|
304
299
|
|
305
300
|
var loadingTask = (0, _api.getDocument)(basicApiGetDocumentParams);
|
@@ -316,18 +311,18 @@ describe('api', function () {
|
|
316
311
|
expect(!!destroyedWorker).toEqual(false);
|
317
312
|
expect(worker.destroyed).toEqual(true);
|
318
313
|
done();
|
319
|
-
})
|
314
|
+
}).catch(done.fail);
|
320
315
|
});
|
321
|
-
it(
|
322
|
-
if (
|
323
|
-
pending(
|
316
|
+
it("worker created and can be used in getDocument", function (done) {
|
317
|
+
if (_is_node.isNodeJS) {
|
318
|
+
pending("Worker is not supported in Node.js.");
|
324
319
|
}
|
325
320
|
|
326
321
|
var worker = new _api.PDFWorker({
|
327
|
-
name:
|
322
|
+
name: "test1"
|
328
323
|
});
|
329
324
|
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(basicApiFileName, {
|
330
|
-
worker
|
325
|
+
worker
|
331
326
|
}));
|
332
327
|
loadingTask.promise.then(function () {
|
333
328
|
var docWorker = loadingTask._worker;
|
@@ -342,21 +337,21 @@ describe('api', function () {
|
|
342
337
|
expect(worker.destroyed).toEqual(false);
|
343
338
|
worker.destroy();
|
344
339
|
done();
|
345
|
-
})
|
340
|
+
}).catch(done.fail);
|
346
341
|
});
|
347
|
-
it(
|
348
|
-
if (
|
349
|
-
pending(
|
342
|
+
it("creates more than one worker", function (done) {
|
343
|
+
if (_is_node.isNodeJS) {
|
344
|
+
pending("Worker is not supported in Node.js.");
|
350
345
|
}
|
351
346
|
|
352
347
|
var worker1 = new _api.PDFWorker({
|
353
|
-
name:
|
348
|
+
name: "test1"
|
354
349
|
});
|
355
350
|
var worker2 = new _api.PDFWorker({
|
356
|
-
name:
|
351
|
+
name: "test2"
|
357
352
|
});
|
358
353
|
var worker3 = new _api.PDFWorker({
|
359
|
-
name:
|
354
|
+
name: "test3"
|
360
355
|
});
|
361
356
|
var ready = Promise.all([worker1.promise, worker2.promise, worker3.promise]);
|
362
357
|
ready.then(function () {
|
@@ -365,20 +360,20 @@ describe('api', function () {
|
|
365
360
|
worker2.destroy();
|
366
361
|
worker3.destroy();
|
367
362
|
done();
|
368
|
-
})
|
363
|
+
}).catch(done.fail);
|
369
364
|
});
|
370
|
-
it(
|
371
|
-
if (
|
372
|
-
pending(
|
365
|
+
it("gets current workerSrc", function () {
|
366
|
+
if (_is_node.isNodeJS) {
|
367
|
+
pending("Worker is not supported in Node.js.");
|
373
368
|
}
|
374
369
|
|
375
|
-
|
370
|
+
const workerSrc = _api.PDFWorker.getWorkerSrc();
|
376
371
|
|
377
|
-
expect(
|
372
|
+
expect(typeof workerSrc).toEqual("string");
|
378
373
|
expect(workerSrc).toEqual(_worker_options.GlobalWorkerOptions.workerSrc);
|
379
374
|
});
|
380
375
|
});
|
381
|
-
describe(
|
376
|
+
describe("PDFDocument", function () {
|
382
377
|
var loadingTask;
|
383
378
|
var doc;
|
384
379
|
beforeAll(function (done) {
|
@@ -391,44 +386,69 @@ describe('api', function () {
|
|
391
386
|
afterAll(function (done) {
|
392
387
|
loadingTask.destroy().then(done);
|
393
388
|
});
|
394
|
-
it(
|
389
|
+
it("gets number of pages", function () {
|
395
390
|
expect(doc.numPages).toEqual(3);
|
396
391
|
});
|
397
|
-
it(
|
398
|
-
expect(doc.fingerprint).toEqual(
|
392
|
+
it("gets fingerprint", function () {
|
393
|
+
expect(doc.fingerprint).toEqual("ea8b35919d6279a369e835bde778611b");
|
399
394
|
});
|
400
|
-
it(
|
395
|
+
it("gets page", function (done) {
|
401
396
|
var promise = doc.getPage(1);
|
402
397
|
promise.then(function (data) {
|
403
398
|
expect(data instanceof _api.PDFPageProxy).toEqual(true);
|
404
|
-
expect(data.
|
399
|
+
expect(data.pageNumber).toEqual(1);
|
405
400
|
done();
|
406
|
-
})
|
401
|
+
}).catch(done.fail);
|
407
402
|
});
|
408
|
-
it(
|
403
|
+
it("gets non-existent page", function (done) {
|
409
404
|
var outOfRangePromise = doc.getPage(100);
|
410
405
|
var nonIntegerPromise = doc.getPage(2.5);
|
411
|
-
var nonNumberPromise = doc.getPage(
|
406
|
+
var nonNumberPromise = doc.getPage("1");
|
412
407
|
outOfRangePromise = outOfRangePromise.then(function () {
|
413
|
-
throw new Error(
|
408
|
+
throw new Error("shall fail for out-of-range pageNumber parameter");
|
414
409
|
}, function (reason) {
|
415
410
|
expect(reason instanceof Error).toEqual(true);
|
416
411
|
});
|
417
412
|
nonIntegerPromise = nonIntegerPromise.then(function () {
|
418
|
-
throw new Error(
|
413
|
+
throw new Error("shall fail for non-integer pageNumber parameter");
|
419
414
|
}, function (reason) {
|
420
415
|
expect(reason instanceof Error).toEqual(true);
|
421
416
|
});
|
422
417
|
nonNumberPromise = nonNumberPromise.then(function () {
|
423
|
-
throw new Error(
|
418
|
+
throw new Error("shall fail for non-number pageNumber parameter");
|
424
419
|
}, function (reason) {
|
425
420
|
expect(reason instanceof Error).toEqual(true);
|
426
421
|
});
|
427
422
|
Promise.all([outOfRangePromise, nonIntegerPromise, nonNumberPromise]).then(function () {
|
428
423
|
done();
|
429
|
-
})
|
424
|
+
}).catch(done.fail);
|
430
425
|
});
|
431
|
-
it(
|
426
|
+
it("gets page, from /Pages tree with circular reference", function (done) {
|
427
|
+
const loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("Pages-tree-refs.pdf"));
|
428
|
+
const page1 = loadingTask.promise.then(function (pdfDoc) {
|
429
|
+
return pdfDoc.getPage(1).then(function (pdfPage) {
|
430
|
+
expect(pdfPage instanceof _api.PDFPageProxy).toEqual(true);
|
431
|
+
expect(pdfPage.ref).toEqual({
|
432
|
+
num: 6,
|
433
|
+
gen: 0
|
434
|
+
});
|
435
|
+
}, function (reason) {
|
436
|
+
throw new Error("shall not fail for valid page");
|
437
|
+
});
|
438
|
+
});
|
439
|
+
const page2 = loadingTask.promise.then(function (pdfDoc) {
|
440
|
+
return pdfDoc.getPage(2).then(function (pdfPage) {
|
441
|
+
throw new Error("shall fail for invalid page");
|
442
|
+
}, function (reason) {
|
443
|
+
expect(reason instanceof Error).toEqual(true);
|
444
|
+
expect(reason.message).toEqual("Pages tree contains circular reference.");
|
445
|
+
});
|
446
|
+
});
|
447
|
+
Promise.all([page1, page2]).then(function () {
|
448
|
+
loadingTask.destroy().then(done);
|
449
|
+
}, done.fail);
|
450
|
+
});
|
451
|
+
it("gets page index", function (done) {
|
432
452
|
var ref = {
|
433
453
|
num: 17,
|
434
454
|
gen: 0
|
@@ -437,22 +457,22 @@ describe('api', function () {
|
|
437
457
|
promise.then(function (pageIndex) {
|
438
458
|
expect(pageIndex).toEqual(1);
|
439
459
|
done();
|
440
|
-
})
|
460
|
+
}).catch(done.fail);
|
441
461
|
});
|
442
|
-
it(
|
462
|
+
it("gets invalid page index", function (done) {
|
443
463
|
var ref = {
|
444
464
|
num: 3,
|
445
465
|
gen: 0
|
446
466
|
};
|
447
467
|
var promise = doc.getPageIndex(ref);
|
448
468
|
promise.then(function () {
|
449
|
-
done.fail(
|
450
|
-
})
|
469
|
+
done.fail("shall fail for invalid page reference.");
|
470
|
+
}).catch(function (reason) {
|
451
471
|
expect(reason instanceof Error).toEqual(true);
|
452
472
|
done();
|
453
473
|
});
|
454
474
|
});
|
455
|
-
it(
|
475
|
+
it("gets destinations, from /Dests dictionary", function (done) {
|
456
476
|
var promise = doc.getDestinations();
|
457
477
|
promise.then(function (data) {
|
458
478
|
expect(data).toEqual({
|
@@ -460,270 +480,278 @@ describe('api', function () {
|
|
460
480
|
gen: 0,
|
461
481
|
num: 17
|
462
482
|
}, {
|
463
|
-
name:
|
483
|
+
name: "XYZ"
|
464
484
|
}, 0, 841.89, null]
|
465
485
|
});
|
466
486
|
done();
|
467
|
-
})
|
487
|
+
}).catch(done.fail);
|
468
488
|
});
|
469
|
-
it(
|
470
|
-
var promise = doc.getDestination(
|
489
|
+
it("gets a destination, from /Dests dictionary", function (done) {
|
490
|
+
var promise = doc.getDestination("chapter1");
|
471
491
|
promise.then(function (data) {
|
472
492
|
expect(data).toEqual([{
|
473
493
|
gen: 0,
|
474
494
|
num: 17
|
475
495
|
}, {
|
476
|
-
name:
|
496
|
+
name: "XYZ"
|
477
497
|
}, 0, 841.89, null]);
|
478
498
|
done();
|
479
|
-
})
|
499
|
+
}).catch(done.fail);
|
480
500
|
});
|
481
|
-
it(
|
482
|
-
var promise = doc.getDestination(
|
501
|
+
it("gets a non-existent destination, from /Dests dictionary", function (done) {
|
502
|
+
var promise = doc.getDestination("non-existent-named-destination");
|
483
503
|
promise.then(function (data) {
|
484
504
|
expect(data).toEqual(null);
|
485
505
|
done();
|
486
|
-
})
|
506
|
+
}).catch(done.fail);
|
487
507
|
});
|
488
|
-
it(
|
489
|
-
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(
|
508
|
+
it("gets destinations, from /Names (NameTree) dictionary", function (done) {
|
509
|
+
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("issue6204.pdf"));
|
490
510
|
var promise = loadingTask.promise.then(function (pdfDocument) {
|
491
511
|
return pdfDocument.getDestinations();
|
492
512
|
});
|
493
513
|
promise.then(function (destinations) {
|
494
514
|
expect(destinations).toEqual({
|
495
|
-
|
515
|
+
"Page.1": [{
|
496
516
|
num: 1,
|
497
517
|
gen: 0
|
498
518
|
}, {
|
499
|
-
name:
|
519
|
+
name: "XYZ"
|
500
520
|
}, 0, 375, null],
|
501
|
-
|
521
|
+
"Page.2": [{
|
502
522
|
num: 6,
|
503
523
|
gen: 0
|
504
524
|
}, {
|
505
|
-
name:
|
525
|
+
name: "XYZ"
|
506
526
|
}, 0, 375, null]
|
507
527
|
});
|
508
528
|
loadingTask.destroy().then(done);
|
509
|
-
})
|
529
|
+
}).catch(done.fail);
|
510
530
|
});
|
511
|
-
it(
|
512
|
-
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(
|
531
|
+
it("gets a destination, from /Names (NameTree) dictionary", function (done) {
|
532
|
+
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("issue6204.pdf"));
|
513
533
|
var promise = loadingTask.promise.then(function (pdfDocument) {
|
514
|
-
return pdfDocument.getDestination(
|
534
|
+
return pdfDocument.getDestination("Page.1");
|
515
535
|
});
|
516
536
|
promise.then(function (destination) {
|
517
537
|
expect(destination).toEqual([{
|
518
538
|
num: 1,
|
519
539
|
gen: 0
|
520
540
|
}, {
|
521
|
-
name:
|
541
|
+
name: "XYZ"
|
522
542
|
}, 0, 375, null]);
|
523
543
|
loadingTask.destroy().then(done);
|
524
|
-
})
|
544
|
+
}).catch(done.fail);
|
525
545
|
});
|
526
|
-
it(
|
527
|
-
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(
|
546
|
+
it("gets a non-existent destination, from /Names (NameTree) dictionary", function (done) {
|
547
|
+
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("issue6204.pdf"));
|
528
548
|
var promise = loadingTask.promise.then(function (pdfDocument) {
|
529
|
-
return pdfDocument.getDestination(
|
549
|
+
return pdfDocument.getDestination("non-existent-named-destination");
|
530
550
|
});
|
531
551
|
promise.then(function (destination) {
|
532
552
|
expect(destination).toEqual(null);
|
533
553
|
loadingTask.destroy().then(done);
|
534
|
-
})
|
554
|
+
}).catch(done.fail);
|
535
555
|
});
|
536
|
-
it(
|
537
|
-
|
538
|
-
|
539
|
-
|
556
|
+
it("gets non-string destination", function (done) {
|
557
|
+
let numberPromise = doc.getDestination(4.3);
|
558
|
+
let booleanPromise = doc.getDestination(true);
|
559
|
+
let arrayPromise = doc.getDestination([{
|
540
560
|
num: 17,
|
541
561
|
gen: 0
|
542
562
|
}, {
|
543
|
-
name:
|
563
|
+
name: "XYZ"
|
544
564
|
}, 0, 841.89, null]);
|
545
565
|
numberPromise = numberPromise.then(function () {
|
546
|
-
throw new Error(
|
566
|
+
throw new Error("shall fail for non-string destination.");
|
547
567
|
}, function (reason) {
|
548
568
|
expect(reason instanceof Error).toEqual(true);
|
549
569
|
});
|
550
570
|
booleanPromise = booleanPromise.then(function () {
|
551
|
-
throw new Error(
|
571
|
+
throw new Error("shall fail for non-string destination.");
|
552
572
|
}, function (reason) {
|
553
573
|
expect(reason instanceof Error).toEqual(true);
|
554
574
|
});
|
555
575
|
arrayPromise = arrayPromise.then(function () {
|
556
|
-
throw new Error(
|
576
|
+
throw new Error("shall fail for non-string destination.");
|
557
577
|
}, function (reason) {
|
558
578
|
expect(reason instanceof Error).toEqual(true);
|
559
579
|
});
|
560
580
|
Promise.all([numberPromise, booleanPromise, arrayPromise]).then(done, done.fail);
|
561
581
|
});
|
562
|
-
it(
|
582
|
+
it("gets non-existent page labels", function (done) {
|
563
583
|
var promise = doc.getPageLabels();
|
564
584
|
promise.then(function (data) {
|
565
585
|
expect(data).toEqual(null);
|
566
586
|
done();
|
567
|
-
})
|
587
|
+
}).catch(done.fail);
|
568
588
|
});
|
569
|
-
it(
|
570
|
-
var loadingTask0 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(
|
589
|
+
it("gets page labels", function (done) {
|
590
|
+
var loadingTask0 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("bug793632.pdf"));
|
571
591
|
var promise0 = loadingTask0.promise.then(function (pdfDoc) {
|
572
592
|
return pdfDoc.getPageLabels();
|
573
593
|
});
|
574
|
-
var loadingTask1 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(
|
594
|
+
var loadingTask1 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("issue1453.pdf"));
|
575
595
|
var promise1 = loadingTask1.promise.then(function (pdfDoc) {
|
576
596
|
return pdfDoc.getPageLabels();
|
577
597
|
});
|
578
|
-
var loadingTask2 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(
|
598
|
+
var loadingTask2 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("rotation.pdf"));
|
579
599
|
var promise2 = loadingTask2.promise.then(function (pdfDoc) {
|
580
600
|
return pdfDoc.getPageLabels();
|
581
601
|
});
|
582
|
-
var loadingTask3 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(
|
602
|
+
var loadingTask3 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("bad-PageLabels.pdf"));
|
583
603
|
var promise3 = loadingTask3.promise.then(function (pdfDoc) {
|
584
604
|
return pdfDoc.getPageLabels();
|
585
605
|
});
|
586
606
|
Promise.all([promise0, promise1, promise2, promise3]).then(function (pageLabels) {
|
587
|
-
expect(pageLabels[0]).toEqual([
|
588
|
-
expect(pageLabels[1]).toEqual([
|
589
|
-
expect(pageLabels[2]).toEqual([
|
590
|
-
expect(pageLabels[3]).toEqual([
|
607
|
+
expect(pageLabels[0]).toEqual(["i", "ii", "iii", "1"]);
|
608
|
+
expect(pageLabels[1]).toEqual(["Front Page1"]);
|
609
|
+
expect(pageLabels[2]).toEqual(["1", "2"]);
|
610
|
+
expect(pageLabels[3]).toEqual(["X3"]);
|
591
611
|
Promise.all([loadingTask0.destroy(), loadingTask1.destroy(), loadingTask2.destroy(), loadingTask3.destroy()]).then(done);
|
592
|
-
})
|
612
|
+
}).catch(done.fail);
|
593
613
|
});
|
594
|
-
it(
|
595
|
-
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(
|
614
|
+
it("gets default page layout", function (done) {
|
615
|
+
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("tracemonkey.pdf"));
|
596
616
|
loadingTask.promise.then(function (pdfDocument) {
|
597
617
|
return pdfDocument.getPageLayout();
|
598
618
|
}).then(function (mode) {
|
599
|
-
expect(mode).toEqual(
|
619
|
+
expect(mode).toEqual("");
|
600
620
|
loadingTask.destroy().then(done);
|
601
|
-
})
|
621
|
+
}).catch(done.fail);
|
602
622
|
});
|
603
|
-
it(
|
623
|
+
it("gets non-default page layout", function (done) {
|
604
624
|
doc.getPageLayout().then(function (mode) {
|
605
|
-
expect(mode).toEqual(
|
625
|
+
expect(mode).toEqual("SinglePage");
|
606
626
|
done();
|
607
|
-
})
|
627
|
+
}).catch(done.fail);
|
608
628
|
});
|
609
|
-
it(
|
610
|
-
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(
|
629
|
+
it("gets default page mode", function (done) {
|
630
|
+
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("tracemonkey.pdf"));
|
611
631
|
loadingTask.promise.then(function (pdfDocument) {
|
612
632
|
return pdfDocument.getPageMode();
|
613
633
|
}).then(function (mode) {
|
614
|
-
expect(mode).toEqual(
|
634
|
+
expect(mode).toEqual("UseNone");
|
615
635
|
loadingTask.destroy().then(done);
|
616
|
-
})
|
636
|
+
}).catch(done.fail);
|
617
637
|
});
|
618
|
-
it(
|
638
|
+
it("gets non-default page mode", function (done) {
|
619
639
|
doc.getPageMode().then(function (mode) {
|
620
|
-
expect(mode).toEqual(
|
640
|
+
expect(mode).toEqual("UseOutlines");
|
621
641
|
done();
|
622
|
-
})
|
642
|
+
}).catch(done.fail);
|
623
643
|
});
|
624
|
-
it(
|
625
|
-
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(
|
644
|
+
it("gets default viewer preferences", function (done) {
|
645
|
+
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("tracemonkey.pdf"));
|
626
646
|
loadingTask.promise.then(function (pdfDocument) {
|
627
647
|
return pdfDocument.getViewerPreferences();
|
628
648
|
}).then(function (prefs) {
|
629
|
-
expect(
|
649
|
+
expect(typeof prefs === "object" && prefs !== null && (0, _util.isEmptyObj)(prefs)).toEqual(true);
|
630
650
|
loadingTask.destroy().then(done);
|
631
|
-
})
|
651
|
+
}).catch(done.fail);
|
632
652
|
});
|
633
|
-
it(
|
653
|
+
it("gets non-default viewer preferences", function (done) {
|
634
654
|
doc.getViewerPreferences().then(function (prefs) {
|
635
655
|
expect(prefs).toEqual({
|
636
|
-
Direction:
|
656
|
+
Direction: "L2R"
|
637
657
|
});
|
638
658
|
done();
|
639
|
-
})
|
659
|
+
}).catch(done.fail);
|
640
660
|
});
|
641
|
-
it(
|
642
|
-
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(
|
661
|
+
it("gets default open action", function (done) {
|
662
|
+
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("tracemonkey.pdf"));
|
643
663
|
loadingTask.promise.then(function (pdfDocument) {
|
644
|
-
return pdfDocument.
|
645
|
-
}).then(function (
|
646
|
-
expect(
|
664
|
+
return pdfDocument.getOpenAction();
|
665
|
+
}).then(function (openAction) {
|
666
|
+
expect(openAction).toEqual(null);
|
647
667
|
loadingTask.destroy().then(done);
|
648
|
-
})
|
668
|
+
}).catch(done.fail);
|
649
669
|
});
|
650
|
-
it(
|
651
|
-
doc.
|
652
|
-
expect(dest).toEqual([{
|
670
|
+
it("gets non-default open action (with destination)", function (done) {
|
671
|
+
doc.getOpenAction().then(function (openAction) {
|
672
|
+
expect(openAction.dest).toEqual([{
|
653
673
|
num: 15,
|
654
674
|
gen: 0
|
655
675
|
}, {
|
656
|
-
name:
|
676
|
+
name: "FitH"
|
657
677
|
}, null]);
|
678
|
+
expect(openAction.action).toBeUndefined();
|
658
679
|
done();
|
659
|
-
})
|
660
|
-
});
|
661
|
-
it(
|
680
|
+
}).catch(done.fail);
|
681
|
+
});
|
682
|
+
it("gets non-default open action (with Print action)", function (done) {
|
683
|
+
const loadingTask1 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("bug1001080.pdf"));
|
684
|
+
const loadingTask2 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("issue11442_reduced.pdf"));
|
685
|
+
const promise1 = loadingTask1.promise.then(function (pdfDocument) {
|
686
|
+
return pdfDocument.getOpenAction();
|
687
|
+
}).then(function (openAction) {
|
688
|
+
expect(openAction.dest).toBeUndefined();
|
689
|
+
expect(openAction.action).toEqual("Print");
|
690
|
+
return loadingTask1.destroy();
|
691
|
+
});
|
692
|
+
const promise2 = loadingTask2.promise.then(function (pdfDocument) {
|
693
|
+
return pdfDocument.getOpenAction();
|
694
|
+
}).then(function (openAction) {
|
695
|
+
expect(openAction.dest).toBeUndefined();
|
696
|
+
expect(openAction.action).toEqual("Print");
|
697
|
+
return loadingTask2.destroy();
|
698
|
+
});
|
699
|
+
Promise.all([promise1, promise2]).then(done, done.fail);
|
700
|
+
});
|
701
|
+
it("gets non-existent attachments", function (done) {
|
662
702
|
var promise = doc.getAttachments();
|
663
703
|
promise.then(function (data) {
|
664
704
|
expect(data).toEqual(null);
|
665
705
|
done();
|
666
|
-
})
|
706
|
+
}).catch(done.fail);
|
667
707
|
});
|
668
|
-
it(
|
669
|
-
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(
|
708
|
+
it("gets attachments", function (done) {
|
709
|
+
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("attachment.pdf"));
|
670
710
|
var promise = loadingTask.promise.then(function (pdfDoc) {
|
671
711
|
return pdfDoc.getAttachments();
|
672
712
|
});
|
673
713
|
promise.then(function (data) {
|
674
|
-
var attachment = data[
|
675
|
-
expect(attachment.filename).toEqual(
|
714
|
+
var attachment = data["foo.txt"];
|
715
|
+
expect(attachment.filename).toEqual("foo.txt");
|
676
716
|
expect(attachment.content).toEqual(new Uint8Array([98, 97, 114, 32, 98, 97, 122, 32, 10]));
|
677
717
|
loadingTask.destroy().then(done);
|
678
|
-
})
|
718
|
+
}).catch(done.fail);
|
679
719
|
});
|
680
|
-
it(
|
720
|
+
it("gets javascript", function (done) {
|
681
721
|
var promise = doc.getJavaScript();
|
682
722
|
promise.then(function (data) {
|
683
723
|
expect(data).toEqual(null);
|
684
724
|
done();
|
685
|
-
})
|
725
|
+
}).catch(done.fail);
|
686
726
|
});
|
687
|
-
|
688
|
-
|
689
|
-
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('bug1001080.pdf'));
|
727
|
+
it("gets javascript with printing instructions (JS action)", function (done) {
|
728
|
+
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("issue6106.pdf"));
|
690
729
|
var promise = loadingTask.promise.then(function (doc) {
|
691
730
|
return doc.getJavaScript();
|
692
731
|
});
|
693
732
|
promise.then(function (data) {
|
694
|
-
expect(data).toEqual([
|
695
|
-
expect(data[0]).toMatch(
|
733
|
+
expect(data).toEqual(["this.print({bUI:true,bSilent:false,bShrinkToFit:true});"]);
|
734
|
+
expect(data[0]).toMatch(_ui_utils.AutoPrintRegExp);
|
696
735
|
loadingTask.destroy().then(done);
|
697
|
-
})
|
736
|
+
}).catch(done.fail);
|
698
737
|
});
|
699
|
-
it(
|
700
|
-
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(
|
701
|
-
var promise = loadingTask.promise.then(function (doc) {
|
702
|
-
return doc.getJavaScript();
|
703
|
-
});
|
704
|
-
promise.then(function (data) {
|
705
|
-
expect(data).toEqual(['this.print({bUI:true,bSilent:false,bShrinkToFit:true});']);
|
706
|
-
expect(data[0]).toMatch(viewerPrintRegExp);
|
707
|
-
loadingTask.destroy().then(done);
|
708
|
-
})["catch"](done.fail);
|
709
|
-
});
|
710
|
-
it('gets non-existent outline', function (done) {
|
711
|
-
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('tracemonkey.pdf'));
|
738
|
+
it("gets non-existent outline", function (done) {
|
739
|
+
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("tracemonkey.pdf"));
|
712
740
|
var promise = loadingTask.promise.then(function (pdfDocument) {
|
713
741
|
return pdfDocument.getOutline();
|
714
742
|
});
|
715
743
|
promise.then(function (outline) {
|
716
744
|
expect(outline).toEqual(null);
|
717
745
|
loadingTask.destroy().then(done);
|
718
|
-
})
|
746
|
+
}).catch(done.fail);
|
719
747
|
});
|
720
|
-
it(
|
748
|
+
it("gets outline", function (done) {
|
721
749
|
var promise = doc.getOutline();
|
722
750
|
promise.then(function (outline) {
|
723
751
|
expect(Array.isArray(outline)).toEqual(true);
|
724
752
|
expect(outline.length).toEqual(2);
|
725
753
|
var outlineItem = outline[1];
|
726
|
-
expect(outlineItem.title).toEqual(
|
754
|
+
expect(outlineItem.title).toEqual("Chapter 1");
|
727
755
|
expect(Array.isArray(outlineItem.dest)).toEqual(true);
|
728
756
|
expect(outlineItem.url).toEqual(null);
|
729
757
|
expect(outlineItem.unsafeUrl).toBeUndefined();
|
@@ -732,21 +760,21 @@ describe('api', function () {
|
|
732
760
|
expect(outlineItem.italic).toEqual(false);
|
733
761
|
expect(outlineItem.color).toEqual(new Uint8ClampedArray([0, 64, 128]));
|
734
762
|
expect(outlineItem.items.length).toEqual(1);
|
735
|
-
expect(outlineItem.items[0].title).toEqual(
|
763
|
+
expect(outlineItem.items[0].title).toEqual("Paragraph 1.1");
|
736
764
|
done();
|
737
|
-
})
|
765
|
+
}).catch(done.fail);
|
738
766
|
});
|
739
|
-
it(
|
740
|
-
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(
|
767
|
+
it("gets outline containing a url", function (done) {
|
768
|
+
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("issue3214.pdf"));
|
741
769
|
loadingTask.promise.then(function (pdfDocument) {
|
742
770
|
pdfDocument.getOutline().then(function (outline) {
|
743
771
|
expect(Array.isArray(outline)).toEqual(true);
|
744
772
|
expect(outline.length).toEqual(5);
|
745
773
|
var outlineItemTwo = outline[2];
|
746
|
-
expect(
|
774
|
+
expect(typeof outlineItemTwo.title).toEqual("string");
|
747
775
|
expect(outlineItemTwo.dest).toEqual(null);
|
748
|
-
expect(outlineItemTwo.url).toEqual(
|
749
|
-
expect(outlineItemTwo.unsafeUrl).toEqual(
|
776
|
+
expect(outlineItemTwo.url).toEqual("http://google.com/");
|
777
|
+
expect(outlineItemTwo.unsafeUrl).toEqual("http://google.com");
|
750
778
|
expect(outlineItemTwo.newWindow).toBeUndefined();
|
751
779
|
var outlineItemOne = outline[1];
|
752
780
|
expect(outlineItemOne.bold).toEqual(false);
|
@@ -754,28 +782,28 @@ describe('api', function () {
|
|
754
782
|
expect(outlineItemOne.color).toEqual(new Uint8ClampedArray([0, 0, 0]));
|
755
783
|
loadingTask.destroy().then(done);
|
756
784
|
});
|
757
|
-
})
|
785
|
+
}).catch(done.fail);
|
758
786
|
});
|
759
|
-
it(
|
787
|
+
it("gets non-existent permissions", function (done) {
|
760
788
|
doc.getPermissions().then(function (permissions) {
|
761
789
|
expect(permissions).toEqual(null);
|
762
790
|
done();
|
763
|
-
})
|
791
|
+
}).catch(done.fail);
|
764
792
|
});
|
765
|
-
it(
|
766
|
-
|
767
|
-
|
793
|
+
it("gets permissions", function (done) {
|
794
|
+
const loadingTask0 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("issue9972-1.pdf"));
|
795
|
+
const promise0 = loadingTask0.promise.then(function (pdfDocument) {
|
768
796
|
return pdfDocument.getPermissions();
|
769
797
|
});
|
770
|
-
|
771
|
-
|
798
|
+
const loadingTask1 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("issue9972-2.pdf"));
|
799
|
+
const promise1 = loadingTask1.promise.then(function (pdfDocument) {
|
772
800
|
return pdfDocument.getPermissions();
|
773
801
|
});
|
774
|
-
|
775
|
-
|
802
|
+
const loadingTask2 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("issue9972-3.pdf"));
|
803
|
+
const promise2 = loadingTask2.promise.then(function (pdfDocument) {
|
776
804
|
return pdfDocument.getPermissions();
|
777
805
|
});
|
778
|
-
|
806
|
+
const totalPermissionCount = Object.keys(_util.PermissionFlag).length;
|
779
807
|
Promise.all([promise0, promise1, promise2]).then(function (permissions) {
|
780
808
|
expect(permissions[0].length).toEqual(totalPermissionCount - 1);
|
781
809
|
expect(permissions[0].includes(_util.PermissionFlag.MODIFY_CONTENTS)).toBeFalsy();
|
@@ -785,69 +813,90 @@ describe('api', function () {
|
|
785
813
|
expect(permissions[2].length).toEqual(totalPermissionCount - 1);
|
786
814
|
expect(permissions[2].includes(_util.PermissionFlag.COPY)).toBeFalsy();
|
787
815
|
Promise.all([loadingTask0.destroy(), loadingTask1.destroy(), loadingTask2.destroy()]).then(done);
|
788
|
-
})
|
816
|
+
}).catch(done.fail);
|
789
817
|
});
|
790
|
-
it(
|
818
|
+
it("gets metadata", function (done) {
|
791
819
|
var promise = doc.getMetadata();
|
792
|
-
promise.then(function (
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
expect(info[
|
798
|
-
expect(info[
|
799
|
-
expect(info[
|
800
|
-
expect(info[
|
801
|
-
expect(info[
|
802
|
-
expect(info[
|
820
|
+
promise.then(function ({
|
821
|
+
info,
|
822
|
+
metadata,
|
823
|
+
contentDispositionFilename
|
824
|
+
}) {
|
825
|
+
expect(info["Title"]).toEqual("Basic API Test");
|
826
|
+
expect(info["Custom"]).toEqual(undefined);
|
827
|
+
expect(info["PDFFormatVersion"]).toEqual("1.7");
|
828
|
+
expect(info["IsLinearized"]).toEqual(false);
|
829
|
+
expect(info["IsAcroFormPresent"]).toEqual(false);
|
830
|
+
expect(info["IsXFAPresent"]).toEqual(false);
|
831
|
+
expect(info["IsCollectionPresent"]).toEqual(false);
|
803
832
|
expect(metadata instanceof _metadata.Metadata).toEqual(true);
|
804
|
-
expect(metadata.get(
|
833
|
+
expect(metadata.get("dc:title")).toEqual("Basic API Test");
|
805
834
|
expect(contentDispositionFilename).toEqual(null);
|
806
835
|
done();
|
807
|
-
})
|
836
|
+
}).catch(done.fail);
|
808
837
|
});
|
809
|
-
it(
|
810
|
-
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(
|
838
|
+
it("gets metadata, with custom info dict entries", function (done) {
|
839
|
+
var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("tracemonkey.pdf"));
|
811
840
|
loadingTask.promise.then(function (pdfDocument) {
|
812
841
|
return pdfDocument.getMetadata();
|
813
|
-
}).then(function (
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
expect(info[
|
819
|
-
expect(info[
|
820
|
-
|
821
|
-
|
822
|
-
expect(custom
|
823
|
-
expect(
|
824
|
-
expect(info[
|
825
|
-
expect(info[
|
826
|
-
expect(info[
|
827
|
-
expect(info[
|
842
|
+
}).then(function ({
|
843
|
+
info,
|
844
|
+
metadata,
|
845
|
+
contentDispositionFilename
|
846
|
+
}) {
|
847
|
+
expect(info["Creator"]).toEqual("TeX");
|
848
|
+
expect(info["Producer"]).toEqual("pdfeTeX-1.21a");
|
849
|
+
expect(info["CreationDate"]).toEqual("D:20090401163925-07'00'");
|
850
|
+
const custom = info["Custom"];
|
851
|
+
expect(typeof custom === "object" && custom !== null).toEqual(true);
|
852
|
+
expect(custom["PTEX.Fullbanner"]).toEqual("This is pdfeTeX, " + "Version 3.141592-1.21a-2.2 (Web2C 7.5.4) kpathsea version 3.5.6");
|
853
|
+
expect(info["PDFFormatVersion"]).toEqual("1.4");
|
854
|
+
expect(info["IsLinearized"]).toEqual(false);
|
855
|
+
expect(info["IsAcroFormPresent"]).toEqual(false);
|
856
|
+
expect(info["IsXFAPresent"]).toEqual(false);
|
857
|
+
expect(info["IsCollectionPresent"]).toEqual(false);
|
828
858
|
expect(metadata).toEqual(null);
|
829
859
|
expect(contentDispositionFilename).toEqual(null);
|
830
860
|
loadingTask.destroy().then(done);
|
831
|
-
})
|
861
|
+
}).catch(done.fail);
|
832
862
|
});
|
833
|
-
it(
|
863
|
+
it("gets metadata, with missing PDF header (bug 1606566)", function (done) {
|
864
|
+
const loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("bug1606566.pdf"));
|
865
|
+
loadingTask.promise.then(function (pdfDocument) {
|
866
|
+
return pdfDocument.getMetadata();
|
867
|
+
}).then(function ({
|
868
|
+
info,
|
869
|
+
metadata,
|
870
|
+
contentDispositionFilename
|
871
|
+
}) {
|
872
|
+
expect(info["PDFFormatVersion"]).toEqual(null);
|
873
|
+
expect(info["IsLinearized"]).toEqual(false);
|
874
|
+
expect(info["IsAcroFormPresent"]).toEqual(false);
|
875
|
+
expect(info["IsXFAPresent"]).toEqual(false);
|
876
|
+
expect(info["IsCollectionPresent"]).toEqual(false);
|
877
|
+
expect(metadata).toEqual(null);
|
878
|
+
expect(contentDispositionFilename).toEqual(null);
|
879
|
+
loadingTask.destroy().then(done);
|
880
|
+
}).catch(done.fail);
|
881
|
+
});
|
882
|
+
it("gets data", function (done) {
|
834
883
|
var promise = doc.getData();
|
835
884
|
promise.then(function (data) {
|
836
885
|
expect(data instanceof Uint8Array).toEqual(true);
|
837
886
|
expect(data.length).toEqual(basicApiFileLength);
|
838
887
|
done();
|
839
|
-
})
|
888
|
+
}).catch(done.fail);
|
840
889
|
});
|
841
|
-
it(
|
890
|
+
it("gets download info", function (done) {
|
842
891
|
var promise = doc.getDownloadInfo();
|
843
892
|
promise.then(function (data) {
|
844
893
|
expect(data).toEqual({
|
845
894
|
length: basicApiFileLength
|
846
895
|
});
|
847
896
|
done();
|
848
|
-
})
|
897
|
+
}).catch(done.fail);
|
849
898
|
});
|
850
|
-
it(
|
899
|
+
it("gets document stats", function (done) {
|
851
900
|
var promise = doc.getStats();
|
852
901
|
promise.then(function (stats) {
|
853
902
|
expect(stats).toEqual({
|
@@ -855,37 +904,44 @@ describe('api', function () {
|
|
855
904
|
fontTypes: {}
|
856
905
|
});
|
857
906
|
done();
|
858
|
-
})
|
907
|
+
}).catch(done.fail);
|
859
908
|
});
|
860
|
-
it(
|
861
|
-
|
862
|
-
|
909
|
+
it("cleans up document resources", function (done) {
|
910
|
+
const promise = doc.cleanup();
|
911
|
+
promise.then(function () {
|
912
|
+
expect(true).toEqual(true);
|
913
|
+
done();
|
914
|
+
}, done.fail);
|
915
|
+
});
|
916
|
+
it("checks that fingerprints are unique", function (done) {
|
917
|
+
const loadingTask1 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("issue4436r.pdf"));
|
918
|
+
const loadingTask2 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("issue4575.pdf"));
|
863
919
|
Promise.all([loadingTask1.promise, loadingTask2.promise]).then(function (data) {
|
864
|
-
|
865
|
-
|
920
|
+
const fingerprint1 = data[0].fingerprint;
|
921
|
+
const fingerprint2 = data[1].fingerprint;
|
866
922
|
expect(fingerprint1).not.toEqual(fingerprint2);
|
867
|
-
expect(fingerprint1).toEqual(
|
868
|
-
expect(fingerprint2).toEqual(
|
923
|
+
expect(fingerprint1).toEqual("2f695a83d6e7553c24fc08b7ac69712d");
|
924
|
+
expect(fingerprint2).toEqual("04c7126b34a46b6d4d6e7a1eff7edcb6");
|
869
925
|
Promise.all([loadingTask1.destroy(), loadingTask2.destroy()]).then(done);
|
870
|
-
})
|
926
|
+
}).catch(done.fail);
|
871
927
|
});
|
872
|
-
describe(
|
928
|
+
describe("Cross-origin", function () {
|
873
929
|
var loadingTask;
|
874
930
|
|
875
931
|
function _checkCanLoad(expectSuccess, filename, options) {
|
876
|
-
if (
|
877
|
-
pending(
|
932
|
+
if (_is_node.isNodeJS) {
|
933
|
+
pending("Cannot simulate cross-origin requests in Node.js");
|
878
934
|
}
|
879
935
|
|
880
936
|
var params = (0, _test_utils.buildGetDocumentParams)(filename, options);
|
881
937
|
var url = new URL(params.url);
|
882
938
|
|
883
|
-
if (url.hostname ===
|
884
|
-
url.hostname =
|
885
|
-
} else if (params.url.hostname ===
|
886
|
-
url.hostname =
|
939
|
+
if (url.hostname === "localhost") {
|
940
|
+
url.hostname = "127.0.0.1";
|
941
|
+
} else if (params.url.hostname === "127.0.0.1") {
|
942
|
+
url.hostname = "localhost";
|
887
943
|
} else {
|
888
|
-
pending(
|
944
|
+
pending("Can only run cross-origin test on localhost!");
|
889
945
|
}
|
890
946
|
|
891
947
|
params.url = url.href;
|
@@ -896,7 +952,7 @@ describe('api', function () {
|
|
896
952
|
expect(expectSuccess).toEqual(true);
|
897
953
|
}, function (error) {
|
898
954
|
if (expectSuccess) {
|
899
|
-
expect(error).toEqual(
|
955
|
+
expect(error).toEqual("There should not be any error");
|
900
956
|
}
|
901
957
|
|
902
958
|
expect(expectSuccess).toEqual(false);
|
@@ -918,35 +974,35 @@ describe('api', function () {
|
|
918
974
|
done();
|
919
975
|
}
|
920
976
|
});
|
921
|
-
it(
|
922
|
-
testCannotLoad(
|
977
|
+
it("server disallows cors", function (done) {
|
978
|
+
testCannotLoad("basicapi.pdf").then(done);
|
923
979
|
});
|
924
|
-
it(
|
925
|
-
testCanLoad(
|
980
|
+
it("server allows cors without credentials, default withCredentials", function (done) {
|
981
|
+
testCanLoad("basicapi.pdf?cors=withoutCredentials").then(done);
|
926
982
|
});
|
927
|
-
it(
|
928
|
-
testCanLoad(
|
983
|
+
it("server allows cors without credentials, and withCredentials=false", function (done) {
|
984
|
+
testCanLoad("basicapi.pdf?cors=withoutCredentials", {
|
929
985
|
withCredentials: false
|
930
986
|
}).then(done);
|
931
987
|
});
|
932
|
-
it(
|
933
|
-
testCannotLoad(
|
988
|
+
it("server allows cors without credentials, but withCredentials=true", function (done) {
|
989
|
+
testCannotLoad("basicapi.pdf?cors=withoutCredentials", {
|
934
990
|
withCredentials: true
|
935
991
|
}).then(done);
|
936
992
|
});
|
937
|
-
it(
|
938
|
-
testCanLoad(
|
993
|
+
it("server allows cors with credentials, and withCredentials=true", function (done) {
|
994
|
+
testCanLoad("basicapi.pdf?cors=withCredentials", {
|
939
995
|
withCredentials: true
|
940
996
|
}).then(done);
|
941
997
|
});
|
942
|
-
it(
|
943
|
-
testCanLoad(
|
998
|
+
it("server allows cors with credentials, and withCredentials=false", function (done) {
|
999
|
+
testCanLoad("basicapi.pdf?cors=withCredentials", {
|
944
1000
|
withCredentials: false
|
945
1001
|
}).then(done);
|
946
1002
|
});
|
947
1003
|
});
|
948
1004
|
});
|
949
|
-
describe(
|
1005
|
+
describe("Page", function () {
|
950
1006
|
var loadingTask;
|
951
1007
|
var pdfDocument, page;
|
952
1008
|
beforeAll(function (done) {
|
@@ -957,56 +1013,51 @@ describe('api', function () {
|
|
957
1013
|
page = data;
|
958
1014
|
done();
|
959
1015
|
});
|
960
|
-
})
|
1016
|
+
}).catch(done.fail);
|
961
1017
|
});
|
962
1018
|
afterAll(function (done) {
|
963
1019
|
loadingTask.destroy().then(done);
|
964
1020
|
});
|
965
|
-
it(
|
1021
|
+
it("gets page number", function () {
|
966
1022
|
expect(page.pageNumber).toEqual(1);
|
967
1023
|
});
|
968
|
-
it(
|
1024
|
+
it("gets rotate", function () {
|
969
1025
|
expect(page.rotate).toEqual(0);
|
970
1026
|
});
|
971
|
-
it(
|
1027
|
+
it("gets ref", function () {
|
972
1028
|
expect(page.ref).toEqual({
|
973
1029
|
num: 15,
|
974
1030
|
gen: 0
|
975
1031
|
});
|
976
1032
|
});
|
977
|
-
it(
|
1033
|
+
it("gets userUnit", function () {
|
978
1034
|
expect(page.userUnit).toEqual(1.0);
|
979
1035
|
});
|
980
|
-
it(
|
1036
|
+
it("gets view", function () {
|
981
1037
|
expect(page.view).toEqual([0, 0, 595.28, 841.89]);
|
982
1038
|
});
|
983
|
-
it(
|
984
|
-
|
985
|
-
viewLoadingTask.promise.then(
|
986
|
-
|
1039
|
+
it("gets view, with empty/invalid bounding boxes", function (done) {
|
1040
|
+
const viewLoadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("boundingBox_invalid.pdf"));
|
1041
|
+
viewLoadingTask.promise.then(pdfDoc => {
|
1042
|
+
const numPages = pdfDoc.numPages;
|
987
1043
|
expect(numPages).toEqual(3);
|
988
|
-
|
1044
|
+
const viewPromises = [];
|
989
1045
|
|
990
|
-
for (
|
991
|
-
viewPromises[i] = pdfDoc.getPage(i + 1).then(
|
1046
|
+
for (let i = 0; i < numPages; i++) {
|
1047
|
+
viewPromises[i] = pdfDoc.getPage(i + 1).then(pdfPage => {
|
992
1048
|
return pdfPage.view;
|
993
1049
|
});
|
994
1050
|
}
|
995
1051
|
|
996
|
-
Promise.all(viewPromises).then(
|
997
|
-
var _ref4 = _slicedToArray(_ref3, 3),
|
998
|
-
page1 = _ref4[0],
|
999
|
-
page2 = _ref4[1],
|
1000
|
-
page3 = _ref4[2];
|
1001
|
-
|
1052
|
+
Promise.all(viewPromises).then(([page1, page2, page3]) => {
|
1002
1053
|
expect(page1).toEqual([0, 0, 612, 792]);
|
1003
1054
|
expect(page2).toEqual([0, 0, 800, 600]);
|
1004
1055
|
expect(page3).toEqual([0, 0, 600, 800]);
|
1005
1056
|
viewLoadingTask.destroy().then(done);
|
1006
1057
|
});
|
1007
|
-
})
|
1058
|
+
}).catch(done.fail);
|
1008
1059
|
});
|
1009
|
-
it(
|
1060
|
+
it("gets viewport", function () {
|
1010
1061
|
var viewport = page.getViewport({
|
1011
1062
|
scale: 1.5,
|
1012
1063
|
rotation: 90
|
@@ -1018,16 +1069,25 @@ describe('api', function () {
|
|
1018
1069
|
expect(viewport.width).toEqual(1262.835);
|
1019
1070
|
expect(viewport.height).toEqual(892.92);
|
1020
1071
|
});
|
1021
|
-
it('gets viewport
|
1022
|
-
|
1023
|
-
|
1024
|
-
|
1025
|
-
|
1026
|
-
|
1072
|
+
it('gets viewport with "offsetX/offsetY" arguments', function () {
|
1073
|
+
const viewport = page.getViewport({
|
1074
|
+
scale: 1,
|
1075
|
+
rotation: 0,
|
1076
|
+
offsetX: 100,
|
1077
|
+
offsetY: -100
|
1027
1078
|
});
|
1028
|
-
|
1029
|
-
|
1030
|
-
|
1079
|
+
expect(viewport.transform).toEqual([1, 0, 0, -1, 100, 741.89]);
|
1080
|
+
});
|
1081
|
+
it('gets viewport respecting "dontFlip" argument', function () {
|
1082
|
+
const scale = 1,
|
1083
|
+
rotation = 0;
|
1084
|
+
const viewport = page.getViewport({
|
1085
|
+
scale,
|
1086
|
+
rotation
|
1087
|
+
});
|
1088
|
+
const dontFlipViewport = page.getViewport({
|
1089
|
+
scale,
|
1090
|
+
rotation,
|
1031
1091
|
dontFlip: true
|
1032
1092
|
});
|
1033
1093
|
expect(dontFlipViewport).not.toEqual(viewport);
|
@@ -1037,26 +1097,26 @@ describe('api', function () {
|
|
1037
1097
|
expect(viewport.transform).toEqual([1, 0, 0, -1, 0, 841.89]);
|
1038
1098
|
expect(dontFlipViewport.transform).toEqual([1, 0, -0, 1, 0, 0]);
|
1039
1099
|
});
|
1040
|
-
it(
|
1100
|
+
it("gets annotations", function (done) {
|
1041
1101
|
var defaultPromise = page.getAnnotations().then(function (data) {
|
1042
1102
|
expect(data.length).toEqual(4);
|
1043
1103
|
});
|
1044
1104
|
var displayPromise = page.getAnnotations({
|
1045
|
-
intent:
|
1105
|
+
intent: "display"
|
1046
1106
|
}).then(function (data) {
|
1047
1107
|
expect(data.length).toEqual(4);
|
1048
1108
|
});
|
1049
1109
|
var printPromise = page.getAnnotations({
|
1050
|
-
intent:
|
1110
|
+
intent: "print"
|
1051
1111
|
}).then(function (data) {
|
1052
1112
|
expect(data.length).toEqual(4);
|
1053
1113
|
});
|
1054
1114
|
Promise.all([defaultPromise, displayPromise, printPromise]).then(function () {
|
1055
1115
|
done();
|
1056
|
-
})
|
1116
|
+
}).catch(done.fail);
|
1057
1117
|
});
|
1058
|
-
it(
|
1059
|
-
var filename =
|
1118
|
+
it("gets annotations containing relative URLs (bug 766086)", function (done) {
|
1119
|
+
var filename = "bug766086.pdf";
|
1060
1120
|
var defaultLoadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(filename));
|
1061
1121
|
var defaultPromise = defaultLoadingTask.promise.then(function (pdfDoc) {
|
1062
1122
|
return pdfDoc.getPage(1).then(function (pdfPage) {
|
@@ -1064,7 +1124,7 @@ describe('api', function () {
|
|
1064
1124
|
});
|
1065
1125
|
});
|
1066
1126
|
var docBaseUrlLoadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(filename, {
|
1067
|
-
docBaseUrl:
|
1127
|
+
docBaseUrl: "http://www.example.com/test/pdfs/qwerty.pdf"
|
1068
1128
|
}));
|
1069
1129
|
var docBaseUrlPromise = docBaseUrlLoadingTask.promise.then(function (pdfDoc) {
|
1070
1130
|
return pdfDoc.getPage(1).then(function (pdfPage) {
|
@@ -1072,7 +1132,7 @@ describe('api', function () {
|
|
1072
1132
|
});
|
1073
1133
|
});
|
1074
1134
|
var invalidDocBaseUrlLoadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(filename, {
|
1075
|
-
docBaseUrl:
|
1135
|
+
docBaseUrl: "qwerty.pdf"
|
1076
1136
|
}));
|
1077
1137
|
var invalidDocBaseUrlPromise = invalidDocBaseUrlLoadingTask.promise.then(function (pdfDoc) {
|
1078
1138
|
return pdfDoc.getPage(1).then(function (pdfPage) {
|
@@ -1084,15 +1144,15 @@ describe('api', function () {
|
|
1084
1144
|
var docBaseUrlAnnotations = data[1];
|
1085
1145
|
var invalidDocBaseUrlAnnotations = data[2];
|
1086
1146
|
expect(defaultAnnotations[0].url).toBeUndefined();
|
1087
|
-
expect(defaultAnnotations[0].unsafeUrl).toEqual(
|
1088
|
-
expect(docBaseUrlAnnotations[0].url).toEqual(
|
1089
|
-
expect(docBaseUrlAnnotations[0].unsafeUrl).toEqual(
|
1147
|
+
expect(defaultAnnotations[0].unsafeUrl).toEqual("../../0021/002156/215675E.pdf#15");
|
1148
|
+
expect(docBaseUrlAnnotations[0].url).toEqual("http://www.example.com/0021/002156/215675E.pdf#15");
|
1149
|
+
expect(docBaseUrlAnnotations[0].unsafeUrl).toEqual("../../0021/002156/215675E.pdf#15");
|
1090
1150
|
expect(invalidDocBaseUrlAnnotations[0].url).toBeUndefined();
|
1091
|
-
expect(invalidDocBaseUrlAnnotations[0].unsafeUrl).toEqual(
|
1151
|
+
expect(invalidDocBaseUrlAnnotations[0].unsafeUrl).toEqual("../../0021/002156/215675E.pdf#15");
|
1092
1152
|
Promise.all([defaultLoadingTask.destroy(), docBaseUrlLoadingTask.destroy(), invalidDocBaseUrlLoadingTask.destroy()]).then(done);
|
1093
|
-
})
|
1153
|
+
}).catch(done.fail);
|
1094
1154
|
});
|
1095
|
-
it(
|
1155
|
+
it("gets text content", function (done) {
|
1096
1156
|
var defaultPromise = page.getTextContent();
|
1097
1157
|
var parametersPromise = page.getTextContent({
|
1098
1158
|
normalizeWhitespace: true,
|
@@ -1105,27 +1165,28 @@ describe('api', function () {
|
|
1105
1165
|
expect(!!data[0].styles).toEqual(true);
|
1106
1166
|
expect(JSON.stringify(data[0])).toEqual(JSON.stringify(data[1]));
|
1107
1167
|
done();
|
1108
|
-
})
|
1109
|
-
});
|
1110
|
-
it(
|
1111
|
-
|
1112
|
-
loadingTask.promise.then(
|
1113
|
-
pdfDoc.getPage(1).then(
|
1114
|
-
pdfPage.getTextContent().then(
|
1115
|
-
|
1116
|
-
|
1168
|
+
}).catch(done.fail);
|
1169
|
+
});
|
1170
|
+
it("gets text content, with correct properties (issue 8276)", function (done) {
|
1171
|
+
const loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("issue8276_reduced.pdf"));
|
1172
|
+
loadingTask.promise.then(pdfDoc => {
|
1173
|
+
pdfDoc.getPage(1).then(pdfPage => {
|
1174
|
+
pdfPage.getTextContent().then(({
|
1175
|
+
items,
|
1176
|
+
styles
|
1177
|
+
}) => {
|
1117
1178
|
expect(items.length).toEqual(1);
|
1118
|
-
expect(Object.keys(styles)).toEqual([
|
1179
|
+
expect(Object.keys(styles)).toEqual(["Times"]);
|
1119
1180
|
expect(items[0]).toEqual({
|
1120
|
-
dir:
|
1121
|
-
fontName:
|
1181
|
+
dir: "ltr",
|
1182
|
+
fontName: "Times",
|
1122
1183
|
height: 18,
|
1123
|
-
str:
|
1184
|
+
str: "Issue 8276",
|
1124
1185
|
transform: [18, 0, 0, 18, 441.81, 708.4499999999999],
|
1125
1186
|
width: 77.49
|
1126
1187
|
});
|
1127
1188
|
expect(styles.Times).toEqual({
|
1128
|
-
fontFamily:
|
1189
|
+
fontFamily: "serif",
|
1129
1190
|
ascent: NaN,
|
1130
1191
|
descent: NaN,
|
1131
1192
|
vertical: false
|
@@ -1133,45 +1194,44 @@ describe('api', function () {
|
|
1133
1194
|
loadingTask.destroy().then(done);
|
1134
1195
|
});
|
1135
1196
|
});
|
1136
|
-
})
|
1197
|
+
}).catch(done.fail);
|
1137
1198
|
});
|
1138
|
-
it(
|
1199
|
+
it("gets operator list", function (done) {
|
1139
1200
|
var promise = page.getOperatorList();
|
1140
1201
|
promise.then(function (oplist) {
|
1141
1202
|
expect(!!oplist.fnArray).toEqual(true);
|
1142
1203
|
expect(!!oplist.argsArray).toEqual(true);
|
1143
1204
|
expect(oplist.lastChunk).toEqual(true);
|
1144
1205
|
done();
|
1145
|
-
})
|
1146
|
-
});
|
1147
|
-
it(
|
1148
|
-
|
1149
|
-
loadingTask.promise.then(
|
1150
|
-
pdfDoc.getPage(1).then(
|
1151
|
-
pdfPage.getOperatorList().then(
|
1152
|
-
|
1153
|
-
|
1154
|
-
|
1155
|
-
|
1156
|
-
|
1157
|
-
|
1206
|
+
}).catch(done.fail);
|
1207
|
+
});
|
1208
|
+
it("gets operatorList with JPEG image (issue 4888)", function (done) {
|
1209
|
+
const loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("cmykjpeg.pdf"));
|
1210
|
+
loadingTask.promise.then(pdfDoc => {
|
1211
|
+
pdfDoc.getPage(1).then(pdfPage => {
|
1212
|
+
pdfPage.getOperatorList().then(opList => {
|
1213
|
+
const imgIndex = opList.fnArray.indexOf(_util.OPS.paintImageXObject);
|
1214
|
+
const imgArgs = opList.argsArray[imgIndex];
|
1215
|
+
const {
|
1216
|
+
data
|
1217
|
+
} = pdfPage.objs.get(imgArgs[0]);
|
1158
1218
|
expect(data instanceof Uint8ClampedArray).toEqual(true);
|
1159
1219
|
expect(data.length).toEqual(90000);
|
1160
1220
|
loadingTask.destroy().then(done);
|
1161
1221
|
});
|
1162
1222
|
});
|
1163
|
-
})
|
1223
|
+
}).catch(done.fail);
|
1164
1224
|
});
|
1165
|
-
it(
|
1166
|
-
|
1225
|
+
it("gets operatorList, from corrupt PDF file (issue 8702), " + "with/without `stopAtErrors` set", function (done) {
|
1226
|
+
const loadingTask1 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("issue8702.pdf", {
|
1167
1227
|
stopAtErrors: false
|
1168
1228
|
}));
|
1169
|
-
|
1229
|
+
const loadingTask2 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("issue8702.pdf", {
|
1170
1230
|
stopAtErrors: true
|
1171
1231
|
}));
|
1172
|
-
|
1173
|
-
return pdfDoc.getPage(1).then(
|
1174
|
-
return pdfPage.getOperatorList().then(
|
1232
|
+
const result1 = loadingTask1.promise.then(pdfDoc => {
|
1233
|
+
return pdfDoc.getPage(1).then(pdfPage => {
|
1234
|
+
return pdfPage.getOperatorList().then(opList => {
|
1175
1235
|
expect(opList.fnArray.length).toEqual(722);
|
1176
1236
|
expect(opList.argsArray.length).toEqual(722);
|
1177
1237
|
expect(opList.lastChunk).toEqual(true);
|
@@ -1179,9 +1239,9 @@ describe('api', function () {
|
|
1179
1239
|
});
|
1180
1240
|
});
|
1181
1241
|
});
|
1182
|
-
|
1183
|
-
return pdfDoc.getPage(1).then(
|
1184
|
-
return pdfPage.getOperatorList().then(
|
1242
|
+
const result2 = loadingTask2.promise.then(pdfDoc => {
|
1243
|
+
return pdfDoc.getPage(1).then(pdfPage => {
|
1244
|
+
return pdfPage.getOperatorList().then(opList => {
|
1185
1245
|
expect(opList.fnArray.length).toEqual(0);
|
1186
1246
|
expect(opList.argsArray.length).toEqual(0);
|
1187
1247
|
expect(opList.lastChunk).toEqual(true);
|
@@ -1191,7 +1251,7 @@ describe('api', function () {
|
|
1191
1251
|
});
|
1192
1252
|
Promise.all([result1, result2]).then(done, done.fail);
|
1193
1253
|
});
|
1194
|
-
it(
|
1254
|
+
it("gets document stats after parsing page", function (done) {
|
1195
1255
|
var promise = page.getOperatorList().then(function () {
|
1196
1256
|
return pdfDocument.getStats();
|
1197
1257
|
});
|
@@ -1206,78 +1266,70 @@ describe('api', function () {
|
|
1206
1266
|
fontTypes: expectedFontTypes
|
1207
1267
|
});
|
1208
1268
|
done();
|
1209
|
-
})
|
1269
|
+
}).catch(done.fail);
|
1210
1270
|
});
|
1211
|
-
it(
|
1212
|
-
page.getOperatorList().then(
|
1271
|
+
it("gets page stats after parsing page, without `pdfBug` set", function (done) {
|
1272
|
+
page.getOperatorList().then(opList => {
|
1213
1273
|
return page.stats;
|
1214
|
-
}).then(
|
1274
|
+
}).then(stats => {
|
1215
1275
|
expect(stats).toEqual(null);
|
1216
1276
|
done();
|
1217
1277
|
}, done.fail);
|
1218
1278
|
});
|
1219
|
-
it(
|
1220
|
-
|
1279
|
+
it("gets page stats after parsing page, with `pdfBug` set", function (done) {
|
1280
|
+
const loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(basicApiFileName, {
|
1221
1281
|
pdfBug: true
|
1222
1282
|
}));
|
1223
|
-
loadingTask.promise.then(
|
1224
|
-
return pdfDoc.getPage(1).then(
|
1225
|
-
return pdfPage.getOperatorList().then(
|
1283
|
+
loadingTask.promise.then(pdfDoc => {
|
1284
|
+
return pdfDoc.getPage(1).then(pdfPage => {
|
1285
|
+
return pdfPage.getOperatorList().then(opList => {
|
1226
1286
|
return pdfPage.stats;
|
1227
1287
|
});
|
1228
1288
|
});
|
1229
|
-
}).then(
|
1289
|
+
}).then(stats => {
|
1230
1290
|
expect(stats instanceof _display_utils.StatTimer).toEqual(true);
|
1231
1291
|
expect(stats.times.length).toEqual(1);
|
1232
|
-
|
1233
|
-
|
1234
|
-
statEntry = _stats$times[0];
|
1235
|
-
|
1236
|
-
expect(statEntry.name).toEqual('Page Request');
|
1292
|
+
const [statEntry] = stats.times;
|
1293
|
+
expect(statEntry.name).toEqual("Page Request");
|
1237
1294
|
expect(statEntry.end - statEntry.start).toBeGreaterThanOrEqual(0);
|
1238
1295
|
loadingTask.destroy().then(done);
|
1239
1296
|
}, done.fail);
|
1240
1297
|
});
|
1241
|
-
it(
|
1242
|
-
|
1298
|
+
it("gets page stats after rendering page, with `pdfBug` set", function (done) {
|
1299
|
+
const loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(basicApiFileName, {
|
1243
1300
|
pdfBug: true
|
1244
1301
|
}));
|
1245
|
-
|
1246
|
-
loadingTask.promise.then(
|
1247
|
-
return pdfDoc.getPage(1).then(
|
1248
|
-
|
1302
|
+
let canvasAndCtx;
|
1303
|
+
loadingTask.promise.then(pdfDoc => {
|
1304
|
+
return pdfDoc.getPage(1).then(pdfPage => {
|
1305
|
+
const viewport = pdfPage.getViewport({
|
1249
1306
|
scale: 1
|
1250
1307
|
});
|
1251
1308
|
canvasAndCtx = CanvasFactory.create(viewport.width, viewport.height);
|
1252
|
-
|
1309
|
+
const renderTask = pdfPage.render({
|
1253
1310
|
canvasContext: canvasAndCtx.context,
|
1254
1311
|
canvasFactory: CanvasFactory,
|
1255
|
-
viewport
|
1312
|
+
viewport
|
1256
1313
|
});
|
1257
|
-
return renderTask.promise.then(
|
1314
|
+
return renderTask.promise.then(() => {
|
1258
1315
|
return pdfPage.stats;
|
1259
1316
|
});
|
1260
1317
|
});
|
1261
|
-
}).then(
|
1318
|
+
}).then(stats => {
|
1262
1319
|
expect(stats instanceof _display_utils.StatTimer).toEqual(true);
|
1263
1320
|
expect(stats.times.length).toEqual(3);
|
1264
|
-
|
1265
|
-
|
1266
|
-
|
1267
|
-
|
1268
|
-
statEntryThree = _stats$times2[2];
|
1269
|
-
|
1270
|
-
expect(statEntryOne.name).toEqual('Page Request');
|
1271
|
-
expect(statEntryOne.end - statEntryOne.start).toBeGreaterThan(0);
|
1272
|
-
expect(statEntryTwo.name).toEqual('Rendering');
|
1321
|
+
const [statEntryOne, statEntryTwo, statEntryThree] = stats.times;
|
1322
|
+
expect(statEntryOne.name).toEqual("Page Request");
|
1323
|
+
expect(statEntryOne.end - statEntryOne.start).toBeGreaterThanOrEqual(0);
|
1324
|
+
expect(statEntryTwo.name).toEqual("Rendering");
|
1273
1325
|
expect(statEntryTwo.end - statEntryTwo.start).toBeGreaterThan(0);
|
1274
|
-
expect(statEntryThree.name).toEqual(
|
1326
|
+
expect(statEntryThree.name).toEqual("Overall");
|
1275
1327
|
expect(statEntryThree.end - statEntryThree.start).toBeGreaterThan(0);
|
1276
1328
|
CanvasFactory.destroy(canvasAndCtx);
|
1277
1329
|
loadingTask.destroy().then(done);
|
1278
1330
|
}, done.fail);
|
1279
1331
|
});
|
1280
|
-
it(
|
1332
|
+
it("cancels rendering of page", function (done) {
|
1281
1333
|
var viewport = page.getViewport({
|
1282
1334
|
scale: 1
|
1283
1335
|
});
|
@@ -1285,46 +1337,47 @@ describe('api', function () {
|
|
1285
1337
|
var renderTask = page.render({
|
1286
1338
|
canvasContext: canvasAndCtx.context,
|
1287
1339
|
canvasFactory: CanvasFactory,
|
1288
|
-
viewport
|
1340
|
+
viewport
|
1289
1341
|
});
|
1290
1342
|
renderTask.cancel();
|
1291
1343
|
renderTask.promise.then(function () {
|
1292
|
-
done.fail(
|
1293
|
-
})
|
1344
|
+
done.fail("shall cancel rendering");
|
1345
|
+
}).catch(function (error) {
|
1294
1346
|
expect(error instanceof _display_utils.RenderingCancelledException).toEqual(true);
|
1295
|
-
expect(error.
|
1347
|
+
expect(error.message).toEqual("Rendering cancelled, page 1");
|
1348
|
+
expect(error.type).toEqual("canvas");
|
1296
1349
|
CanvasFactory.destroy(canvasAndCtx);
|
1297
1350
|
done();
|
1298
1351
|
});
|
1299
1352
|
});
|
1300
|
-
it(
|
1301
|
-
|
1353
|
+
it("re-render page, using the same canvas, after cancelling rendering", function (done) {
|
1354
|
+
const viewport = page.getViewport({
|
1302
1355
|
scale: 1
|
1303
1356
|
});
|
1304
|
-
|
1305
|
-
|
1357
|
+
const canvasAndCtx = CanvasFactory.create(viewport.width, viewport.height);
|
1358
|
+
const renderTask = page.render({
|
1306
1359
|
canvasContext: canvasAndCtx.context,
|
1307
1360
|
canvasFactory: CanvasFactory,
|
1308
|
-
viewport
|
1361
|
+
viewport
|
1309
1362
|
});
|
1310
1363
|
renderTask.cancel();
|
1311
|
-
renderTask.promise.then(
|
1312
|
-
throw new Error(
|
1313
|
-
},
|
1364
|
+
renderTask.promise.then(() => {
|
1365
|
+
throw new Error("shall cancel rendering");
|
1366
|
+
}, reason => {
|
1314
1367
|
expect(reason instanceof _display_utils.RenderingCancelledException).toEqual(true);
|
1315
|
-
}).then(
|
1316
|
-
|
1368
|
+
}).then(() => {
|
1369
|
+
const reRenderTask = page.render({
|
1317
1370
|
canvasContext: canvasAndCtx.context,
|
1318
1371
|
canvasFactory: CanvasFactory,
|
1319
|
-
viewport
|
1372
|
+
viewport
|
1320
1373
|
});
|
1321
1374
|
return reRenderTask.promise;
|
1322
|
-
}).then(
|
1375
|
+
}).then(() => {
|
1323
1376
|
CanvasFactory.destroy(canvasAndCtx);
|
1324
1377
|
done();
|
1325
1378
|
}, done.fail);
|
1326
1379
|
});
|
1327
|
-
it(
|
1380
|
+
it("multiple render() on the same canvas", function (done) {
|
1328
1381
|
var viewport = page.getViewport({
|
1329
1382
|
scale: 1
|
1330
1383
|
});
|
@@ -1332,85 +1385,105 @@ describe('api', function () {
|
|
1332
1385
|
var renderTask1 = page.render({
|
1333
1386
|
canvasContext: canvasAndCtx.context,
|
1334
1387
|
canvasFactory: CanvasFactory,
|
1335
|
-
viewport
|
1388
|
+
viewport
|
1336
1389
|
});
|
1337
1390
|
var renderTask2 = page.render({
|
1338
1391
|
canvasContext: canvasAndCtx.context,
|
1339
1392
|
canvasFactory: CanvasFactory,
|
1340
|
-
viewport
|
1393
|
+
viewport
|
1341
1394
|
});
|
1342
|
-
Promise.all([renderTask1.promise, renderTask2.promise.then(
|
1343
|
-
done.fail(
|
1344
|
-
},
|
1395
|
+
Promise.all([renderTask1.promise, renderTask2.promise.then(() => {
|
1396
|
+
done.fail("shall fail rendering");
|
1397
|
+
}, reason => {
|
1345
1398
|
expect(/multiple render\(\)/.test(reason.message)).toEqual(true);
|
1346
1399
|
})]).then(done);
|
1347
1400
|
});
|
1401
|
+
it("cleans up document resources after rendering of page", function (done) {
|
1402
|
+
const loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(basicApiFileName));
|
1403
|
+
let canvasAndCtx;
|
1404
|
+
loadingTask.promise.then(pdfDoc => {
|
1405
|
+
return pdfDoc.getPage(1).then(pdfPage => {
|
1406
|
+
const viewport = pdfPage.getViewport({
|
1407
|
+
scale: 1
|
1408
|
+
});
|
1409
|
+
canvasAndCtx = CanvasFactory.create(viewport.width, viewport.height);
|
1410
|
+
const renderTask = pdfPage.render({
|
1411
|
+
canvasContext: canvasAndCtx.context,
|
1412
|
+
canvasFactory: CanvasFactory,
|
1413
|
+
viewport
|
1414
|
+
});
|
1415
|
+
return renderTask.promise.then(() => {
|
1416
|
+
return pdfDoc.cleanup();
|
1417
|
+
});
|
1418
|
+
});
|
1419
|
+
}).then(() => {
|
1420
|
+
expect(true).toEqual(true);
|
1421
|
+
CanvasFactory.destroy(canvasAndCtx);
|
1422
|
+
loadingTask.destroy().then(done);
|
1423
|
+
}, done.fail);
|
1424
|
+
});
|
1425
|
+
it("cleans up document resources during rendering of page", function (done) {
|
1426
|
+
const loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("tracemonkey.pdf"));
|
1427
|
+
let canvasAndCtx;
|
1428
|
+
loadingTask.promise.then(pdfDoc => {
|
1429
|
+
return pdfDoc.getPage(1).then(pdfPage => {
|
1430
|
+
const viewport = pdfPage.getViewport({
|
1431
|
+
scale: 1
|
1432
|
+
});
|
1433
|
+
canvasAndCtx = CanvasFactory.create(viewport.width, viewport.height);
|
1434
|
+
const renderTask = pdfPage.render({
|
1435
|
+
canvasContext: canvasAndCtx.context,
|
1436
|
+
canvasFactory: CanvasFactory,
|
1437
|
+
viewport
|
1438
|
+
});
|
1439
|
+
pdfDoc.cleanup().then(() => {
|
1440
|
+
throw new Error("shall fail cleanup");
|
1441
|
+
}, reason => {
|
1442
|
+
expect(reason instanceof Error).toEqual(true);
|
1443
|
+
expect(reason.message).toEqual("startCleanup: Page 1 is currently rendering.");
|
1444
|
+
}).then(() => {
|
1445
|
+
return renderTask.promise;
|
1446
|
+
}).then(() => {
|
1447
|
+
CanvasFactory.destroy(canvasAndCtx);
|
1448
|
+
loadingTask.destroy().then(done);
|
1449
|
+
});
|
1450
|
+
});
|
1451
|
+
}).catch(done.fail);
|
1452
|
+
});
|
1348
1453
|
});
|
1349
|
-
describe(
|
1350
|
-
var pdf1 = (0, _test_utils.buildGetDocumentParams)(
|
1351
|
-
var pdf2 = (0, _test_utils.buildGetDocumentParams)(
|
1352
|
-
var pdf3 = (0, _test_utils.buildGetDocumentParams)(
|
1454
|
+
describe("Multiple `getDocument` instances", function () {
|
1455
|
+
var pdf1 = (0, _test_utils.buildGetDocumentParams)("tracemonkey.pdf");
|
1456
|
+
var pdf2 = (0, _test_utils.buildGetDocumentParams)("TAMReview.pdf");
|
1457
|
+
var pdf3 = (0, _test_utils.buildGetDocumentParams)("issue6068.pdf");
|
1353
1458
|
var loadingTasks = [];
|
1354
1459
|
|
1355
|
-
function renderPDF(
|
1356
|
-
|
1357
|
-
|
1358
|
-
|
1359
|
-
|
1360
|
-
|
1361
|
-
|
1362
|
-
|
1363
|
-
|
1364
|
-
|
1365
|
-
|
1366
|
-
|
1367
|
-
|
1368
|
-
|
1369
|
-
|
1370
|
-
|
1371
|
-
|
1372
|
-
|
1373
|
-
case 4:
|
1374
|
-
pdf = _context.sent;
|
1375
|
-
_context.next = 7;
|
1376
|
-
return pdf.getPage(1);
|
1377
|
-
|
1378
|
-
case 7:
|
1379
|
-
page = _context.sent;
|
1380
|
-
viewport = page.getViewport({
|
1381
|
-
scale: 1.2
|
1382
|
-
});
|
1383
|
-
canvasAndCtx = CanvasFactory.create(viewport.width, viewport.height);
|
1384
|
-
renderTask = page.render({
|
1385
|
-
canvasContext: canvasAndCtx.context,
|
1386
|
-
canvasFactory: CanvasFactory,
|
1387
|
-
viewport: viewport
|
1388
|
-
});
|
1389
|
-
_context.next = 13;
|
1390
|
-
return renderTask.promise;
|
1391
|
-
|
1392
|
-
case 13:
|
1393
|
-
data = canvasAndCtx.canvas.toDataURL();
|
1394
|
-
CanvasFactory.destroy(canvasAndCtx);
|
1395
|
-
return _context.abrupt("return", data);
|
1396
|
-
|
1397
|
-
case 16:
|
1398
|
-
case "end":
|
1399
|
-
return _context.stop();
|
1400
|
-
}
|
1401
|
-
}
|
1402
|
-
}, _callee);
|
1403
|
-
}));
|
1404
|
-
return _renderPDF.apply(this, arguments);
|
1460
|
+
async function renderPDF(filename) {
|
1461
|
+
const loadingTask = (0, _api.getDocument)(filename);
|
1462
|
+
loadingTasks.push(loadingTask);
|
1463
|
+
const pdf = await loadingTask.promise;
|
1464
|
+
const page = await pdf.getPage(1);
|
1465
|
+
const viewport = page.getViewport({
|
1466
|
+
scale: 1.2
|
1467
|
+
});
|
1468
|
+
const canvasAndCtx = CanvasFactory.create(viewport.width, viewport.height);
|
1469
|
+
const renderTask = page.render({
|
1470
|
+
canvasContext: canvasAndCtx.context,
|
1471
|
+
canvasFactory: CanvasFactory,
|
1472
|
+
viewport
|
1473
|
+
});
|
1474
|
+
await renderTask.promise;
|
1475
|
+
const data = canvasAndCtx.canvas.toDataURL();
|
1476
|
+
CanvasFactory.destroy(canvasAndCtx);
|
1477
|
+
return data;
|
1405
1478
|
}
|
1406
1479
|
|
1407
1480
|
afterEach(function (done) {
|
1408
|
-
|
1481
|
+
const destroyPromises = loadingTasks.map(function (loadingTask) {
|
1409
1482
|
return loadingTask.destroy();
|
1410
1483
|
});
|
1411
1484
|
Promise.all(destroyPromises).then(done);
|
1412
1485
|
});
|
1413
|
-
it(
|
1486
|
+
it("should correctly render PDFs in parallel", function (done) {
|
1414
1487
|
var baseline1, baseline2, baseline3;
|
1415
1488
|
var promiseDone = renderPDF(pdf1).then(function (data1) {
|
1416
1489
|
baseline1 = data1;
|
@@ -1429,15 +1502,15 @@ describe('api', function () {
|
|
1429
1502
|
});
|
1430
1503
|
promiseDone.then(function () {
|
1431
1504
|
done();
|
1432
|
-
})
|
1505
|
+
}).catch(done.fail);
|
1433
1506
|
});
|
1434
1507
|
});
|
1435
|
-
describe(
|
1436
|
-
|
1508
|
+
describe("PDFDataRangeTransport", function () {
|
1509
|
+
let dataPromise;
|
1437
1510
|
beforeAll(function (done) {
|
1438
|
-
|
1511
|
+
const fileName = "tracemonkey.pdf";
|
1439
1512
|
|
1440
|
-
if (
|
1513
|
+
if (_is_node.isNodeJS) {
|
1441
1514
|
dataPromise = _test_utils.NodeFileReaderFactory.fetch({
|
1442
1515
|
path: _test_utils.TEST_PDFS_PATH.node + fileName
|
1443
1516
|
});
|
@@ -1452,13 +1525,13 @@ describe('api', function () {
|
|
1452
1525
|
afterAll(function () {
|
1453
1526
|
dataPromise = null;
|
1454
1527
|
});
|
1455
|
-
it(
|
1456
|
-
|
1457
|
-
|
1528
|
+
it("should fetch document info and page using ranges", function (done) {
|
1529
|
+
const initialDataLength = 4000;
|
1530
|
+
let fetches = 0,
|
1458
1531
|
loadingTask;
|
1459
1532
|
dataPromise.then(function (data) {
|
1460
|
-
|
1461
|
-
|
1533
|
+
const initialData = data.subarray(0, initialDataLength);
|
1534
|
+
const transport = new _api.PDFDataRangeTransport(data.length, initialData);
|
1462
1535
|
|
1463
1536
|
transport.requestDataRange = function (begin, end) {
|
1464
1537
|
fetches++;
|
@@ -1477,15 +1550,15 @@ describe('api', function () {
|
|
1477
1550
|
expect(pdfPage.rotate).toEqual(0);
|
1478
1551
|
expect(fetches).toBeGreaterThan(2);
|
1479
1552
|
loadingTask.destroy().then(done);
|
1480
|
-
})
|
1553
|
+
}).catch(done.fail);
|
1481
1554
|
});
|
1482
|
-
it(
|
1483
|
-
|
1484
|
-
|
1555
|
+
it("should fetch document info and page using range and streaming", function (done) {
|
1556
|
+
const initialDataLength = 4000;
|
1557
|
+
let fetches = 0,
|
1485
1558
|
loadingTask;
|
1486
1559
|
dataPromise.then(function (data) {
|
1487
|
-
|
1488
|
-
|
1560
|
+
const initialData = data.subarray(0, initialDataLength);
|
1561
|
+
const transport = new _api.PDFDataRangeTransport(data.length, initialData);
|
1489
1562
|
|
1490
1563
|
transport.requestDataRange = function (begin, end) {
|
1491
1564
|
fetches++;
|
@@ -1510,13 +1583,13 @@ describe('api', function () {
|
|
1510
1583
|
waitSome(function () {
|
1511
1584
|
loadingTask.destroy().then(done);
|
1512
1585
|
});
|
1513
|
-
})
|
1586
|
+
}).catch(done.fail);
|
1514
1587
|
});
|
1515
|
-
it(
|
1516
|
-
|
1588
|
+
it("should fetch document info and page, without range, " + "using complete initialData", function (done) {
|
1589
|
+
let fetches = 0,
|
1517
1590
|
loadingTask;
|
1518
1591
|
dataPromise.then(function (data) {
|
1519
|
-
|
1592
|
+
const transport = new _api.PDFDataRangeTransport(data.length, data, true);
|
1520
1593
|
|
1521
1594
|
transport.requestDataRange = function (begin, end) {
|
1522
1595
|
fetches++;
|
@@ -1534,7 +1607,7 @@ describe('api', function () {
|
|
1534
1607
|
expect(pdfPage.rotate).toEqual(0);
|
1535
1608
|
expect(fetches).toEqual(0);
|
1536
1609
|
loadingTask.destroy().then(done);
|
1537
|
-
})
|
1610
|
+
}).catch(done.fail);
|
1538
1611
|
});
|
1539
1612
|
});
|
1540
1613
|
});
|