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