pdfjs-dist 2.3.200 → 2.4.456

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of pdfjs-dist might be problematic. Click here for more details.

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