pdfjs-dist 2.0.550 → 2.3.200

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 (168) hide show
  1. package/CODE_OF_CONDUCT.md +15 -0
  2. package/bower.json +1 -1
  3. package/build/pdf.js +21618 -14369
  4. package/build/pdf.js.map +1 -1
  5. package/build/pdf.min.js +1 -1
  6. package/build/pdf.worker.js +22758 -11399
  7. package/build/pdf.worker.js.map +1 -1
  8. package/build/pdf.worker.min.js +1 -1
  9. package/image_decoders/pdf.image_decoders.js +11500 -0
  10. package/image_decoders/pdf.image_decoders.js.map +1 -0
  11. package/image_decoders/pdf.image_decoders.min.js +1 -0
  12. package/lib/core/annotation.js +767 -258
  13. package/lib/core/arithmetic_decoder.js +275 -245
  14. package/lib/core/bidi.js +65 -6
  15. package/lib/core/ccitt.js +173 -18
  16. package/lib/core/ccitt_stream.js +15 -6
  17. package/lib/core/cff_parser.js +433 -61
  18. package/lib/core/charsets.js +5 -4
  19. package/lib/core/chunked_stream.js +428 -157
  20. package/lib/core/cmap.js +326 -87
  21. package/lib/core/colorspace.js +874 -594
  22. package/lib/core/core_utils.js +173 -0
  23. package/lib/core/crypto.js +290 -45
  24. package/lib/core/document.js +575 -272
  25. package/lib/core/encodings.js +19 -10
  26. package/lib/core/evaluator.js +1032 -351
  27. package/lib/core/font_renderer.js +331 -97
  28. package/lib/core/fonts.js +813 -196
  29. package/lib/core/function.js +253 -27
  30. package/lib/core/glyphlist.js +5 -3
  31. package/lib/core/image.js +169 -62
  32. package/lib/core/image_utils.js +111 -0
  33. package/lib/core/jbig2.js +502 -72
  34. package/lib/core/jbig2_stream.js +19 -8
  35. package/lib/core/jpeg_stream.js +38 -13
  36. package/lib/core/jpg.js +293 -52
  37. package/lib/core/jpx.js +419 -12
  38. package/lib/core/jpx_stream.js +18 -6
  39. package/lib/core/metrics.js +15 -15
  40. package/lib/core/murmurhash3.js +56 -34
  41. package/lib/core/obj.js +1368 -500
  42. package/lib/core/operator_list.js +159 -43
  43. package/lib/core/parser.js +544 -199
  44. package/lib/core/pattern.js +170 -21
  45. package/lib/core/pdf_manager.js +324 -134
  46. package/lib/core/primitives.js +169 -61
  47. package/lib/core/ps_parser.js +134 -45
  48. package/lib/core/standard_fonts.js +17 -17
  49. package/lib/core/stream.js +327 -34
  50. package/lib/core/type1_parser.js +148 -8
  51. package/lib/core/unicode.js +32 -5
  52. package/lib/core/worker.js +215 -229
  53. package/lib/core/worker_stream.js +277 -0
  54. package/lib/display/annotation_layer.js +618 -192
  55. package/lib/display/api.js +1798 -882
  56. package/lib/display/api_compatibility.js +5 -10
  57. package/lib/display/canvas.js +366 -45
  58. package/lib/display/content_disposition.js +71 -24
  59. package/lib/display/display_utils.js +777 -0
  60. package/lib/display/fetch_stream.js +205 -87
  61. package/lib/display/font_loader.js +468 -236
  62. package/lib/display/metadata.js +38 -16
  63. package/lib/display/network.js +635 -428
  64. package/lib/display/network_utils.js +38 -19
  65. package/lib/display/node_stream.js +367 -175
  66. package/lib/display/pattern_helper.js +103 -36
  67. package/lib/display/svg.js +1232 -519
  68. package/lib/display/text_layer.js +208 -75
  69. package/lib/display/transport_stream.js +345 -94
  70. package/lib/display/webgl.js +64 -18
  71. package/lib/display/worker_options.js +5 -4
  72. package/lib/display/xml_parser.js +166 -53
  73. package/lib/examples/node/domstubs.js +60 -4
  74. package/lib/pdf.js +35 -14
  75. package/lib/pdf.worker.js +5 -3
  76. package/lib/shared/compatibility.js +170 -572
  77. package/lib/shared/global_scope.js +2 -2
  78. package/lib/shared/is_node.js +4 -4
  79. package/lib/shared/message_handler.js +216 -163
  80. package/lib/shared/streams_polyfill.js +21 -17
  81. package/lib/shared/util.js +495 -385
  82. package/lib/test/unit/annotation_spec.js +1464 -401
  83. package/lib/test/unit/api_spec.js +718 -361
  84. package/lib/test/unit/bidi_spec.js +7 -7
  85. package/lib/test/unit/cff_parser_spec.js +54 -11
  86. package/lib/test/unit/clitests_helper.js +9 -10
  87. package/lib/test/unit/cmap_spec.js +95 -41
  88. package/lib/test/unit/colorspace_spec.js +115 -63
  89. package/lib/test/unit/core_utils_spec.js +191 -0
  90. package/lib/test/unit/crypto_spec.js +17 -5
  91. package/lib/test/unit/custom_spec.js +43 -55
  92. package/lib/test/unit/display_svg_spec.js +34 -18
  93. package/lib/test/unit/display_utils_spec.js +273 -0
  94. package/lib/test/unit/document_spec.js +8 -13
  95. package/lib/test/unit/encodings_spec.js +25 -45
  96. package/lib/test/unit/evaluator_spec.js +59 -20
  97. package/lib/test/unit/fetch_stream_spec.js +111 -0
  98. package/lib/test/unit/function_spec.js +17 -5
  99. package/lib/test/unit/jasmine-boot.js +33 -20
  100. package/lib/test/unit/message_handler_spec.js +30 -13
  101. package/lib/test/unit/metadata_spec.js +71 -11
  102. package/lib/test/unit/murmurhash3_spec.js +3 -3
  103. package/lib/test/unit/network_spec.js +22 -55
  104. package/lib/test/unit/network_utils_spec.js +105 -14
  105. package/lib/test/unit/node_stream_spec.js +58 -34
  106. package/lib/test/unit/parser_spec.js +162 -71
  107. package/lib/test/unit/pdf_find_controller_spec.js +230 -0
  108. package/lib/test/unit/pdf_find_utils_spec.js +63 -0
  109. package/lib/test/unit/pdf_history_spec.js +21 -9
  110. package/lib/test/unit/primitives_spec.js +55 -22
  111. package/lib/test/unit/stream_spec.js +12 -4
  112. package/lib/test/unit/test_utils.js +273 -56
  113. package/lib/test/unit/testreporter.js +21 -3
  114. package/lib/test/unit/type1_parser_spec.js +9 -7
  115. package/lib/test/unit/ui_utils_spec.js +236 -36
  116. package/lib/test/unit/unicode_spec.js +18 -15
  117. package/lib/test/unit/util_spec.js +87 -128
  118. package/lib/web/annotation_layer_builder.js +39 -22
  119. package/lib/web/app.js +1252 -609
  120. package/lib/web/app_options.js +103 -65
  121. package/lib/web/base_viewer.js +522 -242
  122. package/lib/web/chromecom.js +259 -117
  123. package/lib/web/debugger.js +166 -22
  124. package/lib/web/download_manager.js +31 -12
  125. package/lib/web/firefox_print_service.js +27 -14
  126. package/lib/web/firefoxcom.js +318 -78
  127. package/lib/web/genericcom.js +89 -30
  128. package/lib/web/genericl10n.js +142 -30
  129. package/lib/web/grab_to_pan.js +28 -4
  130. package/lib/web/interfaces.js +174 -47
  131. package/lib/web/overlay_manager.js +235 -85
  132. package/lib/web/password_prompt.js +22 -14
  133. package/lib/web/pdf_attachment_viewer.js +38 -18
  134. package/lib/web/pdf_cursor_tools.js +39 -16
  135. package/lib/web/pdf_document_properties.js +255 -136
  136. package/lib/web/pdf_find_bar.js +84 -40
  137. package/lib/web/pdf_find_controller.js +495 -184
  138. package/lib/web/pdf_find_utils.js +111 -0
  139. package/lib/web/pdf_history.js +190 -53
  140. package/lib/web/pdf_link_service.js +144 -79
  141. package/lib/web/pdf_outline_viewer.js +124 -47
  142. package/lib/web/pdf_page_view.js +194 -74
  143. package/lib/web/pdf_presentation_mode.js +99 -34
  144. package/lib/web/pdf_print_service.js +59 -13
  145. package/lib/web/pdf_rendering_queue.js +28 -9
  146. package/lib/web/pdf_sidebar.js +144 -81
  147. package/lib/web/pdf_sidebar_resizer.js +42 -16
  148. package/lib/web/pdf_single_page_viewer.js +74 -66
  149. package/lib/web/pdf_thumbnail_view.js +104 -33
  150. package/lib/web/pdf_thumbnail_viewer.js +66 -26
  151. package/lib/web/pdf_viewer.component.js +112 -32
  152. package/lib/web/pdf_viewer.js +82 -87
  153. package/lib/web/preferences.js +284 -91
  154. package/lib/web/secondary_toolbar.js +132 -59
  155. package/lib/web/text_layer_builder.js +134 -59
  156. package/lib/web/toolbar.js +80 -43
  157. package/lib/web/ui_utils.js +400 -134
  158. package/lib/web/view_history.js +215 -67
  159. package/lib/web/viewer_compatibility.js +3 -8
  160. package/package.json +3 -2
  161. package/web/pdf_viewer.css +23 -15
  162. package/web/pdf_viewer.js +3429 -1245
  163. package/web/pdf_viewer.js.map +1 -1
  164. package/external/streams/streams-lib.js +0 -3962
  165. package/lib/display/dom_utils.js +0 -429
  166. package/lib/test/unit/dom_utils_spec.js +0 -89
  167. package/lib/test/unit/fonts_spec.js +0 -81
  168. package/lib/web/dom_events.js +0 -137
@@ -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 2017 Mozilla Foundation
5
+ * Copyright 2019 Mozilla Foundation
6
6
  *
7
7
  * Licensed under the Apache License, Version 2.0 (the "License");
8
8
  * you may not use this file except in compliance with the License.
@@ -19,41 +19,59 @@
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
24
  Object.defineProperty(exports, "__esModule", {
25
25
  value: true
26
26
  });
27
- exports.PDFDocument = exports.Page = undefined;
27
+ exports.PDFDocument = exports.Page = void 0;
28
28
 
29
- 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"); } }; }();
29
+ var _util = require("../shared/util");
30
30
 
31
- var _obj = require('./obj');
31
+ var _obj = require("./obj");
32
32
 
33
- var _primitives = require('./primitives');
33
+ var _primitives = require("./primitives");
34
34
 
35
- var _util = require('../shared/util');
35
+ var _core_utils = require("./core_utils");
36
36
 
37
- var _stream = require('./stream');
37
+ var _stream2 = require("./stream");
38
38
 
39
- var _annotation = require('./annotation');
39
+ var _annotation = require("./annotation");
40
40
 
41
- var _crypto = require('./crypto');
41
+ var _crypto = require("./crypto");
42
42
 
43
- var _parser = require('./parser');
43
+ var _parser = require("./parser");
44
44
 
45
- var _operator_list = require('./operator_list');
45
+ var _operator_list = require("./operator_list");
46
46
 
47
- var _evaluator = require('./evaluator');
47
+ var _evaluator = require("./evaluator");
48
48
 
49
- var _function = require('./function');
49
+ var _function = require("./function");
50
50
 
51
- var Page = function PageClosure() {
52
- var DEFAULT_USER_UNIT = 1.0;
53
- var LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
54
- function isAnnotationRenderable(annotation, intent) {
55
- return intent === 'display' && annotation.viewable || intent === 'print' && annotation.printable;
56
- }
51
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
52
+
53
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
54
+
55
+ 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; }
56
+
57
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
58
+
59
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
60
+
61
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
62
+
63
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
64
+
65
+ var DEFAULT_USER_UNIT = 1.0;
66
+ var LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
67
+
68
+ function isAnnotationRenderable(annotation, intent) {
69
+ return intent === 'display' && annotation.viewable || intent === 'print' && annotation.printable;
70
+ }
71
+
72
+ var Page =
73
+ /*#__PURE__*/
74
+ function () {
57
75
  function Page(_ref) {
58
76
  var pdfManager = _ref.pdfManager,
59
77
  xref = _ref.xref,
@@ -64,6 +82,8 @@ var Page = function PageClosure() {
64
82
  builtInCMapCache = _ref.builtInCMapCache,
65
83
  pdfFunctionFactory = _ref.pdfFunctionFactory;
66
84
 
85
+ _classCallCheck(this, Page);
86
+
67
87
  this.pdfManager = pdfManager;
68
88
  this.pageIndex = pageIndex;
69
89
  this.pageDict = pageDict;
@@ -74,122 +94,124 @@ var Page = function PageClosure() {
74
94
  this.pdfFunctionFactory = pdfFunctionFactory;
75
95
  this.evaluatorOptions = pdfManager.evaluatorOptions;
76
96
  this.resourcesPromise = null;
77
- var uniquePrefix = 'p' + this.pageIndex + '_';
78
- var idCounters = { obj: 0 };
97
+ var idCounters = {
98
+ obj: 0
99
+ };
79
100
  this.idFactory = {
80
101
  createObjId: function createObjId() {
81
- return uniquePrefix + ++idCounters.obj;
102
+ return "p".concat(pageIndex, "_").concat(++idCounters.obj);
103
+ },
104
+ getDocId: function getDocId() {
105
+ return "g_".concat(pdfManager.docId);
82
106
  }
83
107
  };
84
108
  }
85
- Page.prototype = {
86
- _getInheritableProperty: function _getInheritableProperty(key) {
87
- var getArray = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
88
109
 
89
- var value = (0, _util.getInheritableProperty)({
110
+ _createClass(Page, [{
111
+ key: "_getInheritableProperty",
112
+ value: function _getInheritableProperty(key) {
113
+ var getArray = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
114
+ var value = (0, _core_utils.getInheritableProperty)({
90
115
  dict: this.pageDict,
91
116
  key: key,
92
117
  getArray: getArray,
93
118
  stopWhenFound: false
94
119
  });
120
+
95
121
  if (!Array.isArray(value)) {
96
122
  return value;
97
123
  }
124
+
98
125
  if (value.length === 1 || !(0, _primitives.isDict)(value[0])) {
99
126
  return value[0];
100
127
  }
128
+
101
129
  return _primitives.Dict.merge(this.xref, value);
102
- },
130
+ }
131
+ }, {
132
+ key: "_getBoundingBox",
133
+ value: function _getBoundingBox(name) {
134
+ var box = this._getInheritableProperty(name, true);
103
135
 
104
- get content() {
105
- return this.pageDict.get('Contents');
106
- },
107
- get resources() {
108
- return (0, _util.shadow)(this, 'resources', this._getInheritableProperty('Resources') || _primitives.Dict.empty);
109
- },
110
- get mediaBox() {
111
- var mediaBox = this._getInheritableProperty('MediaBox', true);
112
- if (!Array.isArray(mediaBox) || mediaBox.length !== 4) {
113
- return (0, _util.shadow)(this, 'mediaBox', LETTER_SIZE_MEDIABOX);
114
- }
115
- return (0, _util.shadow)(this, 'mediaBox', mediaBox);
116
- },
117
- get cropBox() {
118
- var cropBox = this._getInheritableProperty('CropBox', true);
119
- if (!Array.isArray(cropBox) || cropBox.length !== 4) {
120
- return (0, _util.shadow)(this, 'cropBox', this.mediaBox);
121
- }
122
- return (0, _util.shadow)(this, 'cropBox', cropBox);
123
- },
124
- get userUnit() {
125
- var obj = this.pageDict.get('UserUnit');
126
- if (!(0, _util.isNum)(obj) || obj <= 0) {
127
- obj = DEFAULT_USER_UNIT;
128
- }
129
- return (0, _util.shadow)(this, 'userUnit', obj);
130
- },
131
- get view() {
132
- var mediaBox = this.mediaBox,
133
- cropBox = this.cropBox;
134
- if (mediaBox === cropBox) {
135
- return (0, _util.shadow)(this, 'view', mediaBox);
136
- }
137
- var intersection = _util.Util.intersect(cropBox, mediaBox);
138
- return (0, _util.shadow)(this, 'view', intersection || mediaBox);
139
- },
140
- get rotate() {
141
- var rotate = this._getInheritableProperty('Rotate') || 0;
142
- if (rotate % 90 !== 0) {
143
- rotate = 0;
144
- } else if (rotate >= 360) {
145
- rotate = rotate % 360;
146
- } else if (rotate < 0) {
147
- rotate = (rotate % 360 + 360) % 360;
136
+ if (Array.isArray(box) && box.length === 4) {
137
+ if (box[2] - box[0] !== 0 && box[3] - box[1] !== 0) {
138
+ return box;
139
+ }
140
+
141
+ (0, _util.warn)("Empty /".concat(name, " entry."));
148
142
  }
149
- return (0, _util.shadow)(this, 'rotate', rotate);
150
- },
151
- getContentStream: function Page_getContentStream() {
143
+
144
+ return null;
145
+ }
146
+ }, {
147
+ key: "getContentStream",
148
+ value: function getContentStream() {
152
149
  var content = this.content;
153
150
  var stream;
151
+
154
152
  if (Array.isArray(content)) {
155
153
  var xref = this.xref;
156
- var i,
157
- n = content.length;
158
154
  var streams = [];
159
- for (i = 0; i < n; ++i) {
160
- streams.push(xref.fetchIfRef(content[i]));
155
+ var _iteratorNormalCompletion = true;
156
+ var _didIteratorError = false;
157
+ var _iteratorError = undefined;
158
+
159
+ try {
160
+ for (var _iterator = content[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
161
+ var _stream = _step.value;
162
+ streams.push(xref.fetchIfRef(_stream));
163
+ }
164
+ } catch (err) {
165
+ _didIteratorError = true;
166
+ _iteratorError = err;
167
+ } finally {
168
+ try {
169
+ if (!_iteratorNormalCompletion && _iterator["return"] != null) {
170
+ _iterator["return"]();
171
+ }
172
+ } finally {
173
+ if (_didIteratorError) {
174
+ throw _iteratorError;
175
+ }
176
+ }
161
177
  }
162
- stream = new _stream.StreamsSequenceStream(streams);
178
+
179
+ stream = new _stream2.StreamsSequenceStream(streams);
163
180
  } else if ((0, _primitives.isStream)(content)) {
164
181
  stream = content;
165
182
  } else {
166
- stream = new _stream.NullStream();
183
+ stream = new _stream2.NullStream();
167
184
  }
185
+
168
186
  return stream;
169
- },
170
- loadResources: function Page_loadResources(keys) {
187
+ }
188
+ }, {
189
+ key: "loadResources",
190
+ value: function loadResources(keys) {
171
191
  var _this = this;
172
192
 
173
193
  if (!this.resourcesPromise) {
174
194
  this.resourcesPromise = this.pdfManager.ensure(this, 'resources');
175
195
  }
196
+
176
197
  return this.resourcesPromise.then(function () {
177
198
  var objectLoader = new _obj.ObjectLoader(_this.resources, keys, _this.xref);
178
199
  return objectLoader.load();
179
200
  });
180
- },
181
- getOperatorList: function getOperatorList(_ref2) {
201
+ }
202
+ }, {
203
+ key: "getOperatorList",
204
+ value: function getOperatorList(_ref2) {
182
205
  var _this2 = this;
183
206
 
184
207
  var handler = _ref2.handler,
208
+ sink = _ref2.sink,
185
209
  task = _ref2.task,
186
210
  intent = _ref2.intent,
187
211
  renderInteractiveForms = _ref2.renderInteractiveForms;
188
-
189
212
  var contentStreamPromise = this.pdfManager.ensure(this, 'getContentStream');
190
213
  var resourcesPromise = this.loadResources(['ExtGState', 'ColorSpace', 'Pattern', 'Shading', 'XObject', 'Font']);
191
214
  var partialEvaluator = new _evaluator.PartialEvaluator({
192
- pdfManager: this.pdfManager,
193
215
  xref: this.xref,
194
216
  handler: handler,
195
217
  pageIndex: this.pageIndex,
@@ -204,7 +226,7 @@ var Page = function PageClosure() {
204
226
  var _ref4 = _slicedToArray(_ref3, 1),
205
227
  contentStream = _ref4[0];
206
228
 
207
- var opList = new _operator_list.OperatorList(intent, handler, _this2.pageIndex);
229
+ var opList = new _operator_list.OperatorList(intent, sink, _this2.pageIndex);
208
230
  handler.send('StartRenderPage', {
209
231
  transparency: partialEvaluator.hasBlendModes(_this2.resources),
210
232
  pageIndex: _this2.pageIndex,
@@ -219,36 +241,83 @@ var Page = function PageClosure() {
219
241
  return opList;
220
242
  });
221
243
  });
222
- var annotationsPromise = this.pdfManager.ensure(this, 'annotations');
223
- return Promise.all([pageListPromise, annotationsPromise]).then(function (_ref5) {
244
+ return Promise.all([pageListPromise, this._parsedAnnotations]).then(function (_ref5) {
224
245
  var _ref6 = _slicedToArray(_ref5, 2),
225
246
  pageOpList = _ref6[0],
226
247
  annotations = _ref6[1];
227
248
 
228
249
  if (annotations.length === 0) {
229
250
  pageOpList.flush(true);
230
- return pageOpList;
251
+ return {
252
+ length: pageOpList.totalLength
253
+ };
231
254
  }
232
- var i,
233
- ii,
234
- opListPromises = [];
235
- for (i = 0, ii = annotations.length; i < ii; i++) {
236
- if (isAnnotationRenderable(annotations[i], intent)) {
237
- opListPromises.push(annotations[i].getOperatorList(partialEvaluator, task, renderInteractiveForms));
255
+
256
+ var opListPromises = [];
257
+ var _iteratorNormalCompletion2 = true;
258
+ var _didIteratorError2 = false;
259
+ var _iteratorError2 = undefined;
260
+
261
+ try {
262
+ for (var _iterator2 = annotations[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
263
+ var annotation = _step2.value;
264
+
265
+ if (isAnnotationRenderable(annotation, intent)) {
266
+ opListPromises.push(annotation.getOperatorList(partialEvaluator, task, renderInteractiveForms));
267
+ }
268
+ }
269
+ } catch (err) {
270
+ _didIteratorError2 = true;
271
+ _iteratorError2 = err;
272
+ } finally {
273
+ try {
274
+ if (!_iteratorNormalCompletion2 && _iterator2["return"] != null) {
275
+ _iterator2["return"]();
276
+ }
277
+ } finally {
278
+ if (_didIteratorError2) {
279
+ throw _iteratorError2;
280
+ }
238
281
  }
239
282
  }
283
+
240
284
  return Promise.all(opListPromises).then(function (opLists) {
241
285
  pageOpList.addOp(_util.OPS.beginAnnotations, []);
242
- for (i = 0, ii = opLists.length; i < ii; i++) {
243
- pageOpList.addOpList(opLists[i]);
286
+ var _iteratorNormalCompletion3 = true;
287
+ var _didIteratorError3 = false;
288
+ var _iteratorError3 = undefined;
289
+
290
+ try {
291
+ for (var _iterator3 = opLists[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
292
+ var opList = _step3.value;
293
+ pageOpList.addOpList(opList);
294
+ }
295
+ } catch (err) {
296
+ _didIteratorError3 = true;
297
+ _iteratorError3 = err;
298
+ } finally {
299
+ try {
300
+ if (!_iteratorNormalCompletion3 && _iterator3["return"] != null) {
301
+ _iterator3["return"]();
302
+ }
303
+ } finally {
304
+ if (_didIteratorError3) {
305
+ throw _iteratorError3;
306
+ }
307
+ }
244
308
  }
309
+
245
310
  pageOpList.addOp(_util.OPS.endAnnotations, []);
246
311
  pageOpList.flush(true);
247
- return pageOpList;
312
+ return {
313
+ length: pageOpList.totalLength
314
+ };
248
315
  });
249
316
  });
250
- },
251
- extractTextContent: function extractTextContent(_ref7) {
317
+ }
318
+ }, {
319
+ key: "extractTextContent",
320
+ value: function extractTextContent(_ref7) {
252
321
  var _this3 = this;
253
322
 
254
323
  var handler = _ref7.handler,
@@ -256,7 +325,6 @@ var Page = function PageClosure() {
256
325
  normalizeWhitespace = _ref7.normalizeWhitespace,
257
326
  sink = _ref7.sink,
258
327
  combineTextItems = _ref7.combineTextItems;
259
-
260
328
  var contentStreamPromise = this.pdfManager.ensure(this, 'getContentStream');
261
329
  var resourcesPromise = this.loadResources(['ExtGState', 'XObject', 'Font']);
262
330
  var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
@@ -265,7 +333,6 @@ var Page = function PageClosure() {
265
333
  contentStream = _ref9[0];
266
334
 
267
335
  var partialEvaluator = new _evaluator.PartialEvaluator({
268
- pdfManager: _this3.pdfManager,
269
336
  xref: _this3.xref,
270
337
  handler: handler,
271
338
  pageIndex: _this3.pageIndex,
@@ -284,283 +351,519 @@ var Page = function PageClosure() {
284
351
  sink: sink
285
352
  });
286
353
  });
287
- },
288
-
289
- getAnnotationsData: function Page_getAnnotationsData(intent) {
290
- var annotations = this.annotations;
291
- var annotationsData = [];
292
- for (var i = 0, n = annotations.length; i < n; ++i) {
293
- if (!intent || isAnnotationRenderable(annotations[i], intent)) {
294
- annotationsData.push(annotations[i].data);
354
+ }
355
+ }, {
356
+ key: "getAnnotationsData",
357
+ value: function getAnnotationsData(intent) {
358
+ return this._parsedAnnotations.then(function (annotations) {
359
+ var annotationsData = [];
360
+
361
+ for (var i = 0, ii = annotations.length; i < ii; i++) {
362
+ if (!intent || isAnnotationRenderable(annotations[i], intent)) {
363
+ annotationsData.push(annotations[i].data);
364
+ }
295
365
  }
366
+
367
+ return annotationsData;
368
+ });
369
+ }
370
+ }, {
371
+ key: "content",
372
+ get: function get() {
373
+ return this.pageDict.get('Contents');
374
+ }
375
+ }, {
376
+ key: "resources",
377
+ get: function get() {
378
+ return (0, _util.shadow)(this, 'resources', this._getInheritableProperty('Resources') || _primitives.Dict.empty);
379
+ }
380
+ }, {
381
+ key: "mediaBox",
382
+ get: function get() {
383
+ return (0, _util.shadow)(this, 'mediaBox', this._getBoundingBox('MediaBox') || LETTER_SIZE_MEDIABOX);
384
+ }
385
+ }, {
386
+ key: "cropBox",
387
+ get: function get() {
388
+ return (0, _util.shadow)(this, 'cropBox', this._getBoundingBox('CropBox') || this.mediaBox);
389
+ }
390
+ }, {
391
+ key: "userUnit",
392
+ get: function get() {
393
+ var obj = this.pageDict.get('UserUnit');
394
+
395
+ if (!(0, _util.isNum)(obj) || obj <= 0) {
396
+ obj = DEFAULT_USER_UNIT;
296
397
  }
297
- return annotationsData;
298
- },
299
- get annotations() {
300
- var annotations = [];
301
- var annotationRefs = this._getInheritableProperty('Annots') || [];
302
- for (var i = 0, n = annotationRefs.length; i < n; ++i) {
303
- var annotationRef = annotationRefs[i];
304
- var annotation = _annotation.AnnotationFactory.create(this.xref, annotationRef, this.pdfManager, this.idFactory);
305
- if (annotation) {
306
- annotations.push(annotation);
398
+
399
+ return (0, _util.shadow)(this, 'userUnit', obj);
400
+ }
401
+ }, {
402
+ key: "view",
403
+ get: function get() {
404
+ var cropBox = this.cropBox,
405
+ mediaBox = this.mediaBox;
406
+ var view;
407
+
408
+ if (cropBox === mediaBox || (0, _util.isArrayEqual)(cropBox, mediaBox)) {
409
+ view = mediaBox;
410
+ } else {
411
+ var box = _util.Util.intersect(cropBox, mediaBox);
412
+
413
+ if (box && box[2] - box[0] !== 0 && box[3] - box[1] !== 0) {
414
+ view = box;
415
+ } else {
416
+ (0, _util.warn)('Empty /CropBox and /MediaBox intersection.');
307
417
  }
308
418
  }
309
- return (0, _util.shadow)(this, 'annotations', annotations);
419
+
420
+ return (0, _util.shadow)(this, 'view', view || mediaBox);
310
421
  }
311
- };
422
+ }, {
423
+ key: "rotate",
424
+ get: function get() {
425
+ var rotate = this._getInheritableProperty('Rotate') || 0;
426
+
427
+ if (rotate % 90 !== 0) {
428
+ rotate = 0;
429
+ } else if (rotate >= 360) {
430
+ rotate = rotate % 360;
431
+ } else if (rotate < 0) {
432
+ rotate = (rotate % 360 + 360) % 360;
433
+ }
434
+
435
+ return (0, _util.shadow)(this, 'rotate', rotate);
436
+ }
437
+ }, {
438
+ key: "annotations",
439
+ get: function get() {
440
+ return (0, _util.shadow)(this, 'annotations', this._getInheritableProperty('Annots') || []);
441
+ }
442
+ }, {
443
+ key: "_parsedAnnotations",
444
+ get: function get() {
445
+ var _this4 = this;
446
+
447
+ var parsedAnnotations = this.pdfManager.ensure(this, 'annotations').then(function () {
448
+ var annotationRefs = _this4.annotations;
449
+ var annotationPromises = [];
450
+
451
+ for (var i = 0, ii = annotationRefs.length; i < ii; i++) {
452
+ annotationPromises.push(_annotation.AnnotationFactory.create(_this4.xref, annotationRefs[i], _this4.pdfManager, _this4.idFactory));
453
+ }
454
+
455
+ return Promise.all(annotationPromises).then(function (annotations) {
456
+ return annotations.filter(function isDefined(annotation) {
457
+ return !!annotation;
458
+ });
459
+ }, function (reason) {
460
+ (0, _util.warn)("_parsedAnnotations: \"".concat(reason, "\"."));
461
+ return [];
462
+ });
463
+ });
464
+ return (0, _util.shadow)(this, '_parsedAnnotations', parsedAnnotations);
465
+ }
466
+ }]);
467
+
312
468
  return Page;
313
469
  }();
314
- var PDFDocument = function PDFDocumentClosure() {
315
- var FINGERPRINT_FIRST_BYTES = 1024;
316
- var EMPTY_FINGERPRINT = '\x00\x00\x00\x00\x00\x00\x00' + '\x00\x00\x00\x00\x00\x00\x00\x00\x00';
470
+
471
+ exports.Page = Page;
472
+ var FINGERPRINT_FIRST_BYTES = 1024;
473
+ var EMPTY_FINGERPRINT = '\x00\x00\x00\x00\x00\x00\x00' + '\x00\x00\x00\x00\x00\x00\x00\x00\x00';
474
+
475
+ function find(stream, needle, limit) {
476
+ var backwards = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
477
+ (0, _util.assert)(limit > 0, 'The "limit" must be a positive integer.');
478
+ var str = (0, _util.bytesToString)(stream.peekBytes(limit));
479
+ var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
480
+
481
+ if (index === -1) {
482
+ return false;
483
+ }
484
+
485
+ stream.pos += index;
486
+ return true;
487
+ }
488
+
489
+ var PDFDocument =
490
+ /*#__PURE__*/
491
+ function () {
317
492
  function PDFDocument(pdfManager, arg) {
493
+ _classCallCheck(this, PDFDocument);
494
+
318
495
  var stream;
496
+
319
497
  if ((0, _primitives.isStream)(arg)) {
320
498
  stream = arg;
321
499
  } else if ((0, _util.isArrayBuffer)(arg)) {
322
- stream = new _stream.Stream(arg);
500
+ stream = new _stream2.Stream(arg);
323
501
  } else {
324
502
  throw new Error('PDFDocument: Unknown argument type');
325
503
  }
504
+
326
505
  if (stream.length <= 0) {
327
- throw new Error('PDFDocument: stream must have data');
506
+ throw new Error('PDFDocument: Stream must have data');
328
507
  }
508
+
329
509
  this.pdfManager = pdfManager;
330
510
  this.stream = stream;
331
511
  this.xref = new _obj.XRef(stream, pdfManager);
332
- var evaluatorOptions = pdfManager.evaluatorOptions;
333
512
  this.pdfFunctionFactory = new _function.PDFFunctionFactory({
334
513
  xref: this.xref,
335
- isEvalSupported: evaluatorOptions.isEvalSupported
514
+ isEvalSupported: pdfManager.evaluatorOptions.isEvalSupported
336
515
  });
516
+ this._pagePromises = [];
337
517
  }
338
- function find(stream, needle, limit, backwards) {
339
- var pos = stream.pos;
340
- var end = stream.end;
341
- var strBuf = [];
342
- if (pos + limit > end) {
343
- limit = end - pos;
344
- }
345
- for (var n = 0; n < limit; ++n) {
346
- strBuf.push(String.fromCharCode(stream.getByte()));
347
- }
348
- var str = strBuf.join('');
349
- stream.pos = pos;
350
- var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
351
- if (index === -1) {
352
- return false;
353
- }
354
- stream.pos += index;
355
- return true;
356
- }
357
- var DocumentInfoValidators = {
358
- get entries() {
359
- return (0, _util.shadow)(this, 'entries', {
360
- Title: _util.isString,
361
- Author: _util.isString,
362
- Subject: _util.isString,
363
- Keywords: _util.isString,
364
- Creator: _util.isString,
365
- Producer: _util.isString,
366
- CreationDate: _util.isString,
367
- ModDate: _util.isString,
368
- Trapped: _primitives.isName
369
- });
370
- }
371
- };
372
- PDFDocument.prototype = {
373
- parse: function PDFDocument_parse(recoveryMode) {
518
+
519
+ _createClass(PDFDocument, [{
520
+ key: "parse",
521
+ value: function parse(recoveryMode) {
374
522
  this.setup(recoveryMode);
375
523
  var version = this.catalog.catDict.get('Version');
524
+
376
525
  if ((0, _primitives.isName)(version)) {
377
526
  this.pdfFormatVersion = version.name;
378
527
  }
528
+
379
529
  try {
380
530
  this.acroForm = this.catalog.catDict.get('AcroForm');
531
+
381
532
  if (this.acroForm) {
382
533
  this.xfa = this.acroForm.get('XFA');
383
534
  var fields = this.acroForm.get('Fields');
384
- if ((!fields || !Array.isArray(fields) || fields.length === 0) && !this.xfa) {
535
+
536
+ if ((!Array.isArray(fields) || fields.length === 0) && !this.xfa) {
385
537
  this.acroForm = null;
386
538
  }
387
539
  }
388
540
  } catch (ex) {
389
- if (ex instanceof _util.MissingDataException) {
541
+ if (ex instanceof _core_utils.MissingDataException) {
390
542
  throw ex;
391
543
  }
392
- (0, _util.info)('Something wrong with AcroForm entry');
544
+
545
+ (0, _util.info)('Cannot fetch AcroForm entry; assuming no AcroForms are present');
393
546
  this.acroForm = null;
394
547
  }
395
- },
396
- get linearization() {
397
- var linearization = null;
398
- if (this.stream.length) {
399
- try {
400
- linearization = _parser.Linearization.create(this.stream);
401
- } catch (err) {
402
- if (err instanceof _util.MissingDataException) {
403
- throw err;
548
+
549
+ try {
550
+ var collection = this.catalog.catDict.get('Collection');
551
+
552
+ if ((0, _primitives.isDict)(collection) && collection.getKeys().length > 0) {
553
+ this.collection = collection;
554
+ }
555
+ } catch (ex) {
556
+ if (ex instanceof _core_utils.MissingDataException) {
557
+ throw ex;
558
+ }
559
+
560
+ (0, _util.info)('Cannot fetch Collection dictionary.');
561
+ }
562
+ }
563
+ }, {
564
+ key: "checkHeader",
565
+ value: function checkHeader() {
566
+ var stream = this.stream;
567
+ stream.reset();
568
+
569
+ if (!find(stream, '%PDF-', 1024)) {
570
+ return;
571
+ }
572
+
573
+ stream.moveStart();
574
+ var MAX_PDF_VERSION_LENGTH = 12;
575
+ var version = '',
576
+ ch;
577
+
578
+ while ((ch = stream.getByte()) > 0x20) {
579
+ if (version.length >= MAX_PDF_VERSION_LENGTH) {
580
+ break;
581
+ }
582
+
583
+ version += String.fromCharCode(ch);
584
+ }
585
+
586
+ if (!this.pdfFormatVersion) {
587
+ this.pdfFormatVersion = version.substring(5);
588
+ }
589
+ }
590
+ }, {
591
+ key: "parseStartXRef",
592
+ value: function parseStartXRef() {
593
+ this.xref.setStartXRef(this.startXRef);
594
+ }
595
+ }, {
596
+ key: "setup",
597
+ value: function setup(recoveryMode) {
598
+ this.xref.parse(recoveryMode);
599
+ this.catalog = new _obj.Catalog(this.pdfManager, this.xref);
600
+ }
601
+ }, {
602
+ key: "_getLinearizationPage",
603
+ value: function _getLinearizationPage(pageIndex) {
604
+ var catalog = this.catalog,
605
+ linearization = this.linearization;
606
+ (0, _util.assert)(linearization && linearization.pageFirst === pageIndex);
607
+
608
+ var ref = _primitives.Ref.get(linearization.objectNumberFirst, 0);
609
+
610
+ return this.xref.fetchAsync(ref).then(function (obj) {
611
+ if ((0, _primitives.isDict)(obj, 'Page') || (0, _primitives.isDict)(obj) && !obj.has('Type') && obj.has('Contents')) {
612
+ if (ref && !catalog.pageKidsCountCache.has(ref)) {
613
+ catalog.pageKidsCountCache.put(ref, 1);
404
614
  }
405
- (0, _util.info)(err);
615
+
616
+ return [obj, ref];
617
+ }
618
+
619
+ throw new _util.FormatError('The Linearization dictionary doesn\'t point ' + 'to a valid Page dictionary.');
620
+ })["catch"](function (reason) {
621
+ (0, _util.info)(reason);
622
+ return catalog.getPageDict(pageIndex);
623
+ });
624
+ }
625
+ }, {
626
+ key: "getPage",
627
+ value: function getPage(pageIndex) {
628
+ var _this5 = this;
629
+
630
+ if (this._pagePromises[pageIndex] !== undefined) {
631
+ return this._pagePromises[pageIndex];
632
+ }
633
+
634
+ var catalog = this.catalog,
635
+ linearization = this.linearization;
636
+ var promise = linearization && linearization.pageFirst === pageIndex ? this._getLinearizationPage(pageIndex) : catalog.getPageDict(pageIndex);
637
+ return this._pagePromises[pageIndex] = promise.then(function (_ref10) {
638
+ var _ref11 = _slicedToArray(_ref10, 2),
639
+ pageDict = _ref11[0],
640
+ ref = _ref11[1];
641
+
642
+ return new Page({
643
+ pdfManager: _this5.pdfManager,
644
+ xref: _this5.xref,
645
+ pageIndex: pageIndex,
646
+ pageDict: pageDict,
647
+ ref: ref,
648
+ fontCache: catalog.fontCache,
649
+ builtInCMapCache: catalog.builtInCMapCache,
650
+ pdfFunctionFactory: _this5.pdfFunctionFactory
651
+ });
652
+ });
653
+ }
654
+ }, {
655
+ key: "checkFirstPage",
656
+ value: function checkFirstPage() {
657
+ var _this6 = this;
658
+
659
+ return this.getPage(0)["catch"](function (reason) {
660
+ if (reason instanceof _core_utils.XRefEntryException) {
661
+ _this6._pagePromises.length = 0;
662
+
663
+ _this6.cleanup();
664
+
665
+ throw new _core_utils.XRefParseException();
666
+ }
667
+ });
668
+ }
669
+ }, {
670
+ key: "fontFallback",
671
+ value: function fontFallback(id, handler) {
672
+ return this.catalog.fontFallback(id, handler);
673
+ }
674
+ }, {
675
+ key: "cleanup",
676
+ value: function cleanup() {
677
+ return this.catalog.cleanup();
678
+ }
679
+ }, {
680
+ key: "linearization",
681
+ get: function get() {
682
+ var linearization = null;
683
+
684
+ try {
685
+ linearization = _parser.Linearization.create(this.stream);
686
+ } catch (err) {
687
+ if (err instanceof _core_utils.MissingDataException) {
688
+ throw err;
406
689
  }
690
+
691
+ (0, _util.info)(err);
407
692
  }
693
+
408
694
  return (0, _util.shadow)(this, 'linearization', linearization);
409
- },
410
- get startXRef() {
695
+ }
696
+ }, {
697
+ key: "startXRef",
698
+ get: function get() {
411
699
  var stream = this.stream;
412
700
  var startXRef = 0;
413
- var linearization = this.linearization;
414
- if (linearization) {
701
+
702
+ if (this.linearization) {
415
703
  stream.reset();
704
+
416
705
  if (find(stream, 'endobj', 1024)) {
417
706
  startXRef = stream.pos + 6;
418
707
  }
419
708
  } else {
420
709
  var step = 1024;
710
+ var startXRefLength = 'startxref'.length;
421
711
  var found = false,
422
712
  pos = stream.end;
713
+
423
714
  while (!found && pos > 0) {
424
- pos -= step - 'startxref'.length;
715
+ pos -= step - startXRefLength;
716
+
425
717
  if (pos < 0) {
426
718
  pos = 0;
427
719
  }
720
+
428
721
  stream.pos = pos;
429
722
  found = find(stream, 'startxref', step, true);
430
723
  }
724
+
431
725
  if (found) {
432
726
  stream.skip(9);
433
727
  var ch;
728
+
434
729
  do {
435
730
  ch = stream.getByte();
436
731
  } while ((0, _util.isSpace)(ch));
732
+
437
733
  var str = '';
734
+
438
735
  while (ch >= 0x20 && ch <= 0x39) {
439
736
  str += String.fromCharCode(ch);
440
737
  ch = stream.getByte();
441
738
  }
739
+
442
740
  startXRef = parseInt(str, 10);
741
+
443
742
  if (isNaN(startXRef)) {
444
743
  startXRef = 0;
445
744
  }
446
745
  }
447
746
  }
448
- return (0, _util.shadow)(this, 'startXRef', startXRef);
449
- },
450
- get mainXRefEntriesOffset() {
451
- var mainXRefEntriesOffset = 0;
452
- var linearization = this.linearization;
453
- if (linearization) {
454
- mainXRefEntriesOffset = linearization.mainXRefEntriesOffset;
455
- }
456
- return (0, _util.shadow)(this, 'mainXRefEntriesOffset', mainXRefEntriesOffset);
457
- },
458
- checkHeader: function PDFDocument_checkHeader() {
459
- var stream = this.stream;
460
- stream.reset();
461
- if (find(stream, '%PDF-', 1024)) {
462
- stream.moveStart();
463
- var MAX_VERSION_LENGTH = 12;
464
- var version = '',
465
- ch;
466
- while ((ch = stream.getByte()) > 0x20) {
467
- if (version.length >= MAX_VERSION_LENGTH) {
468
- break;
469
- }
470
- version += String.fromCharCode(ch);
471
- }
472
- if (!this.pdfFormatVersion) {
473
- this.pdfFormatVersion = version.substring(5);
474
- }
475
- return;
476
- }
477
- },
478
- parseStartXRef: function PDFDocument_parseStartXRef() {
479
- var startXRef = this.startXRef;
480
- this.xref.setStartXRef(startXRef);
481
- },
482
- setup: function PDFDocument_setup(recoveryMode) {
483
- var _this4 = this;
484
747
 
485
- this.xref.parse(recoveryMode);
486
- var pageFactory = {
487
- createPage: function createPage(pageIndex, dict, ref, fontCache, builtInCMapCache) {
488
- return new Page({
489
- pdfManager: _this4.pdfManager,
490
- xref: _this4.xref,
491
- pageIndex: pageIndex,
492
- pageDict: dict,
493
- ref: ref,
494
- fontCache: fontCache,
495
- builtInCMapCache: builtInCMapCache,
496
- pdfFunctionFactory: _this4.pdfFunctionFactory
497
- });
498
- }
499
- };
500
- this.catalog = new _obj.Catalog(this.pdfManager, this.xref, pageFactory);
501
- },
502
- get numPages() {
748
+ return (0, _util.shadow)(this, 'startXRef', startXRef);
749
+ }
750
+ }, {
751
+ key: "numPages",
752
+ get: function get() {
503
753
  var linearization = this.linearization;
504
754
  var num = linearization ? linearization.numPages : this.catalog.numPages;
505
755
  return (0, _util.shadow)(this, 'numPages', num);
506
- },
507
- get documentInfo() {
756
+ }
757
+ }, {
758
+ key: "documentInfo",
759
+ get: function get() {
760
+ var DocumentInfoValidators = {
761
+ Title: _util.isString,
762
+ Author: _util.isString,
763
+ Subject: _util.isString,
764
+ Keywords: _util.isString,
765
+ Creator: _util.isString,
766
+ Producer: _util.isString,
767
+ CreationDate: _util.isString,
768
+ ModDate: _util.isString,
769
+ Trapped: _primitives.isName
770
+ };
508
771
  var docInfo = {
509
772
  PDFFormatVersion: this.pdfFormatVersion,
773
+ IsLinearized: !!this.linearization,
510
774
  IsAcroFormPresent: !!this.acroForm,
511
- IsXFAPresent: !!this.xfa
775
+ IsXFAPresent: !!this.xfa,
776
+ IsCollectionPresent: !!this.collection
512
777
  };
513
778
  var infoDict;
779
+
514
780
  try {
515
781
  infoDict = this.xref.trailer.get('Info');
516
782
  } catch (err) {
517
- if (err instanceof _util.MissingDataException) {
783
+ if (err instanceof _core_utils.MissingDataException) {
518
784
  throw err;
519
785
  }
786
+
520
787
  (0, _util.info)('The document information dictionary is invalid.');
521
788
  }
522
- if (infoDict) {
523
- var validEntries = DocumentInfoValidators.entries;
524
- for (var key in validEntries) {
525
- if (infoDict.has(key)) {
789
+
790
+ if ((0, _primitives.isDict)(infoDict)) {
791
+ var _iteratorNormalCompletion4 = true;
792
+ var _didIteratorError4 = false;
793
+ var _iteratorError4 = undefined;
794
+
795
+ try {
796
+ for (var _iterator4 = infoDict.getKeys()[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
797
+ var key = _step4.value;
526
798
  var value = infoDict.get(key);
527
- if (validEntries[key](value)) {
528
- docInfo[key] = typeof value !== 'string' ? value : (0, _util.stringToPDFString)(value);
529
- } else {
530
- (0, _util.info)('Bad value in document info for "' + key + '"');
799
+
800
+ if (DocumentInfoValidators[key]) {
801
+ if (DocumentInfoValidators[key](value)) {
802
+ docInfo[key] = typeof value !== 'string' ? value : (0, _util.stringToPDFString)(value);
803
+ } else {
804
+ (0, _util.info)("Bad value in document info for \"".concat(key, "\"."));
805
+ }
806
+ } else if (typeof key === 'string') {
807
+ var customValue = void 0;
808
+
809
+ if ((0, _util.isString)(value)) {
810
+ customValue = (0, _util.stringToPDFString)(value);
811
+ } else if ((0, _primitives.isName)(value) || (0, _util.isNum)(value) || (0, _util.isBool)(value)) {
812
+ customValue = value;
813
+ } else {
814
+ (0, _util.info)("Unsupported value in document info for (custom) \"".concat(key, "\"."));
815
+ continue;
816
+ }
817
+
818
+ if (!docInfo['Custom']) {
819
+ docInfo['Custom'] = Object.create(null);
820
+ }
821
+
822
+ docInfo['Custom'][key] = customValue;
823
+ }
824
+ }
825
+ } catch (err) {
826
+ _didIteratorError4 = true;
827
+ _iteratorError4 = err;
828
+ } finally {
829
+ try {
830
+ if (!_iteratorNormalCompletion4 && _iterator4["return"] != null) {
831
+ _iterator4["return"]();
832
+ }
833
+ } finally {
834
+ if (_didIteratorError4) {
835
+ throw _iteratorError4;
531
836
  }
532
837
  }
533
838
  }
534
839
  }
840
+
535
841
  return (0, _util.shadow)(this, 'documentInfo', docInfo);
536
- },
537
- get fingerprint() {
538
- var xref = this.xref,
539
- hash,
540
- fileID = '';
541
- var idArray = xref.trailer.get('ID');
842
+ }
843
+ }, {
844
+ key: "fingerprint",
845
+ get: function get() {
846
+ var hash;
847
+ var idArray = this.xref.trailer.get('ID');
848
+
542
849
  if (Array.isArray(idArray) && idArray[0] && (0, _util.isString)(idArray[0]) && idArray[0] !== EMPTY_FINGERPRINT) {
543
850
  hash = (0, _util.stringToBytes)(idArray[0]);
544
851
  } else {
545
- if (this.stream.ensureRange) {
546
- this.stream.ensureRange(0, Math.min(FINGERPRINT_FIRST_BYTES, this.stream.end));
547
- }
548
- hash = (0, _crypto.calculateMD5)(this.stream.bytes.subarray(0, FINGERPRINT_FIRST_BYTES), 0, FINGERPRINT_FIRST_BYTES);
852
+ hash = (0, _crypto.calculateMD5)(this.stream.getByteRange(0, FINGERPRINT_FIRST_BYTES), 0, FINGERPRINT_FIRST_BYTES);
549
853
  }
550
- for (var i = 0, n = hash.length; i < n; i++) {
854
+
855
+ var fingerprintBuf = [];
856
+
857
+ for (var i = 0, ii = hash.length; i < ii; i++) {
551
858
  var hex = hash[i].toString(16);
552
- fileID += hex.length === 1 ? '0' + hex : hex;
859
+ fingerprintBuf.push(hex.padStart(2, '0'));
553
860
  }
554
- return (0, _util.shadow)(this, 'fingerprint', fileID);
555
- },
556
- getPage: function PDFDocument_getPage(pageIndex) {
557
- return this.catalog.getPage(pageIndex);
558
- },
559
- cleanup: function PDFDocument_cleanup() {
560
- return this.catalog.cleanup();
861
+
862
+ return (0, _util.shadow)(this, 'fingerprint', fingerprintBuf.join(''));
561
863
  }
562
- };
864
+ }]);
865
+
563
866
  return PDFDocument;
564
867
  }();
565
- exports.Page = Page;
868
+
566
869
  exports.PDFDocument = PDFDocument;