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