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