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