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.
- package/CODE_OF_CONDUCT.md +15 -0
- package/bower.json +1 -1
- package/build/pdf.js +21618 -14369
- package/build/pdf.js.map +1 -1
- package/build/pdf.min.js +1 -1
- package/build/pdf.worker.js +22758 -11399
- package/build/pdf.worker.js.map +1 -1
- package/build/pdf.worker.min.js +1 -1
- package/image_decoders/pdf.image_decoders.js +11500 -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 +767 -258
- 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 +428 -157
- package/lib/core/cmap.js +326 -87
- package/lib/core/colorspace.js +874 -594
- package/lib/core/core_utils.js +173 -0
- package/lib/core/crypto.js +290 -45
- package/lib/core/document.js +575 -272
- package/lib/core/encodings.js +19 -10
- package/lib/core/evaluator.js +1032 -351
- package/lib/core/font_renderer.js +331 -97
- package/lib/core/fonts.js +813 -196
- package/lib/core/function.js +253 -27
- package/lib/core/glyphlist.js +5 -3
- package/lib/core/image.js +169 -62
- package/lib/core/image_utils.js +111 -0
- package/lib/core/jbig2.js +502 -72
- package/lib/core/jbig2_stream.js +19 -8
- package/lib/core/jpeg_stream.js +38 -13
- package/lib/core/jpg.js +293 -52
- package/lib/core/jpx.js +419 -12
- 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 +1368 -500
- package/lib/core/operator_list.js +159 -43
- package/lib/core/parser.js +544 -199
- package/lib/core/pattern.js +170 -21
- package/lib/core/pdf_manager.js +324 -134
- package/lib/core/primitives.js +169 -61
- package/lib/core/ps_parser.js +134 -45
- package/lib/core/standard_fonts.js +17 -17
- package/lib/core/stream.js +327 -34
- package/lib/core/type1_parser.js +148 -8
- package/lib/core/unicode.js +32 -5
- package/lib/core/worker.js +215 -229
- package/lib/core/worker_stream.js +277 -0
- package/lib/display/annotation_layer.js +618 -192
- package/lib/display/api.js +1798 -882
- package/lib/display/api_compatibility.js +5 -10
- package/lib/display/canvas.js +366 -45
- package/lib/display/content_disposition.js +71 -24
- package/lib/display/display_utils.js +777 -0
- package/lib/display/fetch_stream.js +205 -87
- 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 +38 -19
- package/lib/display/node_stream.js +367 -175
- package/lib/display/pattern_helper.js +103 -36
- package/lib/display/svg.js +1232 -519
- package/lib/display/text_layer.js +208 -75
- 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 +35 -14
- package/lib/pdf.worker.js +5 -3
- package/lib/shared/compatibility.js +170 -572
- package/lib/shared/global_scope.js +2 -2
- package/lib/shared/is_node.js +4 -4
- package/lib/shared/message_handler.js +216 -163
- package/lib/shared/streams_polyfill.js +21 -17
- package/lib/shared/util.js +495 -385
- package/lib/test/unit/annotation_spec.js +1464 -401
- package/lib/test/unit/api_spec.js +718 -361
- 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 +9 -10
- 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 +59 -20
- package/lib/test/unit/fetch_stream_spec.js +111 -0
- package/lib/test/unit/function_spec.js +17 -5
- package/lib/test/unit/jasmine-boot.js +33 -20
- package/lib/test/unit/message_handler_spec.js +30 -13
- 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 +22 -55
- package/lib/test/unit/network_utils_spec.js +105 -14
- package/lib/test/unit/node_stream_spec.js +58 -34
- 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 +55 -22
- 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 +9 -7
- package/lib/test/unit/ui_utils_spec.js +236 -36
- 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 +1252 -609
- package/lib/web/app_options.js +103 -65
- package/lib/web/base_viewer.js +522 -242
- package/lib/web/chromecom.js +259 -117
- package/lib/web/debugger.js +166 -22
- package/lib/web/download_manager.js +31 -12
- package/lib/web/firefox_print_service.js +27 -14
- package/lib/web/firefoxcom.js +318 -78
- 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 +174 -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 +144 -79
- package/lib/web/pdf_outline_viewer.js +124 -47
- package/lib/web/pdf_page_view.js +194 -74
- package/lib/web/pdf_presentation_mode.js +99 -34
- package/lib/web/pdf_print_service.js +59 -13
- package/lib/web/pdf_rendering_queue.js +28 -9
- package/lib/web/pdf_sidebar.js +144 -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 +82 -87
- package/lib/web/preferences.js +284 -91
- package/lib/web/secondary_toolbar.js +132 -59
- package/lib/web/text_layer_builder.js +134 -59
- package/lib/web/toolbar.js +80 -43
- package/lib/web/ui_utils.js +400 -134
- package/lib/web/view_history.js +215 -67
- package/lib/web/viewer_compatibility.js +3 -8
- package/package.json +3 -2
- package/web/pdf_viewer.css +23 -15
- package/web/pdf_viewer.js +3429 -1245
- package/web/pdf_viewer.js.map +1 -1
- package/external/streams/streams-lib.js +0 -3962
- package/lib/display/dom_utils.js +0 -429
- 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) { 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
|
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
|
}
|
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
|
-
|
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;
|
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
|
-
|
150
|
-
|
151
|
-
|
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
|
-
|
160
|
-
|
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
|
-
|
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
|
183
|
+
stream = new _stream2.NullStream();
|
167
184
|
}
|
185
|
+
|
168
186
|
return stream;
|
169
|
-
}
|
170
|
-
|
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
|
-
|
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,
|
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
|
-
|
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
|
251
|
+
return {
|
252
|
+
length: pageOpList.totalLength
|
253
|
+
};
|
231
254
|
}
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
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
|
-
|
243
|
-
|
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
|
312
|
+
return {
|
313
|
+
length: pageOpList.totalLength
|
314
|
+
};
|
248
315
|
});
|
249
316
|
});
|
250
|
-
}
|
251
|
-
|
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
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
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
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
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
|
-
|
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
|
-
|
315
|
-
|
316
|
-
|
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
|
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:
|
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
|
-
|
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) {
|
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
|
-
|
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
|
541
|
+
if (ex instanceof _core_utils.MissingDataException) {
|
390
542
|
throw ex;
|
391
543
|
}
|
392
|
-
|
544
|
+
|
545
|
+
(0, _util.info)('Cannot fetch AcroForm entry; assuming no AcroForms are present');
|
393
546
|
this.acroForm = null;
|
394
547
|
}
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
}
|
402
|
-
|
403
|
-
|
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
|
-
|
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
|
-
|
695
|
+
}
|
696
|
+
}, {
|
697
|
+
key: "startXRef",
|
698
|
+
get: function get() {
|
411
699
|
var stream = this.stream;
|
412
700
|
var startXRef = 0;
|
413
|
-
|
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 -
|
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
|
-
|
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() {
|
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
|
-
|
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
|
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
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
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
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
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
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
859
|
+
fingerprintBuf.push(hex.padStart(2, '0'));
|
553
860
|
}
|
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();
|
861
|
+
|
862
|
+
return (0, _util.shadow)(this, 'fingerprint', fingerprintBuf.join(''));
|
561
863
|
}
|
562
|
-
};
|
864
|
+
}]);
|
865
|
+
|
563
866
|
return PDFDocument;
|
564
867
|
}();
|
565
|
-
|
868
|
+
|
566
869
|
exports.PDFDocument = PDFDocument;
|