pdfjs-dist 2.0.943 → 2.1.266

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 (159) hide show
  1. package/bower.json +1 -1
  2. package/build/pdf.js +15329 -11095
  3. package/build/pdf.js.map +1 -1
  4. package/build/pdf.min.js +1 -1
  5. package/build/pdf.worker.js +12497 -4184
  6. package/build/pdf.worker.js.map +1 -1
  7. package/build/pdf.worker.min.js +1 -1
  8. package/image_decoders/pdf.image_decoders.js +3438 -1209
  9. package/image_decoders/pdf.image_decoders.js.map +1 -1
  10. package/image_decoders/pdf.image_decoders.min.js +1 -1
  11. package/lib/core/annotation.js +335 -109
  12. package/lib/core/arithmetic_decoder.js +274 -244
  13. package/lib/core/bidi.js +64 -5
  14. package/lib/core/ccitt.js +172 -17
  15. package/lib/core/ccitt_stream.js +14 -5
  16. package/lib/core/cff_parser.js +304 -28
  17. package/lib/core/charsets.js +4 -3
  18. package/lib/core/chunked_stream.js +379 -149
  19. package/lib/core/cmap.js +210 -40
  20. package/lib/core/colorspace.js +332 -187
  21. package/lib/core/crypto.js +289 -44
  22. package/lib/core/document.js +508 -249
  23. package/lib/core/encodings.js +18 -9
  24. package/lib/core/evaluator.js +657 -119
  25. package/lib/core/font_renderer.js +217 -34
  26. package/lib/core/fonts.js +632 -41
  27. package/lib/core/function.js +252 -26
  28. package/lib/core/glyphlist.js +2 -1
  29. package/lib/core/image.js +124 -27
  30. package/lib/core/jbig2.js +425 -65
  31. package/lib/core/jbig2_stream.js +18 -7
  32. package/lib/core/jpeg_stream.js +24 -8
  33. package/lib/core/jpg.js +208 -16
  34. package/lib/core/jpx.js +395 -5
  35. package/lib/core/jpx_stream.js +17 -5
  36. package/lib/core/metrics.js +3 -3
  37. package/lib/core/murmurhash3.js +23 -5
  38. package/lib/core/obj.js +625 -132
  39. package/lib/core/operator_list.js +104 -3
  40. package/lib/core/parser.js +262 -25
  41. package/lib/core/pattern.js +144 -12
  42. package/lib/core/pdf_manager.js +104 -70
  43. package/lib/core/primitives.js +74 -21
  44. package/lib/core/ps_parser.js +133 -44
  45. package/lib/core/standard_fonts.js +9 -9
  46. package/lib/core/stream.js +283 -31
  47. package/lib/core/type1_parser.js +138 -6
  48. package/lib/core/unicode.js +28 -1
  49. package/lib/core/worker.js +192 -57
  50. package/lib/display/annotation_layer.js +303 -123
  51. package/lib/display/api.js +1073 -574
  52. package/lib/display/api_compatibility.js +4 -1
  53. package/lib/display/canvas.js +314 -18
  54. package/lib/display/content_disposition.js +70 -23
  55. package/lib/display/dom_utils.js +112 -59
  56. package/lib/display/fetch_stream.js +95 -50
  57. package/lib/display/font_loader.js +250 -132
  58. package/lib/display/metadata.js +37 -15
  59. package/lib/display/network.js +123 -34
  60. package/lib/display/network_utils.js +23 -10
  61. package/lib/display/node_stream.js +162 -65
  62. package/lib/display/pattern_helper.js +57 -6
  63. package/lib/display/svg.js +194 -18
  64. package/lib/display/text_layer.js +128 -14
  65. package/lib/display/transport_stream.js +83 -27
  66. package/lib/display/webgl.js +63 -17
  67. package/lib/display/worker_options.js +4 -3
  68. package/lib/display/xml_parser.js +162 -52
  69. package/lib/examples/node/domstubs.js +56 -3
  70. package/lib/pdf.js +15 -2
  71. package/lib/pdf.worker.js +4 -2
  72. package/lib/shared/compatibility.js +129 -26
  73. package/lib/shared/global_scope.js +1 -1
  74. package/lib/shared/is_node.js +3 -3
  75. package/lib/shared/message_handler.js +103 -45
  76. package/lib/shared/streams_polyfill.js +20 -16
  77. package/lib/shared/url_polyfill.js +8 -2
  78. package/lib/shared/util.js +246 -84
  79. package/lib/test/unit/annotation_spec.js +99 -73
  80. package/lib/test/unit/api_spec.js +347 -113
  81. package/lib/test/unit/bidi_spec.js +6 -6
  82. package/lib/test/unit/cff_parser_spec.js +17 -5
  83. package/lib/test/unit/clitests_helper.js +7 -8
  84. package/lib/test/unit/cmap_spec.js +79 -25
  85. package/lib/test/unit/colorspace_spec.js +65 -18
  86. package/lib/test/unit/crypto_spec.js +16 -4
  87. package/lib/test/unit/custom_spec.js +40 -52
  88. package/lib/test/unit/display_svg_spec.js +32 -16
  89. package/lib/test/unit/document_spec.js +2 -2
  90. package/lib/test/unit/dom_utils_spec.js +8 -8
  91. package/lib/test/unit/encodings_spec.js +24 -44
  92. package/lib/test/unit/evaluator_spec.js +15 -8
  93. package/lib/test/unit/function_spec.js +16 -4
  94. package/lib/test/unit/jasmine-boot.js +29 -16
  95. package/lib/test/unit/message_handler_spec.js +19 -6
  96. package/lib/test/unit/metadata_spec.js +64 -11
  97. package/lib/test/unit/murmurhash3_spec.js +2 -2
  98. package/lib/test/unit/network_spec.js +19 -4
  99. package/lib/test/unit/network_utils_spec.js +6 -4
  100. package/lib/test/unit/node_stream_spec.js +50 -26
  101. package/lib/test/unit/parser_spec.js +13 -29
  102. package/lib/test/unit/pdf_find_controller_spec.js +144 -32
  103. package/lib/test/unit/pdf_find_utils_spec.js +10 -9
  104. package/lib/test/unit/pdf_history_spec.js +20 -8
  105. package/lib/test/unit/primitives_spec.js +23 -3
  106. package/lib/test/unit/stream_spec.js +8 -3
  107. package/lib/test/unit/test_utils.js +89 -26
  108. package/lib/test/unit/testreporter.js +19 -1
  109. package/lib/test/unit/type1_parser_spec.js +7 -5
  110. package/lib/test/unit/ui_utils_spec.js +162 -38
  111. package/lib/test/unit/unicode_spec.js +13 -10
  112. package/lib/test/unit/util_spec.js +89 -9
  113. package/lib/web/annotation_layer_builder.js +38 -21
  114. package/lib/web/app.js +610 -245
  115. package/lib/web/app_options.js +54 -34
  116. package/lib/web/base_viewer.js +359 -162
  117. package/lib/web/chromecom.js +159 -80
  118. package/lib/web/debugger.js +161 -17
  119. package/lib/web/download_manager.js +29 -11
  120. package/lib/web/firefox_print_service.js +16 -8
  121. package/lib/web/firefoxcom.js +127 -91
  122. package/lib/web/genericcom.js +50 -31
  123. package/lib/web/genericl10n.js +46 -34
  124. package/lib/web/grab_to_pan.js +25 -3
  125. package/lib/web/interfaces.js +108 -61
  126. package/lib/web/overlay_manager.js +67 -45
  127. package/lib/web/password_prompt.js +20 -12
  128. package/lib/web/pdf_attachment_viewer.js +37 -17
  129. package/lib/web/pdf_cursor_tools.js +38 -15
  130. package/lib/web/pdf_document_properties.js +65 -24
  131. package/lib/web/pdf_find_bar.js +48 -20
  132. package/lib/web/pdf_find_controller.js +290 -89
  133. package/lib/web/pdf_find_utils.js +19 -3
  134. package/lib/web/pdf_history.js +186 -49
  135. package/lib/web/pdf_link_service.js +127 -52
  136. package/lib/web/pdf_outline_viewer.js +71 -21
  137. package/lib/web/pdf_page_view.js +188 -63
  138. package/lib/web/pdf_presentation_mode.js +98 -33
  139. package/lib/web/pdf_print_service.js +54 -10
  140. package/lib/web/pdf_rendering_queue.js +26 -4
  141. package/lib/web/pdf_sidebar.js +116 -62
  142. package/lib/web/pdf_sidebar_resizer.js +41 -15
  143. package/lib/web/pdf_single_page_viewer.js +65 -68
  144. package/lib/web/pdf_thumbnail_view.js +102 -31
  145. package/lib/web/pdf_thumbnail_viewer.js +62 -22
  146. package/lib/web/pdf_viewer.component.js +111 -31
  147. package/lib/web/pdf_viewer.js +80 -60
  148. package/lib/web/preferences.js +61 -39
  149. package/lib/web/secondary_toolbar.js +101 -82
  150. package/lib/web/text_layer_builder.js +124 -69
  151. package/lib/web/toolbar.js +67 -27
  152. package/lib/web/ui_utils.js +284 -128
  153. package/lib/web/view_history.js +75 -51
  154. package/lib/web/viewer_compatibility.js +2 -1
  155. package/package.json +1 -1
  156. package/web/pdf_viewer.css +1 -1
  157. package/web/pdf_viewer.js +2200 -973
  158. package/web/pdf_viewer.js.map +1 -1
  159. package/lib/web/dom_events.js +0 -140
@@ -19,62 +19,77 @@
19
19
  * @licend The above is the entire license notice for the
20
20
  * Javascript code in this page
21
21
  */
22
- 'use strict';
22
+ "use strict";
23
23
 
24
- var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
24
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
25
25
 
26
- var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
26
+ var _test_utils = require("./test_utils");
27
27
 
28
- var _test_utils = require('./test_utils');
28
+ var _util = require("../../shared/util");
29
29
 
30
- var _util = require('../../shared/util');
30
+ var _dom_utils = require("../../display/dom_utils");
31
31
 
32
- var _dom_utils = require('../../display/dom_utils');
32
+ var _api = require("../../display/api");
33
33
 
34
- var _api = require('../../display/api');
34
+ var _worker_options = require("../../display/worker_options");
35
35
 
36
- var _worker_options = require('../../display/worker_options');
36
+ var _is_node = _interopRequireDefault(require("../../shared/is_node"));
37
37
 
38
- var _is_node = require('../../shared/is_node');
38
+ var _metadata = require("../../display/metadata");
39
39
 
40
- var _is_node2 = _interopRequireDefault(_is_node);
40
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
41
41
 
42
- var _metadata = require('../../display/metadata');
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
43
 
44
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
44
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
45
+
46
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
47
+
48
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
49
+
50
+ function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
51
+
52
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
53
+
54
+ function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
45
55
 
46
56
  describe('api', function () {
47
57
  var basicApiFileName = 'basicapi.pdf';
48
58
  var basicApiFileLength = 105779;
49
59
  var basicApiGetDocumentParams = (0, _test_utils.buildGetDocumentParams)(basicApiFileName);
50
- var CanvasFactory = void 0;
60
+ var CanvasFactory;
51
61
  beforeAll(function (done) {
52
- if ((0, _is_node2.default)()) {} else {
62
+ if ((0, _is_node.default)()) {
63
+ CanvasFactory = new _test_utils.NodeCanvasFactory();
64
+ } else {
53
65
  CanvasFactory = new _dom_utils.DOMCanvasFactory();
54
66
  }
67
+
55
68
  done();
56
69
  });
57
70
  afterAll(function (done) {
58
71
  CanvasFactory = null;
59
72
  done();
60
73
  });
74
+
61
75
  function waitSome(callback) {
62
76
  var WAIT_TIMEOUT = 10;
63
77
  setTimeout(function () {
64
78
  callback();
65
79
  }, WAIT_TIMEOUT);
66
80
  }
81
+
67
82
  describe('getDocument', function () {
68
83
  it('creates pdf doc from URL', function (done) {
69
84
  var loadingTask = (0, _api.getDocument)(basicApiGetDocumentParams);
70
- var isProgressReportedResolved = false;
71
85
  var progressReportedCapability = (0, _util.createPromiseCapability)();
86
+
72
87
  loadingTask.onProgress = function (progressData) {
73
- if (!isProgressReportedResolved) {
74
- isProgressReportedResolved = true;
88
+ if (!progressReportedCapability.settled) {
75
89
  progressReportedCapability.resolve(progressData);
76
90
  }
77
91
  };
92
+
78
93
  var promises = [progressReportedCapability.promise, loadingTask.promise];
79
94
  Promise.all(promises).then(function (data) {
80
95
  expect(data[0].loaded / data[0].total >= 0).toEqual(true);
@@ -95,9 +110,11 @@ describe('api', function () {
95
110
  });
96
111
  it('creates pdf doc from URL and aborts loading after worker initialized', function (done) {
97
112
  var loadingTask = (0, _api.getDocument)(basicApiGetDocumentParams);
113
+
98
114
  var destroyed = loadingTask._worker.promise.then(function () {
99
115
  return loadingTask.destroy();
100
116
  });
117
+
101
118
  destroyed.then(function (data) {
102
119
  expect(true).toEqual(true);
103
120
  done();
@@ -105,34 +122,44 @@ describe('api', function () {
105
122
  });
106
123
  it('creates pdf doc from typed array', function (done) {
107
124
  var typedArrayPdf;
108
- if ((0, _is_node2.default)()) {
109
- typedArrayPdf = _test_utils.NodeFileReaderFactory.fetch({ path: _test_utils.TEST_PDFS_PATH.node + basicApiFileName });
125
+
126
+ if ((0, _is_node.default)()) {
127
+ typedArrayPdf = _test_utils.NodeFileReaderFactory.fetch({
128
+ path: _test_utils.TEST_PDFS_PATH.node + basicApiFileName
129
+ });
110
130
  } else {
111
131
  var nonBinaryRequest = false;
112
132
  var request = new XMLHttpRequest();
113
133
  request.open('GET', _test_utils.TEST_PDFS_PATH.dom + basicApiFileName, false);
134
+
114
135
  try {
115
136
  request.responseType = 'arraybuffer';
116
137
  nonBinaryRequest = request.responseType !== 'arraybuffer';
117
138
  } catch (e) {
118
139
  nonBinaryRequest = true;
119
140
  }
141
+
120
142
  if (nonBinaryRequest && request.overrideMimeType) {
121
143
  request.overrideMimeType('text/plain; charset=x-user-defined');
122
144
  }
145
+
123
146
  request.send(null);
147
+
124
148
  if (nonBinaryRequest) {
125
149
  typedArrayPdf = (0, _util.stringToBytes)(request.responseText);
126
150
  } else {
127
151
  typedArrayPdf = new Uint8Array(request.response);
128
152
  }
129
153
  }
154
+
130
155
  expect(typedArrayPdf.length).toEqual(basicApiFileLength);
131
156
  var loadingTask = (0, _api.getDocument)(typedArrayPdf);
132
157
  var progressReportedCapability = (0, _util.createPromiseCapability)();
158
+
133
159
  loadingTask.onProgress = function (data) {
134
160
  progressReportedCapability.resolve(data);
135
161
  };
162
+
136
163
  Promise.all([loadingTask.promise, progressReportedCapability.promise]).then(function (data) {
137
164
  expect(data[0] instanceof _api.PDFDocumentProxy).toEqual(true);
138
165
  expect(data[1].loaded / data[1].total).toEqual(1);
@@ -159,25 +186,25 @@ describe('api', function () {
159
186
  });
160
187
  it('creates pdf doc from PDF file protected with user and owner password', function (done) {
161
188
  var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('pr6531_1.pdf'));
162
- var isPasswordNeededResolved = false;
163
189
  var passwordNeededCapability = (0, _util.createPromiseCapability)();
164
- var isPasswordIncorrectResolved = false;
165
190
  var passwordIncorrectCapability = (0, _util.createPromiseCapability)();
191
+
166
192
  loadingTask.onPassword = function (updatePassword, reason) {
167
- if (reason === _util.PasswordResponses.NEED_PASSWORD && !isPasswordNeededResolved) {
168
- isPasswordNeededResolved = true;
193
+ if (reason === _util.PasswordResponses.NEED_PASSWORD && !passwordNeededCapability.settled) {
169
194
  passwordNeededCapability.resolve();
170
195
  updatePassword('qwerty');
171
196
  return;
172
197
  }
173
- if (reason === _util.PasswordResponses.INCORRECT_PASSWORD && !isPasswordIncorrectResolved) {
174
- isPasswordIncorrectResolved = true;
198
+
199
+ if (reason === _util.PasswordResponses.INCORRECT_PASSWORD && !passwordIncorrectCapability.settled) {
175
200
  passwordIncorrectCapability.resolve();
176
201
  updatePassword('asdfasdf');
177
202
  return;
178
203
  }
204
+
179
205
  expect(false).toEqual(true);
180
206
  };
207
+
181
208
  var promises = [passwordNeededCapability.promise, passwordIncorrectCapability.promise, loadingTask.promise];
182
209
  Promise.all(promises).then(function (data) {
183
210
  expect(data[2] instanceof _api.PDFDocumentProxy).toEqual(true);
@@ -186,7 +213,9 @@ describe('api', function () {
186
213
  });
187
214
  it('creates pdf doc from PDF file protected with only a user password', function (done) {
188
215
  var filename = 'pr6531_2.pdf';
189
- var passwordNeededLoadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(filename, { password: '' }));
216
+ var passwordNeededLoadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(filename, {
217
+ password: ''
218
+ }));
190
219
  var result1 = passwordNeededLoadingTask.promise.then(function () {
191
220
  done.fail('shall fail with no password');
192
221
  return Promise.reject(new Error('loadingTask should be rejected'));
@@ -195,7 +224,9 @@ describe('api', function () {
195
224
  expect(data.code).toEqual(_util.PasswordResponses.NEED_PASSWORD);
196
225
  return passwordNeededLoadingTask.destroy();
197
226
  });
198
- var passwordIncorrectLoadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(filename, { password: 'qwerty' }));
227
+ var passwordIncorrectLoadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(filename, {
228
+ password: 'qwerty'
229
+ }));
199
230
  var result2 = passwordIncorrectLoadingTask.promise.then(function () {
200
231
  done.fail('shall fail with wrong password');
201
232
  return Promise.reject(new Error('loadingTask should be rejected'));
@@ -204,7 +235,9 @@ describe('api', function () {
204
235
  expect(data.code).toEqual(_util.PasswordResponses.INCORRECT_PASSWORD);
205
236
  return passwordIncorrectLoadingTask.destroy();
206
237
  });
207
- var passwordAcceptedLoadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(filename, { password: 'asdfasdf' }));
238
+ var passwordAcceptedLoadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(filename, {
239
+ password: 'asdfasdf'
240
+ }));
208
241
  var result3 = passwordAcceptedLoadingTask.promise.then(function (data) {
209
242
  expect(data instanceof _api.PDFDocumentProxy).toEqual(true);
210
243
  return passwordAcceptedLoadingTask.destroy();
@@ -216,15 +249,20 @@ describe('api', function () {
216
249
  it('creates pdf doc from password protected PDF file and aborts/throws ' + 'in the onPassword callback (issue 7806)', function (done) {
217
250
  var filename = 'issue3371.pdf';
218
251
  var passwordNeededLoadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(filename));
219
- var passwordIncorrectLoadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(filename, { password: 'qwerty' }));
220
- var passwordNeededDestroyed = void 0;
252
+ var passwordIncorrectLoadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(filename, {
253
+ password: 'qwerty'
254
+ }));
255
+ var passwordNeededDestroyed;
256
+
221
257
  passwordNeededLoadingTask.onPassword = function (callback, reason) {
222
258
  if (reason === _util.PasswordResponses.NEED_PASSWORD) {
223
259
  passwordNeededDestroyed = passwordNeededLoadingTask.destroy();
224
260
  return;
225
261
  }
262
+
226
263
  expect(false).toEqual(true);
227
264
  };
265
+
228
266
  var result1 = passwordNeededLoadingTask.promise.then(function () {
229
267
  done.fail('shall fail since the loadingTask should be destroyed');
230
268
  return Promise.reject(new Error('loadingTask should be rejected'));
@@ -233,12 +271,15 @@ describe('api', function () {
233
271
  expect(reason.code).toEqual(_util.PasswordResponses.NEED_PASSWORD);
234
272
  return passwordNeededDestroyed;
235
273
  });
274
+
236
275
  passwordIncorrectLoadingTask.onPassword = function (callback, reason) {
237
276
  if (reason === _util.PasswordResponses.INCORRECT_PASSWORD) {
238
277
  throw new Error('Incorrect password');
239
278
  }
279
+
240
280
  expect(false).toEqual(true);
241
281
  };
282
+
242
283
  var result2 = passwordIncorrectLoadingTask.promise.then(function () {
243
284
  done.fail('shall fail since the onPassword callback should throw');
244
285
  return Promise.reject(new Error('loadingTask should be rejected'));
@@ -254,10 +295,13 @@ describe('api', function () {
254
295
  });
255
296
  describe('PDFWorker', function () {
256
297
  it('worker created or destroyed', function (done) {
257
- if ((0, _is_node2.default)()) {
298
+ if ((0, _is_node.default)()) {
258
299
  pending('Worker is not supported in Node.js.');
259
300
  }
260
- var worker = new _api.PDFWorker({ name: 'test1' });
301
+
302
+ var worker = new _api.PDFWorker({
303
+ name: 'test1'
304
+ });
261
305
  worker.promise.then(function () {
262
306
  expect(worker.name).toEqual('test1');
263
307
  expect(!!worker.port).toEqual(true);
@@ -271,9 +315,10 @@ describe('api', function () {
271
315
  }).catch(done.fail);
272
316
  });
273
317
  it('worker created or destroyed by getDocument', function (done) {
274
- if ((0, _is_node2.default)()) {
318
+ if ((0, _is_node.default)()) {
275
319
  pending('Worker is not supported in Node.js.');
276
320
  }
321
+
277
322
  var loadingTask = (0, _api.getDocument)(basicApiGetDocumentParams);
278
323
  var worker;
279
324
  loadingTask.promise.then(function () {
@@ -291,11 +336,16 @@ describe('api', function () {
291
336
  }).catch(done.fail);
292
337
  });
293
338
  it('worker created and can be used in getDocument', function (done) {
294
- if ((0, _is_node2.default)()) {
339
+ if ((0, _is_node.default)()) {
295
340
  pending('Worker is not supported in Node.js.');
296
341
  }
297
- var worker = new _api.PDFWorker({ name: 'test1' });
298
- var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(basicApiFileName, { worker: worker }));
342
+
343
+ var worker = new _api.PDFWorker({
344
+ name: 'test1'
345
+ });
346
+ var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(basicApiFileName, {
347
+ worker: worker
348
+ }));
299
349
  loadingTask.promise.then(function () {
300
350
  var docWorker = loadingTask._worker;
301
351
  expect(!!docWorker).toEqual(false);
@@ -312,12 +362,19 @@ describe('api', function () {
312
362
  }).catch(done.fail);
313
363
  });
314
364
  it('creates more than one worker', function (done) {
315
- if ((0, _is_node2.default)()) {
365
+ if ((0, _is_node.default)()) {
316
366
  pending('Worker is not supported in Node.js.');
317
367
  }
318
- var worker1 = new _api.PDFWorker({ name: 'test1' });
319
- var worker2 = new _api.PDFWorker({ name: 'test2' });
320
- var worker3 = new _api.PDFWorker({ name: 'test3' });
368
+
369
+ var worker1 = new _api.PDFWorker({
370
+ name: 'test1'
371
+ });
372
+ var worker2 = new _api.PDFWorker({
373
+ name: 'test2'
374
+ });
375
+ var worker3 = new _api.PDFWorker({
376
+ name: 'test3'
377
+ });
321
378
  var ready = Promise.all([worker1.promise, worker2.promise, worker3.promise]);
322
379
  ready.then(function () {
323
380
  expect(worker1.port !== worker2.port && worker1.port !== worker3.port && worker2.port !== worker3.port).toEqual(true);
@@ -328,11 +385,13 @@ describe('api', function () {
328
385
  }).catch(done.fail);
329
386
  });
330
387
  it('gets current workerSrc', function () {
331
- if ((0, _is_node2.default)()) {
388
+ if ((0, _is_node.default)()) {
332
389
  pending('Worker is not supported in Node.js.');
333
390
  }
391
+
334
392
  var workerSrc = _api.PDFWorker.getWorkerSrc();
335
- expect(typeof workerSrc === 'undefined' ? 'undefined' : _typeof(workerSrc)).toEqual('string');
393
+
394
+ expect(_typeof(workerSrc)).toEqual('string');
336
395
  expect(workerSrc).toEqual(_worker_options.GlobalWorkerOptions.workerSrc);
337
396
  });
338
397
  });
@@ -354,7 +413,7 @@ describe('api', function () {
354
413
  });
355
414
  it('gets fingerprint', function () {
356
415
  var fingerprint = doc.fingerprint;
357
- expect(typeof fingerprint === 'undefined' ? 'undefined' : _typeof(fingerprint)).toEqual('string');
416
+ expect(_typeof(fingerprint)).toEqual('string');
358
417
  expect(fingerprint.length > 0).toEqual(true);
359
418
  });
360
419
  it('gets page', function (done) {
@@ -419,7 +478,9 @@ describe('api', function () {
419
478
  chapter1: [{
420
479
  gen: 0,
421
480
  num: 17
422
- }, { name: 'XYZ' }, 0, 841.89, null]
481
+ }, {
482
+ name: 'XYZ'
483
+ }, 0, 841.89, null]
423
484
  });
424
485
  done();
425
486
  }).catch(done.fail);
@@ -430,7 +491,9 @@ describe('api', function () {
430
491
  expect(data).toEqual([{
431
492
  gen: 0,
432
493
  num: 17
433
- }, { name: 'XYZ' }, 0, 841.89, null]);
494
+ }, {
495
+ name: 'XYZ'
496
+ }, 0, 841.89, null]);
434
497
  done();
435
498
  }).catch(done.fail);
436
499
  });
@@ -451,11 +514,15 @@ describe('api', function () {
451
514
  'Page.1': [{
452
515
  num: 1,
453
516
  gen: 0
454
- }, { name: 'XYZ' }, 0, 375, null],
517
+ }, {
518
+ name: 'XYZ'
519
+ }, 0, 375, null],
455
520
  'Page.2': [{
456
521
  num: 6,
457
522
  gen: 0
458
- }, { name: 'XYZ' }, 0, 375, null]
523
+ }, {
524
+ name: 'XYZ'
525
+ }, 0, 375, null]
459
526
  });
460
527
  loadingTask.destroy().then(done);
461
528
  }).catch(done.fail);
@@ -469,7 +536,9 @@ describe('api', function () {
469
536
  expect(destination).toEqual([{
470
537
  num: 1,
471
538
  gen: 0
472
- }, { name: 'XYZ' }, 0, 375, null]);
539
+ }, {
540
+ name: 'XYZ'
541
+ }, 0, 375, null]);
473
542
  loadingTask.destroy().then(done);
474
543
  }).catch(done.fail);
475
544
  });
@@ -489,7 +558,9 @@ describe('api', function () {
489
558
  var arrayPromise = doc.getDestination([{
490
559
  num: 17,
491
560
  gen: 0
492
- }, { name: 'XYZ' }, 0, 841.89, null]);
561
+ }, {
562
+ name: 'XYZ'
563
+ }, 0, 841.89, null]);
493
564
  numberPromise = numberPromise.then(function () {
494
565
  throw new Error('shall fail for non-string destination.');
495
566
  }, function (reason) {
@@ -554,6 +625,26 @@ describe('api', function () {
554
625
  done();
555
626
  }).catch(done.fail);
556
627
  });
628
+ it('gets default open action destination', function (done) {
629
+ var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('tracemonkey.pdf'));
630
+ loadingTask.promise.then(function (pdfDocument) {
631
+ return pdfDocument.getOpenActionDestination();
632
+ }).then(function (dest) {
633
+ expect(dest).toEqual(null);
634
+ loadingTask.destroy().then(done);
635
+ }).catch(done.fail);
636
+ });
637
+ it('gets non-default open action destination', function (done) {
638
+ doc.getOpenActionDestination().then(function (dest) {
639
+ expect(dest).toEqual([{
640
+ num: 15,
641
+ gen: 0
642
+ }, {
643
+ name: 'FitH'
644
+ }, null]);
645
+ done();
646
+ }).catch(done.fail);
647
+ });
557
648
  it('gets non-existent attachments', function (done) {
558
649
  var promise = doc.getAttachments();
559
650
  promise.then(function (data) {
@@ -562,9 +653,10 @@ describe('api', function () {
562
653
  }).catch(done.fail);
563
654
  });
564
655
  it('gets attachments', function (done) {
565
- if ((0, _is_node2.default)()) {
656
+ if ((0, _is_node.default)()) {
566
657
  pending('TODO: Use a non-linked test-case.');
567
658
  }
659
+
568
660
  var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('bug766138.pdf'));
569
661
  var promise = loadingTask.promise.then(function (pdfDoc) {
570
662
  return pdfDoc.getAttachments();
@@ -693,8 +785,8 @@ describe('api', function () {
693
785
  var info = _ref.info,
694
786
  metadata = _ref.metadata,
695
787
  contentDispositionFilename = _ref.contentDispositionFilename;
696
-
697
788
  expect(info['Title']).toEqual('Basic API Test');
789
+ expect(info['Custom']).toEqual(undefined);
698
790
  expect(info['PDFFormatVersion']).toEqual('1.7');
699
791
  expect(info['IsLinearized']).toEqual(false);
700
792
  expect(info['IsAcroFormPresent']).toEqual(false);
@@ -705,6 +797,29 @@ describe('api', function () {
705
797
  done();
706
798
  }).catch(done.fail);
707
799
  });
800
+ it('gets metadata, with custom info dict entries', function (done) {
801
+ var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('tracemonkey.pdf'));
802
+ loadingTask.promise.then(function (pdfDocument) {
803
+ return pdfDocument.getMetadata();
804
+ }).then(function (_ref2) {
805
+ var info = _ref2.info,
806
+ metadata = _ref2.metadata,
807
+ contentDispositionFilename = _ref2.contentDispositionFilename;
808
+ expect(info['Creator']).toEqual('TeX');
809
+ expect(info['Producer']).toEqual('pdfeTeX-1.21a');
810
+ expect(info['CreationDate']).toEqual('D:20090401163925-07\'00\'');
811
+ var custom = info['Custom'];
812
+ expect(_typeof(custom) === 'object' && custom !== null).toEqual(true);
813
+ expect(custom['PTEX.Fullbanner']).toEqual('This is pdfeTeX, ' + 'Version 3.141592-1.21a-2.2 (Web2C 7.5.4) kpathsea version 3.5.6');
814
+ expect(info['PDFFormatVersion']).toEqual('1.4');
815
+ expect(info['IsLinearized']).toEqual(false);
816
+ expect(info['IsAcroFormPresent']).toEqual(false);
817
+ expect(info['IsXFAPresent']).toEqual(false);
818
+ expect(metadata).toEqual(null);
819
+ expect(contentDispositionFilename).toEqual(null);
820
+ loadingTask.destroy().then(done);
821
+ }).catch(done.fail);
822
+ });
708
823
  it('gets data', function (done) {
709
824
  var promise = doc.getData();
710
825
  promise.then(function (data) {
@@ -716,7 +831,9 @@ describe('api', function () {
716
831
  it('gets download info', function (done) {
717
832
  var promise = doc.getDownloadInfo();
718
833
  promise.then(function (data) {
719
- expect(data).toEqual({ length: basicApiFileLength });
834
+ expect(data).toEqual({
835
+ length: basicApiFileLength
836
+ });
720
837
  done();
721
838
  }).catch(done.fail);
722
839
  });
@@ -736,10 +853,10 @@ describe('api', function () {
736
853
  var promises = [loadingTask1.promise, loadingTask2.promise];
737
854
  Promise.all(promises).then(function (data) {
738
855
  var fingerprint1 = data[0].fingerprint;
739
- expect(typeof fingerprint1 === 'undefined' ? 'undefined' : _typeof(fingerprint1)).toEqual('string');
856
+ expect(_typeof(fingerprint1)).toEqual('string');
740
857
  expect(fingerprint1.length > 0).toEqual(true);
741
858
  var fingerprint2 = data[1].fingerprint;
742
- expect(typeof fingerprint2 === 'undefined' ? 'undefined' : _typeof(fingerprint2)).toEqual('string');
859
+ expect(_typeof(fingerprint2)).toEqual('string');
743
860
  expect(fingerprint2.length > 0).toEqual(true);
744
861
  expect(fingerprint1).not.toEqual(fingerprint2);
745
862
  Promise.all([loadingTask1.destroy(), loadingTask2.destroy()]).then(done);
@@ -747,12 +864,15 @@ describe('api', function () {
747
864
  });
748
865
  describe('Cross-origin', function () {
749
866
  var loadingTask;
867
+
750
868
  function _checkCanLoad(expectSuccess, filename, options) {
751
- if ((0, _is_node2.default)()) {
869
+ if ((0, _is_node.default)()) {
752
870
  pending('Cannot simulate cross-origin requests in Node.js');
753
871
  }
872
+
754
873
  var params = (0, _test_utils.buildGetDocumentParams)(filename, options);
755
874
  var url = new URL(params.url);
875
+
756
876
  if (url.hostname === 'localhost') {
757
877
  url.hostname = '127.0.0.1';
758
878
  } else if (params.url.hostname === '127.0.0.1') {
@@ -760,6 +880,7 @@ describe('api', function () {
760
880
  } else {
761
881
  pending('Can only run cross-origin test on localhost!');
762
882
  }
883
+
763
884
  params.url = url.href;
764
885
  loadingTask = (0, _api.getDocument)(params);
765
886
  return loadingTask.promise.then(function (pdf) {
@@ -770,15 +891,19 @@ describe('api', function () {
770
891
  if (expectSuccess) {
771
892
  expect(error).toEqual('There should not be any error');
772
893
  }
894
+
773
895
  expect(expectSuccess).toEqual(false);
774
896
  });
775
897
  }
898
+
776
899
  function testCanLoad(filename, options) {
777
900
  return _checkCanLoad(true, filename, options);
778
901
  }
902
+
779
903
  function testCannotLoad(filename, options) {
780
904
  return _checkCanLoad(false, filename, options);
781
905
  }
906
+
782
907
  afterEach(function (done) {
783
908
  if (loadingTask) {
784
909
  loadingTask.destroy().then(done);
@@ -793,16 +918,24 @@ describe('api', function () {
793
918
  testCanLoad('basicapi.pdf?cors=withoutCredentials').then(done);
794
919
  });
795
920
  it('server allows cors without credentials, and withCredentials=false', function (done) {
796
- testCanLoad('basicapi.pdf?cors=withoutCredentials', { withCredentials: false }).then(done);
921
+ testCanLoad('basicapi.pdf?cors=withoutCredentials', {
922
+ withCredentials: false
923
+ }).then(done);
797
924
  });
798
925
  it('server allows cors without credentials, but withCredentials=true', function (done) {
799
- testCannotLoad('basicapi.pdf?cors=withoutCredentials', { withCredentials: true }).then(done);
926
+ testCannotLoad('basicapi.pdf?cors=withoutCredentials', {
927
+ withCredentials: true
928
+ }).then(done);
800
929
  });
801
930
  it('server allows cors with credentials, and withCredentials=true', function (done) {
802
- testCanLoad('basicapi.pdf?cors=withCredentials', { withCredentials: true }).then(done);
931
+ testCanLoad('basicapi.pdf?cors=withCredentials', {
932
+ withCredentials: true
933
+ }).then(done);
803
934
  });
804
935
  it('server allows cors with credentials, and withCredentials=false', function (done) {
805
- testCanLoad('basicapi.pdf?cors=withCredentials', { withCredentials: false }).then(done);
936
+ testCanLoad('basicapi.pdf?cors=withCredentials', {
937
+ withCredentials: false
938
+ }).then(done);
806
939
  });
807
940
  });
808
941
  });
@@ -841,7 +974,10 @@ describe('api', function () {
841
974
  expect(page.view).toEqual([0, 0, 595.28, 841.89]);
842
975
  });
843
976
  it('gets viewport', function () {
844
- var viewport = page.getViewport(1.5, 90);
977
+ var viewport = page.getViewport({
978
+ scale: 1.5,
979
+ rotation: 90
980
+ });
845
981
  expect(viewport.viewBox).toEqual(page.view);
846
982
  expect(viewport.scale).toEqual(1.5);
847
983
  expect(viewport.rotation).toEqual(90);
@@ -852,10 +988,19 @@ describe('api', function () {
852
988
  it('gets viewport respecting "dontFlip" argument', function () {
853
989
  var scale = 1;
854
990
  var rotation = 135;
855
- var viewport = page.getViewport(scale, rotation);
856
- var dontFlipViewport = page.getViewport(scale, rotation, true);
991
+ var viewport = page.getViewport({
992
+ scale: scale,
993
+ rotation: rotation
994
+ });
995
+ var dontFlipViewport = page.getViewport({
996
+ scale: scale,
997
+ rotation: rotation,
998
+ dontFlip: true
999
+ });
857
1000
  expect(dontFlipViewport).not.toEqual(viewport);
858
- expect(dontFlipViewport).toEqual(viewport.clone({ dontFlip: true }));
1001
+ expect(dontFlipViewport).toEqual(viewport.clone({
1002
+ dontFlip: true
1003
+ }));
859
1004
  expect(viewport.transform).toEqual([1, 0, 0, -1, 0, 841.89]);
860
1005
  expect(dontFlipViewport.transform).toEqual([1, 0, -0, 1, 0, 0]);
861
1006
  });
@@ -863,10 +1008,14 @@ describe('api', function () {
863
1008
  var defaultPromise = page.getAnnotations().then(function (data) {
864
1009
  expect(data.length).toEqual(4);
865
1010
  });
866
- var displayPromise = page.getAnnotations({ intent: 'display' }).then(function (data) {
1011
+ var displayPromise = page.getAnnotations({
1012
+ intent: 'display'
1013
+ }).then(function (data) {
867
1014
  expect(data.length).toEqual(4);
868
1015
  });
869
- var printPromise = page.getAnnotations({ intent: 'print' }).then(function (data) {
1016
+ var printPromise = page.getAnnotations({
1017
+ intent: 'print'
1018
+ }).then(function (data) {
870
1019
  expect(data.length).toEqual(4);
871
1020
  });
872
1021
  Promise.all([defaultPromise, displayPromise, printPromise]).then(function () {
@@ -881,13 +1030,17 @@ describe('api', function () {
881
1030
  return pdfPage.getAnnotations();
882
1031
  });
883
1032
  });
884
- var docBaseUrlLoadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(filename, { docBaseUrl: 'http://www.example.com/test/pdfs/qwerty.pdf' }));
1033
+ var docBaseUrlLoadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(filename, {
1034
+ docBaseUrl: 'http://www.example.com/test/pdfs/qwerty.pdf'
1035
+ }));
885
1036
  var docBaseUrlPromise = docBaseUrlLoadingTask.promise.then(function (pdfDoc) {
886
1037
  return pdfDoc.getPage(1).then(function (pdfPage) {
887
1038
  return pdfPage.getAnnotations();
888
1039
  });
889
1040
  });
890
- var invalidDocBaseUrlLoadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(filename, { docBaseUrl: 'qwerty.pdf' }));
1041
+ var invalidDocBaseUrlLoadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(filename, {
1042
+ docBaseUrl: 'qwerty.pdf'
1043
+ }));
891
1044
  var invalidDocBaseUrlPromise = invalidDocBaseUrlLoadingTask.promise.then(function (pdfDoc) {
892
1045
  return pdfDoc.getPage(1).then(function (pdfPage) {
893
1046
  return pdfPage.getAnnotations();
@@ -921,6 +1074,34 @@ describe('api', function () {
921
1074
  done();
922
1075
  }).catch(done.fail);
923
1076
  });
1077
+ it('gets text content, with correct properties (issue 8276)', function (done) {
1078
+ var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)('issue8276_reduced.pdf'));
1079
+ loadingTask.promise.then(function (pdfDoc) {
1080
+ pdfDoc.getPage(1).then(function (pdfPage) {
1081
+ pdfPage.getTextContent().then(function (_ref3) {
1082
+ var items = _ref3.items,
1083
+ styles = _ref3.styles;
1084
+ expect(items.length).toEqual(1);
1085
+ expect(Object.keys(styles)).toEqual(['Times']);
1086
+ expect(items[0]).toEqual({
1087
+ dir: 'ltr',
1088
+ fontName: 'Times',
1089
+ height: 18,
1090
+ str: 'Issue 8276',
1091
+ transform: [18, 0, 0, 18, 441.81, 708.4499999999999],
1092
+ width: 77.49
1093
+ });
1094
+ expect(styles.Times).toEqual({
1095
+ fontFamily: 'serif',
1096
+ ascent: NaN,
1097
+ descent: NaN,
1098
+ vertical: false
1099
+ });
1100
+ loadingTask.destroy().then(done);
1101
+ });
1102
+ });
1103
+ }).catch(done.fail);
1104
+ });
924
1105
  it('gets operator list', function (done) {
925
1106
  var promise = page.getOperatorList();
926
1107
  promise.then(function (oplist) {
@@ -939,11 +1120,11 @@ describe('api', function () {
939
1120
  var imgArgs = opList.argsArray[imgIndex];
940
1121
 
941
1122
  var _pdfPage$objs$get = pdfPage.objs.get(imgArgs[0]),
942
- imgData = _pdfPage$objs$get.data;
1123
+ data = _pdfPage$objs$get.data;
943
1124
 
944
- expect(imgData instanceof Uint8ClampedArray).toEqual(true);
945
- expect(imgData.length).toEqual(90000);
946
- done();
1125
+ expect(data instanceof Uint8ClampedArray).toEqual(true);
1126
+ expect(data.length).toEqual(90000);
1127
+ loadingTask.destroy().then(done);
947
1128
  });
948
1129
  });
949
1130
  }).catch(done.fail);
@@ -974,7 +1155,9 @@ describe('api', function () {
974
1155
  }, done.fail);
975
1156
  });
976
1157
  it('gets page stats after parsing page, with `pdfBug` set', function (done) {
977
- var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(basicApiFileName, { pdfBug: true }));
1158
+ var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(basicApiFileName, {
1159
+ pdfBug: true
1160
+ }));
978
1161
  loadingTask.promise.then(function (pdfDoc) {
979
1162
  return pdfDoc.getPage(1).then(function (pdfPage) {
980
1163
  return pdfPage.getOperatorList().then(function (opList) {
@@ -994,17 +1177,19 @@ describe('api', function () {
994
1177
  }, done.fail);
995
1178
  });
996
1179
  it('gets page stats after rendering page, with `pdfBug` set', function (done) {
997
- if ((0, _is_node2.default)()) {
998
- pending('TODO: Support Canvas testing in Node.js.');
999
- }
1000
- var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(basicApiFileName, { pdfBug: true }));
1001
- var canvasAndCtx = void 0;
1180
+ var loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)(basicApiFileName, {
1181
+ pdfBug: true
1182
+ }));
1183
+ var canvasAndCtx;
1002
1184
  loadingTask.promise.then(function (pdfDoc) {
1003
1185
  return pdfDoc.getPage(1).then(function (pdfPage) {
1004
- var viewport = pdfPage.getViewport(1);
1186
+ var viewport = pdfPage.getViewport({
1187
+ scale: 1
1188
+ });
1005
1189
  canvasAndCtx = CanvasFactory.create(viewport.width, viewport.height);
1006
1190
  var renderTask = pdfPage.render({
1007
1191
  canvasContext: canvasAndCtx.context,
1192
+ canvasFactory: CanvasFactory,
1008
1193
  viewport: viewport
1009
1194
  });
1010
1195
  return renderTask.promise.then(function () {
@@ -1031,13 +1216,13 @@ describe('api', function () {
1031
1216
  }, done.fail);
1032
1217
  });
1033
1218
  it('cancels rendering of page', function (done) {
1034
- if ((0, _is_node2.default)()) {
1035
- pending('TODO: Support Canvas testing in Node.js.');
1036
- }
1037
- var viewport = page.getViewport(1);
1219
+ var viewport = page.getViewport({
1220
+ scale: 1
1221
+ });
1038
1222
  var canvasAndCtx = CanvasFactory.create(viewport.width, viewport.height);
1039
1223
  var renderTask = page.render({
1040
1224
  canvasContext: canvasAndCtx.context,
1225
+ canvasFactory: CanvasFactory,
1041
1226
  viewport: viewport
1042
1227
  });
1043
1228
  renderTask.cancel();
@@ -1051,13 +1236,13 @@ describe('api', function () {
1051
1236
  });
1052
1237
  });
1053
1238
  it('re-render page, using the same canvas, after cancelling rendering', function (done) {
1054
- if ((0, _is_node2.default)()) {
1055
- pending('TODO: Support Canvas testing in Node.js.');
1056
- }
1057
- var viewport = page.getViewport(1);
1239
+ var viewport = page.getViewport({
1240
+ scale: 1
1241
+ });
1058
1242
  var canvasAndCtx = CanvasFactory.create(viewport.width, viewport.height);
1059
1243
  var renderTask = page.render({
1060
1244
  canvasContext: canvasAndCtx.context,
1245
+ canvasFactory: CanvasFactory,
1061
1246
  viewport: viewport
1062
1247
  });
1063
1248
  renderTask.cancel();
@@ -1068,6 +1253,7 @@ describe('api', function () {
1068
1253
  }).then(function () {
1069
1254
  var reRenderTask = page.render({
1070
1255
  canvasContext: canvasAndCtx.context,
1256
+ canvasFactory: CanvasFactory,
1071
1257
  viewport: viewport
1072
1258
  });
1073
1259
  return reRenderTask.promise;
@@ -1077,17 +1263,18 @@ describe('api', function () {
1077
1263
  }, done.fail);
1078
1264
  });
1079
1265
  it('multiple render() on the same canvas', function (done) {
1080
- if ((0, _is_node2.default)()) {
1081
- pending('TODO: Support Canvas testing in Node.js.');
1082
- }
1083
- var viewport = page.getViewport(1);
1266
+ var viewport = page.getViewport({
1267
+ scale: 1
1268
+ });
1084
1269
  var canvasAndCtx = CanvasFactory.create(viewport.width, viewport.height);
1085
1270
  var renderTask1 = page.render({
1086
1271
  canvasContext: canvasAndCtx.context,
1272
+ canvasFactory: CanvasFactory,
1087
1273
  viewport: viewport
1088
1274
  });
1089
1275
  var renderTask2 = page.render({
1090
1276
  canvasContext: canvasAndCtx.context,
1277
+ canvasFactory: CanvasFactory,
1091
1278
  viewport: viewport
1092
1279
  });
1093
1280
  Promise.all([renderTask1.promise, renderTask2.promise.then(function () {
@@ -1103,25 +1290,60 @@ describe('api', function () {
1103
1290
  var pdf3 = (0, _test_utils.buildGetDocumentParams)('issue6068.pdf');
1104
1291
  var loadingTasks = [];
1105
1292
  var pdfDocuments = [];
1106
- function renderPDF(filename) {
1107
- var loadingTask = (0, _api.getDocument)(filename);
1108
- loadingTasks.push(loadingTask);
1109
- return loadingTask.promise.then(function (pdf) {
1110
- pdfDocuments.push(pdf);
1111
- return pdf.getPage(1);
1112
- }).then(function (page) {
1113
- var viewport = page.getViewport(1.2);
1114
- var canvasAndCtx = CanvasFactory.create(viewport.width, viewport.height);
1115
- return page.render({
1116
- canvasContext: canvasAndCtx.context,
1117
- viewport: viewport
1118
- }).then(function () {
1119
- var data = canvasAndCtx.canvas.toDataURL();
1120
- CanvasFactory.destroy(canvasAndCtx);
1121
- return data;
1122
- });
1123
- });
1293
+
1294
+ function renderPDF(_x) {
1295
+ return _renderPDF.apply(this, arguments);
1124
1296
  }
1297
+
1298
+ function _renderPDF() {
1299
+ _renderPDF = _asyncToGenerator(
1300
+ /*#__PURE__*/
1301
+ _regenerator.default.mark(function _callee(filename) {
1302
+ var loadingTask, pdf, page, viewport, canvasAndCtx, renderTask, data;
1303
+ return _regenerator.default.wrap(function _callee$(_context) {
1304
+ while (1) {
1305
+ switch (_context.prev = _context.next) {
1306
+ case 0:
1307
+ loadingTask = (0, _api.getDocument)(filename);
1308
+ loadingTasks.push(loadingTask);
1309
+ _context.next = 4;
1310
+ return loadingTask.promise;
1311
+
1312
+ case 4:
1313
+ pdf = _context.sent;
1314
+ pdfDocuments.push(pdf);
1315
+ _context.next = 8;
1316
+ return pdf.getPage(1);
1317
+
1318
+ case 8:
1319
+ page = _context.sent;
1320
+ viewport = page.getViewport({
1321
+ scale: 1.2
1322
+ });
1323
+ canvasAndCtx = CanvasFactory.create(viewport.width, viewport.height);
1324
+ renderTask = page.render({
1325
+ canvasContext: canvasAndCtx.context,
1326
+ canvasFactory: CanvasFactory,
1327
+ viewport: viewport
1328
+ });
1329
+ _context.next = 14;
1330
+ return renderTask.promise;
1331
+
1332
+ case 14:
1333
+ data = canvasAndCtx.canvas.toDataURL();
1334
+ CanvasFactory.destroy(canvasAndCtx);
1335
+ return _context.abrupt("return", data);
1336
+
1337
+ case 17:
1338
+ case "end":
1339
+ return _context.stop();
1340
+ }
1341
+ }
1342
+ }, _callee, this);
1343
+ }));
1344
+ return _renderPDF.apply(this, arguments);
1345
+ }
1346
+
1125
1347
  afterEach(function (done) {
1126
1348
  var destroyPromises = pdfDocuments.map(function (pdfDocument) {
1127
1349
  return pdfDocument.destroy();
@@ -1134,9 +1356,6 @@ describe('api', function () {
1134
1356
  });
1135
1357
  });
1136
1358
  it('should correctly render PDFs in parallel', function (done) {
1137
- if ((0, _is_node2.default)()) {
1138
- pending('TODO: Support Canvas testing in Node.js.');
1139
- }
1140
1359
  var baseline1, baseline2, baseline3;
1141
1360
  var promiseDone = renderPDF(pdf1).then(function (data1) {
1142
1361
  baseline1 = data1;
@@ -1160,35 +1379,44 @@ describe('api', function () {
1160
1379
  });
1161
1380
  describe('PDFDataRangeTransport', function () {
1162
1381
  var loadPromise;
1382
+
1163
1383
  function getDocumentData() {
1164
1384
  var pdfPath = new URL('../pdfs/tracemonkey.pdf', window.location).href;
1385
+
1165
1386
  if (loadPromise) {
1166
1387
  return loadPromise;
1167
1388
  }
1389
+
1168
1390
  loadPromise = new Promise(function (resolve, reject) {
1169
1391
  var xhr = new XMLHttpRequest(pdfPath);
1170
1392
  xhr.open('GET', pdfPath);
1171
1393
  xhr.responseType = 'arraybuffer';
1394
+
1172
1395
  xhr.onload = function () {
1173
1396
  resolve(new Uint8Array(xhr.response));
1174
1397
  };
1398
+
1175
1399
  xhr.onerror = function () {
1176
1400
  reject(new Error('PDF is not loaded'));
1177
1401
  };
1402
+
1178
1403
  xhr.send();
1179
1404
  });
1180
1405
  return loadPromise;
1181
1406
  }
1407
+
1182
1408
  it('should fetch document info and page using ranges', function (done) {
1183
- if ((0, _is_node2.default)()) {
1409
+ if ((0, _is_node.default)()) {
1184
1410
  pending('XMLHttpRequest is not supported in Node.js.');
1185
1411
  }
1412
+
1186
1413
  var transport;
1187
1414
  var initialDataLength = 4000;
1188
1415
  var fetches = 0;
1189
1416
  var getDocumentPromise = getDocumentData().then(function (data) {
1190
1417
  var initialData = data.subarray(0, initialDataLength);
1191
1418
  transport = new _api.PDFDataRangeTransport(data.length, initialData);
1419
+
1192
1420
  transport.requestDataRange = function (begin, end) {
1193
1421
  fetches++;
1194
1422
  waitSome(function () {
@@ -1196,6 +1424,7 @@ describe('api', function () {
1196
1424
  transport.onDataRange(begin, data.subarray(begin, end));
1197
1425
  });
1198
1426
  };
1427
+
1199
1428
  var loadingTask = (0, _api.getDocument)(transport);
1200
1429
  return loadingTask.promise;
1201
1430
  });
@@ -1213,24 +1442,29 @@ describe('api', function () {
1213
1442
  }).catch(done.fail);
1214
1443
  });
1215
1444
  it('should fetch document info and page using range and streaming', function (done) {
1216
- if ((0, _is_node2.default)()) {
1445
+ if ((0, _is_node.default)()) {
1217
1446
  pending('XMLHttpRequest is not supported in Node.js.');
1218
1447
  }
1448
+
1219
1449
  var transport;
1220
1450
  var initialDataLength = 4000;
1221
1451
  var fetches = 0;
1222
1452
  var getDocumentPromise = getDocumentData().then(function (data) {
1223
1453
  var initialData = data.subarray(0, initialDataLength);
1224
1454
  transport = new _api.PDFDataRangeTransport(data.length, initialData);
1455
+
1225
1456
  transport.requestDataRange = function (begin, end) {
1226
1457
  fetches++;
1458
+
1227
1459
  if (fetches === 1) {
1228
1460
  transport.onDataProgressiveRead(data.subarray(initialDataLength));
1229
1461
  }
1462
+
1230
1463
  waitSome(function () {
1231
1464
  transport.onDataRange(begin, data.subarray(begin, end));
1232
1465
  });
1233
1466
  };
1467
+
1234
1468
  var loadingTask = (0, _api.getDocument)(transport);
1235
1469
  return loadingTask.promise;
1236
1470
  });