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.

Files changed (229) hide show
  1. package/README.md +4 -0
  2. package/bower.json +1 -1
  3. package/build/pdf.js +8816 -19300
  4. package/build/pdf.js.map +1 -1
  5. package/build/pdf.min.js +22 -1
  6. package/build/pdf.worker.entry.js +5 -3
  7. package/build/pdf.worker.js +27185 -35746
  8. package/build/pdf.worker.js.map +1 -1
  9. package/build/pdf.worker.min.js +22 -1
  10. package/es5/build/pdf.js +26665 -0
  11. package/es5/build/pdf.js.map +1 -0
  12. package/es5/build/pdf.min.js +22 -0
  13. package/{lib/shared/global_scope.js → es5/build/pdf.worker.entry.js} +5 -10
  14. package/es5/build/pdf.worker.js +61231 -0
  15. package/es5/build/pdf.worker.js.map +1 -0
  16. package/es5/build/pdf.worker.min.js +22 -0
  17. package/es5/image_decoders/pdf.image_decoders.js +12529 -0
  18. package/es5/image_decoders/pdf.image_decoders.js.map +1 -0
  19. package/es5/image_decoders/pdf.image_decoders.min.js +22 -0
  20. package/es5/web/images/annotation-check.svg +11 -0
  21. package/es5/web/images/annotation-comment.svg +16 -0
  22. package/es5/web/images/annotation-help.svg +26 -0
  23. package/es5/web/images/annotation-insert.svg +10 -0
  24. package/es5/web/images/annotation-key.svg +11 -0
  25. package/es5/web/images/annotation-newparagraph.svg +11 -0
  26. package/es5/web/images/annotation-noicon.svg +7 -0
  27. package/es5/web/images/annotation-note.svg +42 -0
  28. package/es5/web/images/annotation-paragraph.svg +16 -0
  29. package/es5/web/images/loading-icon.gif +0 -0
  30. package/es5/web/images/shadow.png +0 -0
  31. package/es5/web/pdf_viewer.css +406 -0
  32. package/es5/web/pdf_viewer.js +7886 -0
  33. package/es5/web/pdf_viewer.js.map +1 -0
  34. package/image_decoders/pdf.image_decoders.js +1498 -4832
  35. package/image_decoders/pdf.image_decoders.js.map +1 -1
  36. package/image_decoders/pdf.image_decoders.min.js +22 -1
  37. package/lib/README.md +7 -0
  38. package/lib/core/annotation.js +1144 -927
  39. package/lib/core/arithmetic_decoder.js +81 -97
  40. package/lib/core/bidi.js +54 -46
  41. package/lib/core/ccitt.js +88 -81
  42. package/lib/core/ccitt_stream.js +15 -14
  43. package/lib/core/cff_parser.js +747 -716
  44. package/lib/core/charsets.js +4 -4
  45. package/lib/core/chunked_stream.js +462 -553
  46. package/lib/core/cmap.js +231 -277
  47. package/lib/core/colorspace.js +715 -857
  48. package/lib/core/core_utils.js +57 -52
  49. package/lib/core/crypto.js +416 -437
  50. package/lib/core/document.js +629 -670
  51. package/lib/core/encodings.js +15 -15
  52. package/lib/core/evaluator.js +3229 -2800
  53. package/lib/core/font_renderer.js +135 -178
  54. package/lib/core/fonts.js +602 -534
  55. package/lib/core/function.js +355 -279
  56. package/lib/core/glyphlist.js +4527 -4526
  57. package/lib/core/image.js +442 -439
  58. package/lib/core/image_utils.js +221 -61
  59. package/lib/core/jbig2.js +325 -316
  60. package/lib/core/jbig2_stream.js +18 -17
  61. package/lib/core/jpeg_stream.js +21 -26
  62. package/lib/core/jpg.js +289 -233
  63. package/lib/core/jpx.js +161 -143
  64. package/lib/core/jpx_stream.js +28 -28
  65. package/lib/core/metrics.js +2928 -2928
  66. package/lib/core/murmurhash3.js +87 -102
  67. package/lib/core/obj.js +1343 -1300
  68. package/lib/core/operator_list.js +90 -67
  69. package/lib/core/parser.js +990 -987
  70. package/lib/core/pattern.js +105 -77
  71. package/lib/core/pdf_manager.js +149 -316
  72. package/lib/core/primitives.js +156 -104
  73. package/lib/core/ps_parser.js +175 -214
  74. package/lib/core/standard_fonts.js +237 -236
  75. package/lib/core/stream.js +94 -74
  76. package/lib/core/type1_parser.js +89 -69
  77. package/lib/core/unicode.js +1654 -1654
  78. package/lib/core/worker.js +275 -290
  79. package/lib/core/worker_stream.js +101 -210
  80. package/lib/core/writer.js +242 -0
  81. package/lib/display/annotation_layer.js +772 -1041
  82. package/lib/display/annotation_storage.js +89 -0
  83. package/lib/display/api.js +1575 -1868
  84. package/lib/display/api_compatibility.js +12 -17
  85. package/lib/display/canvas.js +370 -222
  86. package/lib/display/content_disposition.js +40 -59
  87. package/lib/display/display_utils.js +341 -536
  88. package/lib/display/fetch_stream.js +188 -304
  89. package/lib/display/font_loader.js +282 -414
  90. package/lib/display/metadata.js +81 -99
  91. package/lib/display/network.js +362 -511
  92. package/lib/display/network_utils.js +25 -18
  93. package/lib/display/node_stream.js +283 -465
  94. package/lib/display/node_utils.js +87 -0
  95. package/lib/display/optional_content_config.js +184 -0
  96. package/lib/display/pattern_helper.js +93 -44
  97. package/lib/display/svg.js +1163 -1401
  98. package/lib/display/text_layer.js +154 -137
  99. package/lib/display/transport_stream.js +237 -375
  100. package/lib/display/webgl.js +70 -83
  101. package/lib/display/worker_options.js +3 -3
  102. package/lib/display/xml_parser.js +303 -392
  103. package/lib/examples/node/domstubs.js +37 -37
  104. package/lib/pdf.js +220 -58
  105. package/lib/pdf.worker.js +14 -6
  106. package/lib/shared/compatibility.js +3 -246
  107. package/lib/shared/is_node.js +7 -6
  108. package/lib/shared/message_handler.js +327 -332
  109. package/lib/shared/util.js +271 -306
  110. package/lib/test/unit/annotation_spec.js +1902 -763
  111. package/lib/test/unit/annotation_storage_spec.js +83 -0
  112. package/lib/test/unit/api_spec.js +790 -592
  113. package/lib/test/unit/bidi_spec.js +7 -7
  114. package/lib/test/unit/cff_parser_spec.js +73 -72
  115. package/lib/test/unit/clitests_helper.js +7 -9
  116. package/lib/test/unit/cmap_spec.js +86 -88
  117. package/lib/test/unit/colorspace_spec.js +346 -154
  118. package/lib/test/unit/core_utils_spec.js +125 -105
  119. package/lib/test/unit/crypto_spec.js +232 -185
  120. package/lib/test/unit/custom_spec.js +150 -24
  121. package/lib/test/unit/display_svg_spec.js +34 -39
  122. package/lib/test/unit/display_utils_spec.js +139 -149
  123. package/lib/test/unit/document_spec.js +128 -17
  124. package/lib/test/unit/encodings_spec.js +12 -34
  125. package/lib/test/unit/evaluator_spec.js +112 -91
  126. package/lib/test/unit/fetch_stream_spec.js +31 -29
  127. package/lib/test/unit/function_spec.js +206 -204
  128. package/lib/test/unit/jasmine-boot.js +48 -32
  129. package/lib/test/unit/message_handler_spec.js +173 -159
  130. package/lib/test/unit/metadata_spec.js +71 -71
  131. package/lib/test/unit/murmurhash3_spec.js +12 -12
  132. package/lib/test/unit/network_spec.js +13 -11
  133. package/lib/test/unit/network_utils_spec.js +158 -144
  134. package/lib/test/unit/node_stream_spec.js +76 -90
  135. package/lib/test/unit/parser_spec.js +108 -114
  136. package/lib/test/unit/pdf_find_controller_spec.js +55 -86
  137. package/lib/test/unit/pdf_find_utils_spec.js +32 -32
  138. package/lib/test/unit/pdf_history_spec.js +32 -32
  139. package/lib/test/unit/primitives_spec.js +337 -156
  140. package/lib/test/unit/stream_spec.js +16 -14
  141. package/lib/test/unit/test_utils.js +91 -304
  142. package/lib/test/unit/testreporter.js +33 -22
  143. package/lib/test/unit/type1_parser_spec.js +42 -42
  144. package/lib/test/unit/ui_utils_spec.js +299 -461
  145. package/lib/test/unit/unicode_spec.js +42 -42
  146. package/lib/test/unit/util_spec.js +129 -149
  147. package/lib/test/unit/writer_spec.js +84 -0
  148. package/lib/web/annotation_layer_builder.js +78 -111
  149. package/lib/web/app.js +1542 -1267
  150. package/lib/web/app_options.js +76 -91
  151. package/lib/web/base_tree_viewer.js +100 -0
  152. package/lib/web/base_viewer.js +869 -834
  153. package/lib/web/chromecom.js +165 -252
  154. package/lib/web/debugger.js +149 -205
  155. package/lib/web/download_manager.js +34 -58
  156. package/lib/web/firefox_print_service.js +62 -34
  157. package/lib/web/firefoxcom.js +206 -374
  158. package/lib/web/genericcom.js +26 -108
  159. package/lib/web/genericl10n.js +24 -153
  160. package/lib/web/grab_to_pan.js +30 -30
  161. package/lib/web/interfaces.js +80 -254
  162. package/lib/web/overlay_manager.js +70 -246
  163. package/lib/web/password_prompt.js +38 -64
  164. package/lib/web/pdf_attachment_viewer.js +150 -126
  165. package/lib/web/pdf_cursor_tools.js +75 -102
  166. package/lib/web/pdf_document_properties.js +229 -383
  167. package/lib/web/pdf_find_bar.js +136 -170
  168. package/lib/web/pdf_find_controller.js +492 -548
  169. package/lib/web/pdf_find_utils.js +13 -13
  170. package/lib/web/pdf_history.js +397 -406
  171. package/lib/web/pdf_layer_viewer.js +208 -0
  172. package/lib/web/pdf_link_service.js +304 -348
  173. package/lib/web/pdf_outline_viewer.js +119 -212
  174. package/lib/web/pdf_page_view.js +474 -513
  175. package/lib/web/pdf_presentation_mode.js +308 -357
  176. package/lib/web/pdf_print_service.js +96 -110
  177. package/lib/web/pdf_rendering_queue.js +87 -108
  178. package/lib/web/pdf_sidebar.js +286 -302
  179. package/lib/web/pdf_sidebar_resizer.js +92 -119
  180. package/lib/web/pdf_single_page_viewer.js +77 -126
  181. package/lib/web/pdf_thumbnail_view.js +289 -297
  182. package/lib/web/pdf_thumbnail_viewer.js +202 -206
  183. package/lib/web/pdf_viewer.component.js +20 -21
  184. package/lib/web/pdf_viewer.js +55 -115
  185. package/lib/web/preferences.js +69 -273
  186. package/lib/web/secondary_toolbar.js +164 -196
  187. package/lib/web/text_layer_builder.js +284 -319
  188. package/lib/web/toolbar.js +217 -210
  189. package/lib/web/ui_utils.js +274 -421
  190. package/lib/web/view_history.js +52 -226
  191. package/lib/web/viewer_compatibility.js +21 -6
  192. package/package.json +4 -9
  193. package/types/display/annotation_layer.d.ts +61 -0
  194. package/types/display/annotation_storage.d.ts +36 -0
  195. package/types/display/api.d.ts +1107 -0
  196. package/types/display/api_compatibility.d.ts +1 -0
  197. package/types/display/canvas.d.ts +4 -0
  198. package/types/display/content_disposition.d.ts +7 -0
  199. package/types/display/display_utils.d.ts +243 -0
  200. package/types/display/fetch_stream.d.ts +67 -0
  201. package/types/display/font_loader.d.ts +19 -0
  202. package/types/display/metadata.d.ts +9 -0
  203. package/types/display/network.d.ts +80 -0
  204. package/types/display/network_utils.d.ts +14 -0
  205. package/types/display/node_stream.d.ts +72 -0
  206. package/types/display/node_utils.d.ts +6 -0
  207. package/types/display/optional_content_config.d.ts +12 -0
  208. package/types/display/pattern_helper.d.ts +5 -0
  209. package/types/display/svg.d.ts +2 -0
  210. package/types/display/text_layer.d.ts +83 -0
  211. package/types/display/transport_stream.d.ts +57 -0
  212. package/types/display/webgl.d.ts +20 -0
  213. package/types/display/worker_options.d.ts +27 -0
  214. package/types/display/xml_parser.d.ts +35 -0
  215. package/types/pdf.d.ts +33 -0
  216. package/types/shared/compatibility.d.ts +1 -0
  217. package/types/shared/is_node.d.ts +1 -0
  218. package/types/shared/message_handler.d.ts +62 -0
  219. package/types/shared/util.d.ts +421 -0
  220. package/web/images/shadow.png +0 -0
  221. package/web/pdf_viewer.css +29 -27
  222. package/web/pdf_viewer.js +3524 -4746
  223. package/web/pdf_viewer.js.map +1 -1
  224. package/webpack.js +6 -5
  225. package/external/streams/streams-lib.js +0 -3962
  226. package/external/url/url-lib.js +0 -627
  227. package/lib/shared/streams_polyfill.js +0 -43
  228. package/lib/shared/url_polyfill.js +0 -56
  229. 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 2019 Mozilla Foundation
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 _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
24
+ var _test_utils = require("./test_utils.js");
25
25
 
26
- var _test_utils = require("./test_utils");
26
+ var _util = require("../../shared/util.js");
27
27
 
28
- var _util = require("../../shared/util");
28
+ var _display_utils = require("../../display/display_utils.js");
29
29
 
30
- var _display_utils = require("../../display/display_utils");
30
+ var _api = require("../../display/api.js");
31
31
 
32
- var _api = require("../../display/api");
32
+ var _ui_utils = require("../../web/ui_utils.js");
33
33
 
34
- var _worker_options = require("../../display/worker_options");
34
+ var _image_utils = require("../../core/image_utils.js");
35
35
 
36
- var _is_node = _interopRequireDefault(require("../../shared/is_node"));
36
+ var _worker_options = require("../../display/worker_options.js");
37
37
 
38
- var _metadata = require("../../display/metadata");
38
+ var _is_node = require("../../shared/is_node.js");
39
39
 
40
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
40
+ var _metadata = require("../../display/metadata.js");
41
41
 
42
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
42
+ var _node_utils = require("../../display/node_utils.js");
43
43
 
44
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
45
-
46
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
47
-
48
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
49
-
50
- function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
51
-
52
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
53
-
54
- function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
55
-
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 ((0, _is_node["default"])()) {
63
- CanvasFactory = new _test_utils.NodeCanvasFactory();
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('getDocument', function () {
83
- it('creates pdf doc from URL', function (done) {
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
- })["catch"](done.fail);
87
+ }).catch(done.fail);
100
88
  });
101
- it('creates pdf doc from URL and aborts before worker initialized', function (done) {
89
+ it("creates pdf doc from URL and aborts before worker initialized", function (done) {
102
90
  var loadingTask = (0, _api.getDocument)(basicApiGetDocumentParams);
103
- var destroyed = loadingTask.destroy();
91
+ const destroyed = loadingTask.destroy();
104
92
  loadingTask.promise.then(function (reason) {
105
- done.fail('shall fail loading');
106
- })["catch"](function (reason) {
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('creates pdf doc from URL and aborts loading after worker initialized', function (done) {
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
- })["catch"](done.fail);
109
+ }).catch(done.fail);
122
110
  });
123
- it('creates pdf doc from typed array', function (done) {
124
- var typedArrayPdfPromise;
111
+ it("creates pdf doc from typed array", function (done) {
112
+ let typedArrayPdfPromise;
125
113
 
126
- if ((0, _is_node["default"])()) {
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(function (typedArrayPdf) {
124
+ typedArrayPdfPromise.then(typedArrayPdf => {
137
125
  expect(typedArrayPdf.length).toEqual(basicApiFileLength);
138
- var loadingTask = (0, _api.getDocument)(typedArrayPdf);
139
- var progressReportedCapability = (0, _util.createPromiseCapability)();
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
- })["catch"](done.fail);
138
+ }).catch(done.fail);
151
139
  });
152
- it('creates pdf doc from invalid PDF file', function (done) {
153
- var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('bug1020226.pdf'));
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('shall fail loading');
156
- })["catch"](function (error) {
157
- expect(error instanceof _util.InvalidPDFException).toEqual(true);
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('creates pdf doc from non-existent URL', function (done) {
162
- var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('non-existent.pdf'));
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('shall fail loading');
165
- })["catch"](function (error) {
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('creates pdf doc from PDF file protected with user and owner password', function (done) {
171
- var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('pr6531_1.pdf'));
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('qwerty');
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('asdfasdf');
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
- })["catch"](done.fail);
184
+ }).catch(done.fail);
196
185
  });
197
- it('creates pdf doc from PDF file protected with only a user password', function (done) {
198
- var filename = 'pr6531_2.pdf';
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('shall fail with no password');
204
- return Promise.reject(new Error('loadingTask should be rejected'));
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: 'qwerty'
200
+ password: "qwerty"
212
201
  }));
213
202
  var result2 = passwordIncorrectLoadingTask.promise.then(function () {
214
- done.fail('shall fail with wrong password');
215
- return Promise.reject(new Error('loadingTask should be rejected'));
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: 'asdfasdf'
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
- })["catch"](done.fail);
219
+ }).catch(done.fail);
231
220
  });
232
- it('creates pdf doc from password protected PDF file and aborts/throws ' + 'in the onPassword callback (issue 7806)', function (done) {
233
- var filename = 'issue3371.pdf';
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: 'qwerty'
225
+ password: "qwerty"
237
226
  }));
238
- var passwordNeededDestroyed;
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('shall fail since the loadingTask should be destroyed');
251
- return Promise.reject(new Error('loadingTask should be rejected'));
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('Incorrect password');
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('shall fail since the onPassword callback should throw');
268
- return Promise.reject(new Error('loadingTask should be rejected'));
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
- })["catch"](done.fail);
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('PDFWorker', function () {
280
- it('worker created or destroyed', function (done) {
281
- if ((0, _is_node["default"])()) {
282
- pending('Worker is not supported in Node.js.');
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: 'test1'
285
+ name: "test1"
287
286
  });
288
287
  worker.promise.then(function () {
289
- expect(worker.name).toEqual('test1');
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
- })["catch"](done.fail);
297
+ }).catch(done.fail);
299
298
  });
300
- it('worker created or destroyed by getDocument', function (done) {
301
- if ((0, _is_node["default"])()) {
302
- pending('Worker is not supported in Node.js.');
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
- })["catch"](done.fail);
318
+ }).catch(done.fail);
320
319
  });
321
- it('worker created and can be used in getDocument', function (done) {
322
- if ((0, _is_node["default"])()) {
323
- pending('Worker is not supported in Node.js.');
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: 'test1'
326
+ name: "test1"
328
327
  });
329
328
  var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(basicApiFileName, {
330
- worker: 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
- })["catch"](done.fail);
344
+ }).catch(done.fail);
346
345
  });
347
- it('creates more than one worker', function (done) {
348
- if ((0, _is_node["default"])()) {
349
- pending('Worker is not supported in Node.js.');
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: 'test1'
352
+ name: "test1"
354
353
  });
355
354
  var worker2 = new _api.PDFWorker({
356
- name: 'test2'
355
+ name: "test2"
357
356
  });
358
357
  var worker3 = new _api.PDFWorker({
359
- name: 'test3'
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
- })["catch"](done.fail);
367
+ }).catch(done.fail);
369
368
  });
370
- it('gets current workerSrc', function () {
371
- if ((0, _is_node["default"])()) {
372
- pending('Worker is not supported in Node.js.');
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
- var workerSrc = _api.PDFWorker.getWorkerSrc();
374
+ const workerSrc = _api.PDFWorker.getWorkerSrc();
376
375
 
377
- expect(_typeof(workerSrc)).toEqual('string');
376
+ expect(typeof workerSrc).toEqual("string");
378
377
  expect(workerSrc).toEqual(_worker_options.GlobalWorkerOptions.workerSrc);
379
378
  });
380
379
  });
381
- describe('PDFDocument', function () {
382
- var loadingTask;
383
- var doc;
380
+ describe("PDFDocument", function () {
381
+ let pdfLoadingTask, pdfDocument;
384
382
  beforeAll(function (done) {
385
- loadingTask = (0, _api.getDocument)(basicApiGetDocumentParams);
386
- loadingTask.promise.then(function (data) {
387
- doc = data;
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
- loadingTask.destroy().then(done);
390
+ pdfLoadingTask.destroy().then(done);
393
391
  });
394
- it('gets number of pages', function () {
395
- expect(doc.numPages).toEqual(3);
392
+ it("gets number of pages", function () {
393
+ expect(pdfDocument.numPages).toEqual(3);
396
394
  });
397
- it('gets fingerprint', function () {
398
- var fingerprint = doc.fingerprint;
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('gets page', function (done) {
403
- var promise = doc.getPage(1);
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.pageIndex).toEqual(0);
402
+ expect(data.pageNumber).toEqual(1);
407
403
  done();
408
- })["catch"](done.fail);
404
+ }).catch(done.fail);
409
405
  });
410
- it('gets non-existent page', function (done) {
411
- var outOfRangePromise = doc.getPage(100);
412
- var nonIntegerPromise = doc.getPage(2.5);
413
- var nonNumberPromise = doc.getPage('1');
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('shall fail for out-of-range pageNumber parameter');
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('shall fail for non-integer pageNumber parameter');
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('shall fail for non-number pageNumber parameter');
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
- })["catch"](done.fail);
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('gets page index', function (done) {
454
+ it("gets page index", function (done) {
434
455
  var ref = {
435
456
  num: 17,
436
457
  gen: 0
437
458
  };
438
- var promise = doc.getPageIndex(ref);
459
+ var promise = pdfDocument.getPageIndex(ref);
439
460
  promise.then(function (pageIndex) {
440
461
  expect(pageIndex).toEqual(1);
441
462
  done();
442
- })["catch"](done.fail);
463
+ }).catch(done.fail);
443
464
  });
444
- it('gets invalid page index', function (done) {
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 = doc.getPageIndex(ref);
470
+ var promise = pdfDocument.getPageIndex(ref);
450
471
  promise.then(function () {
451
- done.fail('shall fail for invalid page reference.');
452
- })["catch"](function (reason) {
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('gets destinations, from /Dests dictionary', function (done) {
458
- var promise = doc.getDestinations();
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: 'XYZ'
486
+ name: "XYZ"
466
487
  }, 0, 841.89, null]
467
488
  });
468
489
  done();
469
- })["catch"](done.fail);
490
+ }).catch(done.fail);
470
491
  });
471
- it('gets a destination, from /Dests dictionary', function (done) {
472
- var promise = doc.getDestination('chapter1');
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: 'XYZ'
499
+ name: "XYZ"
479
500
  }, 0, 841.89, null]);
480
501
  done();
481
- })["catch"](done.fail);
502
+ }).catch(done.fail);
482
503
  });
483
- it('gets a non-existent destination, from /Dests dictionary', function (done) {
484
- var promise = doc.getDestination('non-existent-named-destination');
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
- })["catch"](done.fail);
509
+ }).catch(done.fail);
489
510
  });
490
- it('gets destinations, from /Names (NameTree) dictionary', function (done) {
491
- var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue6204.pdf'));
492
- var promise = loadingTask.promise.then(function (pdfDocument) {
493
- return pdfDocument.getDestinations();
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
- 'Page.1': [{
518
+ "Page.1": [{
498
519
  num: 1,
499
520
  gen: 0
500
521
  }, {
501
- name: 'XYZ'
522
+ name: "XYZ"
502
523
  }, 0, 375, null],
503
- 'Page.2': [{
524
+ "Page.2": [{
504
525
  num: 6,
505
526
  gen: 0
506
527
  }, {
507
- name: 'XYZ'
528
+ name: "XYZ"
508
529
  }, 0, 375, null]
509
530
  });
510
531
  loadingTask.destroy().then(done);
511
- })["catch"](done.fail);
532
+ }).catch(done.fail);
512
533
  });
513
- it('gets a destination, from /Names (NameTree) dictionary', function (done) {
514
- var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue6204.pdf'));
515
- var promise = loadingTask.promise.then(function (pdfDocument) {
516
- return pdfDocument.getDestination('Page.1');
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: 'XYZ'
544
+ name: "XYZ"
524
545
  }, 0, 375, null]);
525
546
  loadingTask.destroy().then(done);
526
- })["catch"](done.fail);
547
+ }).catch(done.fail);
527
548
  });
528
- it('gets a non-existent destination, from /Names (NameTree) dictionary', function (done) {
529
- var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue6204.pdf'));
530
- var promise = loadingTask.promise.then(function (pdfDocument) {
531
- return pdfDocument.getDestination('non-existent-named-destination');
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
- })["catch"](done.fail);
557
+ }).catch(done.fail);
537
558
  });
538
- it('gets non-string destination', function (done) {
539
- var numberPromise = doc.getDestination(4.3);
540
- var booleanPromise = doc.getDestination(true);
541
- var arrayPromise = doc.getDestination([{
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: 'XYZ'
566
+ name: "XYZ"
546
567
  }, 0, 841.89, null]);
547
568
  numberPromise = numberPromise.then(function () {
548
- throw new Error('shall fail for non-string destination.');
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('shall fail for non-string destination.');
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('shall fail for non-string destination.');
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('gets non-existent page labels', function (done) {
565
- var promise = doc.getPageLabels();
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
- })["catch"](done.fail);
590
+ }).catch(done.fail);
570
591
  });
571
- it('gets page labels', function (done) {
572
- var loadingTask0 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('bug793632.pdf'));
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)('issue1453.pdf'));
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)('rotation.pdf'));
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)('bad-PageLabels.pdf'));
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(['i', 'ii', 'iii', '1']);
590
- expect(pageLabels[1]).toEqual(['Front Page1']);
591
- expect(pageLabels[2]).toEqual(['1', '2']);
592
- expect(pageLabels[3]).toEqual(['X3']);
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
- })["catch"](done.fail);
615
+ }).catch(done.fail);
595
616
  });
596
- it('gets default page layout', function (done) {
597
- var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('tracemonkey.pdf'));
598
- loadingTask.promise.then(function (pdfDocument) {
599
- return pdfDocument.getPageLayout();
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
- })["catch"](done.fail);
624
+ }).catch(done.fail);
604
625
  });
605
- it('gets non-default page layout', function (done) {
606
- doc.getPageLayout().then(function (mode) {
607
- expect(mode).toEqual('SinglePage');
626
+ it("gets non-default page layout", function (done) {
627
+ pdfDocument.getPageLayout().then(function (mode) {
628
+ expect(mode).toEqual("SinglePage");
608
629
  done();
609
- })["catch"](done.fail);
630
+ }).catch(done.fail);
610
631
  });
611
- it('gets default page mode', function (done) {
612
- var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('tracemonkey.pdf'));
613
- loadingTask.promise.then(function (pdfDocument) {
614
- return pdfDocument.getPageMode();
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('UseNone');
637
+ expect(mode).toEqual("UseNone");
617
638
  loadingTask.destroy().then(done);
618
- })["catch"](done.fail);
639
+ }).catch(done.fail);
619
640
  });
620
- it('gets non-default page mode', function (done) {
621
- doc.getPageMode().then(function (mode) {
622
- expect(mode).toEqual('UseOutlines');
641
+ it("gets non-default page mode", function (done) {
642
+ pdfDocument.getPageMode().then(function (mode) {
643
+ expect(mode).toEqual("UseOutlines");
623
644
  done();
624
- })["catch"](done.fail);
645
+ }).catch(done.fail);
625
646
  });
626
- it('gets default viewer preferences', function (done) {
627
- var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('tracemonkey.pdf'));
628
- loadingTask.promise.then(function (pdfDocument) {
629
- return pdfDocument.getViewerPreferences();
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(_typeof(prefs) === 'object' && prefs !== null && (0, _util.isEmptyObj)(prefs)).toEqual(true);
652
+ expect(prefs).toEqual(null);
632
653
  loadingTask.destroy().then(done);
633
- })["catch"](done.fail);
654
+ }).catch(done.fail);
634
655
  });
635
- it('gets non-default viewer preferences', function (done) {
636
- doc.getViewerPreferences().then(function (prefs) {
656
+ it("gets non-default viewer preferences", function (done) {
657
+ pdfDocument.getViewerPreferences().then(function (prefs) {
637
658
  expect(prefs).toEqual({
638
- Direction: 'L2R'
659
+ Direction: "L2R"
639
660
  });
640
661
  done();
641
- })["catch"](done.fail);
642
- });
643
- it('gets default open action destination', function (done) {
644
- var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('tracemonkey.pdf'));
645
- loadingTask.promise.then(function (pdfDocument) {
646
- return pdfDocument.getOpenActionDestination();
647
- }).then(function (dest) {
648
- expect(dest).toEqual(null);
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
- })["catch"](done.fail);
671
+ }).catch(done.fail);
651
672
  });
652
- it('gets non-default open action destination', function (done) {
653
- doc.getOpenActionDestination().then(function (dest) {
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: 'FitH'
679
+ name: "FitH"
659
680
  }, null]);
681
+ expect(openAction.action).toBeUndefined();
660
682
  done();
661
- })["catch"](done.fail);
662
- });
663
- it('gets non-existent attachments', function (done) {
664
- var promise = doc.getAttachments();
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
- })["catch"](done.fail);
709
+ }).catch(done.fail);
669
710
  });
670
- it('gets attachments', function (done) {
671
- if ((0, _is_node["default"])()) {
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['Press Quality.joboptions'];
681
- expect(attachment.filename).toEqual('Press Quality.joboptions');
682
- expect(attachment.content instanceof Uint8Array).toBeTruthy();
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
- })["catch"](done.fail);
721
+ }).catch(done.fail);
686
722
  });
687
- it('gets javascript', function (done) {
688
- var promise = doc.getJavaScript();
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
- })["catch"](done.fail);
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('gets javascript with printing instructions (JS action)', function (done) {
707
- var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue6106.pdf'));
708
- var promise = loadingTask.promise.then(function (doc) {
709
- return doc.getJavaScript();
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(['this.print({bUI:true,bSilent:false,bShrinkToFit:true});']);
713
- expect(data[0]).toMatch(viewerPrintRegExp);
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
- })["catch"](done.fail);
739
+ }).catch(done.fail);
716
740
  });
717
- it('gets non-existent outline', function (done) {
718
- var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('tracemonkey.pdf'));
719
- var promise = loadingTask.promise.then(function (pdfDocument) {
720
- return pdfDocument.getOutline();
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
- })["catch"](done.fail);
749
+ }).catch(done.fail);
726
750
  });
727
- it('gets outline', function (done) {
728
- var promise = doc.getOutline();
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('Chapter 1');
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('Paragraph 1.1');
766
+ expect(outlineItem.items[0].title).toEqual("Paragraph 1.1");
743
767
  done();
744
- })["catch"](done.fail);
768
+ }).catch(done.fail);
745
769
  });
746
- it('gets outline containing a url', function (done) {
747
- var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue3214.pdf'));
748
- loadingTask.promise.then(function (pdfDocument) {
749
- pdfDocument.getOutline().then(function (outline) {
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(_typeof(outlineItemTwo.title)).toEqual('string');
777
+ expect(typeof outlineItemTwo.title).toEqual("string");
754
778
  expect(outlineItemTwo.dest).toEqual(null);
755
- expect(outlineItemTwo.url).toEqual('http://google.com/');
756
- expect(outlineItemTwo.unsafeUrl).toEqual('http://google.com');
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
- })["catch"](done.fail);
788
+ }).catch(done.fail);
765
789
  });
766
- it('gets non-existent permissions', function (done) {
767
- doc.getPermissions().then(function (permissions) {
790
+ it("gets non-existent permissions", function (done) {
791
+ pdfDocument.getPermissions().then(function (permissions) {
768
792
  expect(permissions).toEqual(null);
769
793
  done();
770
- })["catch"](done.fail);
794
+ }).catch(done.fail);
771
795
  });
772
- it('gets permissions', function (done) {
773
- var loadingTask0 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue9972-1.pdf'));
774
- var promise0 = loadingTask0.promise.then(function (pdfDocument) {
775
- return pdfDocument.getPermissions();
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
- var loadingTask1 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue9972-2.pdf'));
778
- var promise1 = loadingTask1.promise.then(function (pdfDocument) {
779
- return pdfDocument.getPermissions();
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
- var loadingTask2 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue9972-3.pdf'));
782
- var promise2 = loadingTask2.promise.then(function (pdfDocument) {
783
- return pdfDocument.getPermissions();
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
- var totalPermissionCount = Object.keys(_util.PermissionFlag).length;
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
- })["catch"](done.fail);
796
- });
797
- it('gets metadata', function (done) {
798
- var promise = doc.getMetadata();
799
- promise.then(function (_ref) {
800
- var info = _ref.info,
801
- metadata = _ref.metadata,
802
- contentDispositionFilename = _ref.contentDispositionFilename;
803
- expect(info['Title']).toEqual('Basic API Test');
804
- expect(info['Custom']).toEqual(undefined);
805
- expect(info['PDFFormatVersion']).toEqual('1.7');
806
- expect(info['IsLinearized']).toEqual(false);
807
- expect(info['IsAcroFormPresent']).toEqual(false);
808
- expect(info['IsXFAPresent']).toEqual(false);
809
- expect(info['IsCollectionPresent']).toEqual(false);
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('dc:title')).toEqual('Basic API Test');
836
+ expect(metadata.get("dc:title")).toEqual("Basic API Test");
812
837
  expect(contentDispositionFilename).toEqual(null);
813
838
  done();
814
- })["catch"](done.fail);
815
- });
816
- it('gets metadata, with custom info dict entries', function (done) {
817
- var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('tracemonkey.pdf'));
818
- loadingTask.promise.then(function (pdfDocument) {
819
- return pdfDocument.getMetadata();
820
- }).then(function (_ref2) {
821
- var info = _ref2.info,
822
- metadata = _ref2.metadata,
823
- contentDispositionFilename = _ref2.contentDispositionFilename;
824
- expect(info['Creator']).toEqual('TeX');
825
- expect(info['Producer']).toEqual('pdfeTeX-1.21a');
826
- expect(info['CreationDate']).toEqual('D:20090401163925-07\'00\'');
827
- var custom = info['Custom'];
828
- expect(_typeof(custom) === 'object' && custom !== null).toEqual(true);
829
- expect(custom['PTEX.Fullbanner']).toEqual('This is pdfeTeX, ' + 'Version 3.141592-1.21a-2.2 (Web2C 7.5.4) kpathsea version 3.5.6');
830
- expect(info['PDFFormatVersion']).toEqual('1.4');
831
- expect(info['IsLinearized']).toEqual(false);
832
- expect(info['IsAcroFormPresent']).toEqual(false);
833
- expect(info['IsXFAPresent']).toEqual(false);
834
- expect(info['IsCollectionPresent']).toEqual(false);
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
- })["catch"](done.fail);
864
+ }).catch(done.fail);
839
865
  });
840
- it('gets data', function (done) {
841
- var promise = doc.getData();
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
- })["catch"](done.fail);
891
+ }).catch(done.fail);
847
892
  });
848
- it('gets download info', function (done) {
849
- var promise = doc.getDownloadInfo();
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
- })["catch"](done.fail);
900
+ }).catch(done.fail);
856
901
  });
857
- it('gets document stats', function (done) {
858
- var promise = doc.getStats();
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
- })["catch"](done.fail);
910
+ }).catch(done.fail);
866
911
  });
867
- it('checks that fingerprints are unique', function (done) {
868
- var loadingTask1 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue4436r.pdf'));
869
- var loadingTask2 = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue4575.pdf'));
870
- var promises = [loadingTask1.promise, loadingTask2.promise];
871
- Promise.all(promises).then(function (data) {
872
- var fingerprint1 = data[0].fingerprint;
873
- expect(_typeof(fingerprint1)).toEqual('string');
874
- expect(fingerprint1.length > 0).toEqual(true);
875
- var fingerprint2 = data[1].fingerprint;
876
- expect(_typeof(fingerprint2)).toEqual('string');
877
- expect(fingerprint2.length > 0).toEqual(true);
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
- })["catch"](done.fail);
929
+ }).catch(done.fail);
881
930
  });
882
- describe('Cross-origin', function () {
931
+ describe("Cross-origin", function () {
883
932
  var loadingTask;
884
933
 
885
934
  function _checkCanLoad(expectSuccess, filename, options) {
886
- if ((0, _is_node["default"])()) {
887
- pending('Cannot simulate cross-origin requests in Node.js');
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 === 'localhost') {
894
- url.hostname = '127.0.0.1';
895
- } else if (params.url.hostname === '127.0.0.1') {
896
- url.hostname = 'localhost';
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('Can only run cross-origin test on localhost!');
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('There should not be any error');
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('server disallows cors', function (done) {
932
- testCannotLoad('basicapi.pdf').then(done);
980
+ it("server disallows cors", function (done) {
981
+ testCannotLoad("basicapi.pdf").then(done);
933
982
  });
934
- it('server allows cors without credentials, default withCredentials', function (done) {
935
- testCanLoad('basicapi.pdf?cors=withoutCredentials').then(done);
983
+ it("server allows cors without credentials, default withCredentials", function (done) {
984
+ testCanLoad("basicapi.pdf?cors=withoutCredentials").then(done);
936
985
  });
937
- it('server allows cors without credentials, and withCredentials=false', function (done) {
938
- testCanLoad('basicapi.pdf?cors=withoutCredentials', {
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('server allows cors without credentials, but withCredentials=true', function (done) {
943
- testCannotLoad('basicapi.pdf?cors=withoutCredentials', {
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('server allows cors with credentials, and withCredentials=true', function (done) {
948
- testCanLoad('basicapi.pdf?cors=withCredentials', {
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('server allows cors with credentials, and withCredentials=false', function (done) {
953
- testCanLoad('basicapi.pdf?cors=withCredentials', {
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('Page', function () {
960
- var loadingTask;
961
- var pdfDocument, page;
1008
+ describe("Page", function () {
1009
+ let pdfLoadingTask, pdfDocument, page;
962
1010
  beforeAll(function (done) {
963
- loadingTask = (0, _api.getDocument)(basicApiGetDocumentParams);
964
- loadingTask.promise.then(function (doc) {
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
- })["catch"](done.fail);
1018
+ }).catch(done.fail);
971
1019
  });
972
1020
  afterAll(function (done) {
973
- loadingTask.destroy().then(done);
1021
+ pdfLoadingTask.destroy().then(done);
974
1022
  });
975
- it('gets page number', function () {
1023
+ it("gets page number", function () {
976
1024
  expect(page.pageNumber).toEqual(1);
977
1025
  });
978
- it('gets rotate', function () {
1026
+ it("gets rotate", function () {
979
1027
  expect(page.rotate).toEqual(0);
980
1028
  });
981
- it('gets ref', function () {
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('gets userUnit', function () {
1035
+ it("gets userUnit", function () {
988
1036
  expect(page.userUnit).toEqual(1.0);
989
1037
  });
990
- it('gets view', function () {
1038
+ it("gets view", function () {
991
1039
  expect(page.view).toEqual([0, 0, 595.28, 841.89]);
992
1040
  });
993
- it('gets viewport', function () {
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 respecting "dontFlip" argument', function () {
1006
- var scale = 1;
1007
- var rotation = 135;
1008
- var viewport = page.getViewport({
1009
- scale: scale,
1010
- rotation: rotation
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
- var dontFlipViewport = page.getViewport({
1013
- scale: scale,
1014
- rotation: rotation,
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('gets annotations', function (done) {
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: 'display'
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: 'print'
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
- })["catch"](done.fail);
1126
+ }).catch(done.fail);
1041
1127
  });
1042
- it('gets annotations containing relative URLs (bug 766086)', function (done) {
1043
- var filename = 'bug766086.pdf';
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: 'http://www.example.com/test/pdfs/qwerty.pdf'
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: 'qwerty.pdf'
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('../../0021/002156/215675E.pdf#15');
1072
- expect(docBaseUrlAnnotations[0].url).toEqual('http://www.example.com/0021/002156/215675E.pdf#15');
1073
- expect(docBaseUrlAnnotations[0].unsafeUrl).toEqual('../../0021/002156/215675E.pdf#15');
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('../../0021/002156/215675E.pdf#15');
1161
+ expect(invalidDocBaseUrlAnnotations[0].unsafeUrl).toEqual("../../0021/002156/215675E.pdf#15");
1076
1162
  Promise.all([defaultLoadingTask.destroy(), docBaseUrlLoadingTask.destroy(), invalidDocBaseUrlLoadingTask.destroy()]).then(done);
1077
- })["catch"](done.fail);
1163
+ }).catch(done.fail);
1078
1164
  });
1079
- it('gets text content', function (done) {
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
- })["catch"](done.fail);
1093
- });
1094
- it('gets text content, with correct properties (issue 8276)', function (done) {
1095
- var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue8276_reduced.pdf'));
1096
- loadingTask.promise.then(function (pdfDoc) {
1097
- pdfDoc.getPage(1).then(function (pdfPage) {
1098
- pdfPage.getTextContent().then(function (_ref3) {
1099
- var items = _ref3.items,
1100
- styles = _ref3.styles;
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(['Times']);
1189
+ expect(Object.keys(styles)).toEqual(["Times"]);
1103
1190
  expect(items[0]).toEqual({
1104
- dir: 'ltr',
1105
- fontName: 'Times',
1191
+ dir: "ltr",
1192
+ fontName: "Times",
1106
1193
  height: 18,
1107
- str: 'Issue 8276',
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: 'serif',
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
- })["catch"](done.fail);
1207
+ }).catch(done.fail);
1121
1208
  });
1122
- it('gets operator list', function (done) {
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
- })["catch"](done.fail);
1130
- });
1131
- it('gets operatorList with JPEG image (issue 4888)', function (done) {
1132
- var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('cmykjpeg.pdf'));
1133
- loadingTask.promise.then(function (pdfDoc) {
1134
- pdfDoc.getPage(1).then(function (pdfPage) {
1135
- pdfPage.getOperatorList().then(function (opList) {
1136
- var imgIndex = opList.fnArray.indexOf(_util.OPS.paintImageXObject);
1137
- var imgArgs = opList.argsArray[imgIndex];
1138
-
1139
- var _pdfPage$objs$get = pdfPage.objs.get(imgArgs[0]),
1140
- data = _pdfPage$objs$get.data;
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
- })["catch"](done.fail);
1233
+ }).catch(done.fail);
1148
1234
  });
1149
- it('gets document stats after parsing page', function (done) {
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
- })["catch"](done.fail);
1279
+ }).catch(done.fail);
1165
1280
  });
1166
- it('gets page stats after parsing page, without `pdfBug` set', function (done) {
1167
- page.getOperatorList().then(function (opList) {
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(function (stats) {
1284
+ }).then(stats => {
1170
1285
  expect(stats).toEqual(null);
1171
1286
  done();
1172
1287
  }, done.fail);
1173
1288
  });
1174
- it('gets page stats after parsing page, with `pdfBug` set', function (done) {
1175
- var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(basicApiFileName, {
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(function (pdfDoc) {
1179
- return pdfDoc.getPage(1).then(function (pdfPage) {
1180
- return pdfPage.getOperatorList().then(function (opList) {
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(function (stats) {
1299
+ }).then(stats => {
1185
1300
  expect(stats instanceof _display_utils.StatTimer).toEqual(true);
1186
1301
  expect(stats.times.length).toEqual(1);
1187
-
1188
- var _stats$times = _slicedToArray(stats.times, 1),
1189
- statEntry = _stats$times[0];
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('gets page stats after rendering page, with `pdfBug` set', function (done) {
1197
- var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(basicApiFileName, {
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
- var canvasAndCtx;
1201
- loadingTask.promise.then(function (pdfDoc) {
1202
- return pdfDoc.getPage(1).then(function (pdfPage) {
1203
- var viewport = pdfPage.getViewport({
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
- var renderTask = pdfPage.render({
1319
+ const renderTask = pdfPage.render({
1208
1320
  canvasContext: canvasAndCtx.context,
1209
1321
  canvasFactory: CanvasFactory,
1210
- viewport: viewport
1322
+ viewport
1211
1323
  });
1212
- return renderTask.promise.then(function () {
1324
+ return renderTask.promise.then(() => {
1213
1325
  return pdfPage.stats;
1214
1326
  });
1215
1327
  });
1216
- }).then(function (stats) {
1328
+ }).then(stats => {
1217
1329
  expect(stats instanceof _display_utils.StatTimer).toEqual(true);
1218
1330
  expect(stats.times.length).toEqual(3);
1219
-
1220
- var _stats$times2 = _slicedToArray(stats.times, 3),
1221
- statEntryOne = _stats$times2[0],
1222
- statEntryTwo = _stats$times2[1],
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('Overall');
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('cancels rendering of page', function (done) {
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: viewport
1350
+ viewport
1244
1351
  });
1245
1352
  renderTask.cancel();
1246
1353
  renderTask.promise.then(function () {
1247
- done.fail('shall cancel rendering');
1248
- })["catch"](function (error) {
1354
+ done.fail("shall cancel rendering");
1355
+ }).catch(function (error) {
1249
1356
  expect(error instanceof _display_utils.RenderingCancelledException).toEqual(true);
1250
- expect(error.type).toEqual('canvas');
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('re-render page, using the same canvas, after cancelling rendering', function (done) {
1256
- var viewport = page.getViewport({
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
- var canvasAndCtx = CanvasFactory.create(viewport.width, viewport.height);
1260
- var renderTask = page.render({
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: viewport
1371
+ viewport
1264
1372
  });
1265
1373
  renderTask.cancel();
1266
- renderTask.promise.then(function () {
1267
- throw new Error('shall cancel rendering');
1268
- }, function (reason) {
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(function () {
1271
- var reRenderTask = page.render({
1378
+ }).then(() => {
1379
+ const reRenderTask = page.render({
1272
1380
  canvasContext: canvasAndCtx.context,
1273
1381
  canvasFactory: CanvasFactory,
1274
- viewport: viewport
1382
+ viewport
1275
1383
  });
1276
1384
  return reRenderTask.promise;
1277
- }).then(function () {
1385
+ }).then(() => {
1278
1386
  CanvasFactory.destroy(canvasAndCtx);
1279
1387
  done();
1280
1388
  }, done.fail);
1281
1389
  });
1282
- it('multiple render() on the same canvas', function (done) {
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: viewport
1399
+ viewport,
1400
+ optionalContentConfigPromise
1291
1401
  });
1292
1402
  var renderTask2 = page.render({
1293
1403
  canvasContext: canvasAndCtx.context,
1294
1404
  canvasFactory: CanvasFactory,
1295
- viewport: viewport
1405
+ viewport,
1406
+ optionalContentConfigPromise
1296
1407
  });
1297
- Promise.all([renderTask1.promise, renderTask2.promise.then(function () {
1298
- done.fail('shall fail rendering');
1299
- }, function (reason) {
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
- describe('Multiple `getDocument` instances', function () {
1305
- var pdf1 = (0, _test_utils.buildGetDocumentParams)('tracemonkey.pdf');
1306
- var pdf2 = (0, _test_utils.buildGetDocumentParams)('TAMReview.pdf');
1307
- var pdf3 = (0, _test_utils.buildGetDocumentParams)('issue6068.pdf');
1308
- var loadingTasks = [];
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
- function renderPDF(_x) {
1311
- return _renderPDF.apply(this, arguments);
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
- function _renderPDF() {
1315
- _renderPDF = _asyncToGenerator(
1316
- /*#__PURE__*/
1317
- _regenerator["default"].mark(function _callee(filename) {
1318
- var loadingTask, pdf, page, viewport, canvasAndCtx, renderTask, data;
1319
- return _regenerator["default"].wrap(function _callee$(_context) {
1320
- while (1) {
1321
- switch (_context.prev = _context.next) {
1322
- case 0:
1323
- loadingTask = (0, _api.getDocument)(filename);
1324
- loadingTasks.push(loadingTask);
1325
- _context.next = 4;
1326
- return loadingTask.promise;
1327
-
1328
- case 4:
1329
- pdf = _context.sent;
1330
- _context.next = 7;
1331
- return pdf.getPage(1);
1332
-
1333
- case 7:
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
- }, _callee);
1358
- }));
1359
- return _renderPDF.apply(this, arguments);
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
- var destroyPromises = loadingTasks.map(function (loadingTask) {
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('should correctly render PDFs in parallel', function (done) {
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
- })["catch"](done.fail);
1585
+ }).catch(done.fail);
1388
1586
  });
1389
1587
  });
1390
- describe('PDFDataRangeTransport', function () {
1391
- var dataPromise;
1588
+ describe("PDFDataRangeTransport", function () {
1589
+ let dataPromise;
1392
1590
  beforeAll(function (done) {
1393
- var fileName = 'tracemonkey.pdf';
1591
+ const fileName = "tracemonkey.pdf";
1394
1592
 
1395
- if ((0, _is_node["default"])()) {
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('should fetch document info and page using ranges', function (done) {
1411
- var initialDataLength = 4000;
1412
- var fetches = 0,
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
- var initialData = data.subarray(0, initialDataLength);
1416
- var transport = new _api.PDFDataRangeTransport(data.length, initialData);
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
- })["catch"](done.fail);
1633
+ }).catch(done.fail);
1436
1634
  });
1437
- it('should fetch document info and page using range and streaming', function (done) {
1438
- var initialDataLength = 4000;
1439
- var fetches = 0,
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
- var initialData = data.subarray(0, initialDataLength);
1443
- var transport = new _api.PDFDataRangeTransport(data.length, initialData);
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
- })["catch"](done.fail);
1666
+ }).catch(done.fail);
1469
1667
  });
1470
- it('should fetch document info and page, without range, ' + 'using complete initialData', function (done) {
1471
- var fetches = 0,
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
- var transport = new _api.PDFDataRangeTransport(data.length, data, true);
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
- })["catch"](done.fail);
1690
+ }).catch(done.fail);
1493
1691
  });
1494
1692
  });
1495
1693
  });