pdfjs-dist 2.0.943 → 2.4.456
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/README.md +4 -0
- package/bower.json +1 -1
- package/build/pdf.js +8286 -14230
- package/build/pdf.js.map +1 -1
- package/build/pdf.min.js +22 -1
- package/build/pdf.worker.entry.js +5 -3
- package/build/pdf.worker.js +25500 -26628
- package/build/pdf.worker.js.map +1 -1
- package/build/pdf.worker.min.js +22 -1
- package/es5/build/pdf.js +25473 -0
- package/es5/build/pdf.js.map +1 -0
- package/{lib/shared/global_scope.js → es5/build/pdf.worker.entry.js} +5 -10
- package/es5/build/pdf.worker.js +57878 -0
- package/es5/build/pdf.worker.js.map +1 -0
- package/es5/web/images/annotation-check.svg +11 -0
- package/es5/web/images/annotation-comment.svg +16 -0
- package/es5/web/images/annotation-help.svg +26 -0
- package/es5/web/images/annotation-insert.svg +10 -0
- package/es5/web/images/annotation-key.svg +11 -0
- package/es5/web/images/annotation-newparagraph.svg +11 -0
- package/es5/web/images/annotation-noicon.svg +7 -0
- package/es5/web/images/annotation-note.svg +42 -0
- package/es5/web/images/annotation-paragraph.svg +16 -0
- package/es5/web/images/loading-icon.gif +0 -0
- package/es5/web/images/shadow.png +0 -0
- package/es5/web/images/texture.png +0 -0
- package/es5/web/pdf_viewer.css +407 -0
- package/es5/web/pdf_viewer.js +7757 -0
- package/es5/web/pdf_viewer.js.map +1 -0
- package/image_decoders/pdf.image_decoders.js +2887 -4094
- package/image_decoders/pdf.image_decoders.js.map +1 -1
- package/image_decoders/pdf.image_decoders.min.js +22 -1
- package/lib/README.md +7 -0
- package/lib/core/annotation.js +855 -778
- package/lib/core/arithmetic_decoder.js +325 -311
- package/lib/core/bidi.js +117 -50
- package/lib/core/ccitt.js +251 -89
- package/lib/core/ccitt_stream.js +26 -16
- package/lib/core/cff_parser.js +525 -197
- package/lib/core/charsets.js +6 -5
- package/lib/core/chunked_stream.js +541 -406
- package/lib/core/cmap.js +368 -253
- package/lib/core/colorspace.js +781 -800
- package/lib/core/core_utils.js +152 -0
- package/lib/core/crypto.js +609 -422
- package/lib/core/document.js +649 -481
- package/lib/core/encodings.js +33 -24
- package/lib/core/evaluator.js +1471 -736
- package/lib/core/font_renderer.js +289 -149
- package/lib/core/fonts.js +1067 -413
- package/lib/core/function.js +517 -287
- package/lib/core/glyphlist.js +4529 -4527
- package/lib/core/image.js +232 -114
- package/lib/core/image_utils.js +94 -0
- package/lib/core/jbig2.js +711 -342
- package/lib/core/jbig2_stream.js +31 -19
- package/lib/core/jpeg_stream.js +151 -26
- package/lib/core/jpg.js +433 -181
- package/lib/core/jpx.js +551 -143
- package/lib/core/jpx_stream.js +40 -28
- package/lib/core/metrics.js +2931 -2931
- package/lib/core/murmurhash3.js +104 -97
- package/lib/core/obj.js +1561 -1053
- package/lib/core/operator_list.js +192 -64
- package/lib/core/parser.js +1162 -864
- package/lib/core/pattern.js +224 -75
- package/lib/core/pdf_manager.js +154 -285
- package/lib/core/primitives.js +145 -69
- package/lib/core/ps_parser.js +212 -162
- package/lib/core/standard_fonts.js +245 -244
- package/lib/core/stream.js +353 -81
- package/lib/core/type1_parser.js +218 -68
- package/lib/core/unicode.js +1682 -1655
- package/lib/core/worker.js +233 -302
- package/lib/core/worker_stream.js +168 -0
- package/lib/display/annotation_layer.js +808 -862
- package/lib/display/api.js +1778 -1462
- package/lib/display/api_compatibility.js +14 -9
- package/lib/display/canvas.js +463 -140
- package/lib/display/content_disposition.js +86 -58
- package/lib/display/display_utils.js +524 -0
- package/lib/display/fetch_stream.js +202 -274
- package/lib/display/font_loader.js +311 -333
- package/lib/display/metadata.js +98 -88
- package/lib/display/network.js +343 -347
- package/lib/display/network_utils.js +46 -26
- package/lib/display/node_stream.js +326 -404
- package/lib/display/pattern_helper.js +168 -69
- package/lib/display/svg.js +1296 -885
- package/lib/display/text_layer.js +229 -103
- package/lib/display/transport_stream.js +290 -250
- package/lib/display/webgl.js +116 -83
- package/lib/display/worker_options.js +6 -5
- package/lib/display/xml_parser.js +358 -337
- package/lib/examples/node/domstubs.js +95 -39
- package/lib/pdf.js +49 -31
- package/lib/pdf.worker.js +7 -5
- package/lib/shared/compatibility.js +3 -145
- package/lib/shared/is_node.js +8 -7
- package/lib/shared/message_handler.js +367 -314
- package/lib/shared/util.js +421 -415
- package/lib/test/unit/annotation_spec.js +1570 -690
- package/lib/test/unit/api_spec.js +855 -493
- package/lib/test/unit/bidi_spec.js +12 -12
- package/lib/test/unit/cff_parser_spec.js +88 -61
- package/lib/test/unit/clitests_helper.js +9 -12
- package/lib/test/unit/cmap_spec.js +140 -88
- package/lib/test/unit/colorspace_spec.js +204 -152
- package/lib/test/unit/core_utils_spec.js +211 -0
- package/lib/test/unit/crypto_spec.js +194 -182
- package/lib/test/unit/custom_spec.js +50 -64
- package/lib/test/unit/display_svg_spec.js +53 -38
- package/lib/test/unit/display_utils_spec.js +263 -0
- package/lib/test/unit/document_spec.js +17 -22
- package/lib/test/unit/encodings_spec.js +15 -57
- package/lib/test/unit/evaluator_spec.js +90 -83
- package/lib/test/unit/fetch_stream_spec.js +111 -0
- package/lib/test/unit/function_spec.js +219 -205
- package/lib/test/unit/jasmine-boot.js +68 -39
- package/lib/test/unit/message_handler_spec.js +187 -160
- package/lib/test/unit/metadata_spec.js +87 -34
- package/lib/test/unit/murmurhash3_spec.js +13 -13
- package/lib/test/unit/network_spec.js +26 -59
- package/lib/test/unit/network_utils_spec.js +187 -121
- package/lib/test/unit/node_stream_spec.js +98 -90
- package/lib/test/unit/parser_spec.js +173 -131
- package/lib/test/unit/pdf_find_controller_spec.js +148 -67
- package/lib/test/unit/pdf_find_utils_spec.js +35 -34
- package/lib/test/unit/pdf_history_spec.js +45 -33
- package/lib/test/unit/primitives_spec.js +161 -126
- package/lib/test/unit/stream_spec.js +22 -15
- package/lib/test/unit/test_utils.js +149 -98
- package/lib/test/unit/testreporter.js +36 -18
- package/lib/test/unit/type1_parser_spec.js +46 -44
- package/lib/test/unit/ui_utils_spec.js +388 -372
- package/lib/test/unit/unicode_spec.js +49 -46
- package/lib/test/unit/util_spec.js +144 -248
- package/lib/web/annotation_layer_builder.js +75 -95
- package/lib/web/app.js +1538 -1147
- package/lib/web/app_options.js +116 -104
- package/lib/web/base_viewer.js +950 -775
- package/lib/web/chromecom.js +217 -225
- package/lib/web/debugger.js +236 -148
- package/lib/web/download_manager.js +50 -50
- package/lib/web/firefox_print_service.js +51 -33
- package/lib/web/firefoxcom.js +225 -352
- package/lib/web/genericcom.js +30 -93
- package/lib/web/genericl10n.js +26 -143
- package/lib/web/grab_to_pan.js +57 -33
- package/lib/web/interfaces.js +105 -232
- package/lib/web/overlay_manager.js +73 -227
- package/lib/web/password_prompt.js +44 -62
- package/lib/web/pdf_attachment_viewer.js +118 -123
- package/lib/web/pdf_cursor_tools.js +89 -93
- package/lib/web/pdf_document_properties.js +242 -281
- package/lib/web/pdf_find_bar.js +157 -163
- package/lib/web/pdf_find_controller.js +598 -454
- package/lib/web/pdf_find_utils.js +32 -16
- package/lib/web/pdf_history.js +481 -355
- package/lib/web/pdf_link_service.js +355 -323
- package/lib/web/pdf_outline_viewer.js +167 -152
- package/lib/web/pdf_page_view.js +511 -457
- package/lib/web/pdf_presentation_mode.js +347 -335
- package/lib/web/pdf_print_service.js +133 -103
- package/lib/web/pdf_rendering_queue.js +98 -100
- package/lib/web/pdf_sidebar.js +323 -299
- package/lib/web/pdf_sidebar_resizer.js +107 -108
- package/lib/web/pdf_single_page_viewer.js +94 -146
- package/lib/web/pdf_thumbnail_view.js +319 -269
- package/lib/web/pdf_thumbnail_viewer.js +219 -199
- package/lib/web/pdf_viewer.component.js +111 -32
- package/lib/web/pdf_viewer.js +61 -101
- package/lib/web/preferences.js +87 -272
- package/lib/web/secondary_toolbar.js +207 -220
- package/lib/web/text_layer_builder.js +322 -322
- package/lib/web/toolbar.js +227 -180
- package/lib/web/ui_utils.js +476 -421
- package/lib/web/view_history.js +59 -208
- package/lib/web/viewer_compatibility.js +9 -6
- package/package.json +2 -9
- package/web/pdf_viewer.css +36 -22
- package/web/pdf_viewer.js +4407 -4516
- package/web/pdf_viewer.js.map +1 -1
- package/webpack.js +14 -5
- package/external/streams/streams-lib.js +0 -3962
- package/external/url/url-lib.js +0 -627
- package/lib/display/dom_utils.js +0 -441
- package/lib/shared/streams_polyfill.js +0 -39
- package/lib/shared/url_polyfill.js +0 -50
- package/lib/test/unit/dom_utils_spec.js +0 -89
- package/lib/web/dom_events.js +0 -140
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 2020 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,51 +19,53 @@
|
|
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.js");
|
30
30
|
|
31
|
-
var
|
31
|
+
var _obj = require("./obj.js");
|
32
32
|
|
33
|
-
var
|
33
|
+
var _primitives = require("./primitives.js");
|
34
34
|
|
35
|
-
var
|
35
|
+
var _core_utils = require("./core_utils.js");
|
36
36
|
|
37
|
-
var _stream = require(
|
37
|
+
var _stream = require("./stream.js");
|
38
38
|
|
39
|
-
var _annotation = require(
|
39
|
+
var _annotation = require("./annotation.js");
|
40
40
|
|
41
|
-
var _crypto = require(
|
41
|
+
var _crypto = require("./crypto.js");
|
42
42
|
|
43
|
-
var _parser = require(
|
43
|
+
var _parser = require("./parser.js");
|
44
44
|
|
45
|
-
var _operator_list = require(
|
45
|
+
var _operator_list = require("./operator_list.js");
|
46
46
|
|
47
|
-
var _evaluator = require(
|
47
|
+
var _evaluator = require("./evaluator.js");
|
48
48
|
|
49
|
-
var _function = require(
|
49
|
+
var _function = require("./function.js");
|
50
50
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
function Page(_ref) {
|
58
|
-
var pdfManager = _ref.pdfManager,
|
59
|
-
xref = _ref.xref,
|
60
|
-
pageIndex = _ref.pageIndex,
|
61
|
-
pageDict = _ref.pageDict,
|
62
|
-
ref = _ref.ref,
|
63
|
-
fontCache = _ref.fontCache,
|
64
|
-
builtInCMapCache = _ref.builtInCMapCache,
|
65
|
-
pdfFunctionFactory = _ref.pdfFunctionFactory;
|
51
|
+
const DEFAULT_USER_UNIT = 1.0;
|
52
|
+
const LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
|
53
|
+
|
54
|
+
function isAnnotationRenderable(annotation, intent) {
|
55
|
+
return intent === "display" && annotation.viewable || intent === "print" && annotation.printable;
|
56
|
+
}
|
66
57
|
|
58
|
+
class Page {
|
59
|
+
constructor({
|
60
|
+
pdfManager,
|
61
|
+
xref,
|
62
|
+
pageIndex,
|
63
|
+
pageDict,
|
64
|
+
ref,
|
65
|
+
fontCache,
|
66
|
+
builtInCMapCache,
|
67
|
+
pdfFunctionFactory
|
68
|
+
}) {
|
67
69
|
this.pdfManager = pdfManager;
|
68
70
|
this.pageIndex = pageIndex;
|
69
71
|
this.pageDict = pageDict;
|
@@ -74,124 +76,231 @@ var Page = function PageClosure() {
|
|
74
76
|
this.pdfFunctionFactory = pdfFunctionFactory;
|
75
77
|
this.evaluatorOptions = pdfManager.evaluatorOptions;
|
76
78
|
this.resourcesPromise = null;
|
77
|
-
|
78
|
-
|
79
|
+
const idCounters = {
|
80
|
+
obj: 0
|
81
|
+
};
|
79
82
|
this.idFactory = {
|
80
|
-
createObjId
|
81
|
-
return
|
83
|
+
createObjId() {
|
84
|
+
return `p${pageIndex}_${++idCounters.obj}`;
|
85
|
+
},
|
86
|
+
|
87
|
+
getDocId() {
|
88
|
+
return `g_${pdfManager.docId}`;
|
82
89
|
}
|
90
|
+
|
83
91
|
};
|
84
92
|
}
|
85
|
-
Page.prototype = {
|
86
|
-
_getInheritableProperty: function _getInheritableProperty(key) {
|
87
|
-
var getArray = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
88
93
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
94
|
+
_getInheritableProperty(key, getArray = false) {
|
95
|
+
const value = (0, _core_utils.getInheritableProperty)({
|
96
|
+
dict: this.pageDict,
|
97
|
+
key,
|
98
|
+
getArray,
|
99
|
+
stopWhenFound: false
|
100
|
+
});
|
101
|
+
|
102
|
+
if (!Array.isArray(value)) {
|
103
|
+
return value;
|
104
|
+
}
|
105
|
+
|
106
|
+
if (value.length === 1 || !(0, _primitives.isDict)(value[0])) {
|
107
|
+
return value[0];
|
108
|
+
}
|
109
|
+
|
110
|
+
return _primitives.Dict.merge(this.xref, value);
|
111
|
+
}
|
112
|
+
|
113
|
+
get content() {
|
114
|
+
return this.pageDict.get("Contents");
|
115
|
+
}
|
116
|
+
|
117
|
+
get resources() {
|
118
|
+
return (0, _util.shadow)(this, "resources", this._getInheritableProperty("Resources") || _primitives.Dict.empty);
|
119
|
+
}
|
120
|
+
|
121
|
+
_getBoundingBox(name) {
|
122
|
+
const box = this._getInheritableProperty(name, true);
|
123
|
+
|
124
|
+
if (Array.isArray(box) && box.length === 4) {
|
125
|
+
if (box[2] - box[0] !== 0 && box[3] - box[1] !== 0) {
|
126
|
+
return box;
|
121
127
|
}
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
+
|
129
|
+
(0, _util.warn)(`Empty /${name} entry.`);
|
130
|
+
}
|
131
|
+
|
132
|
+
return null;
|
133
|
+
}
|
134
|
+
|
135
|
+
get mediaBox() {
|
136
|
+
return (0, _util.shadow)(this, "mediaBox", this._getBoundingBox("MediaBox") || LETTER_SIZE_MEDIABOX);
|
137
|
+
}
|
138
|
+
|
139
|
+
get cropBox() {
|
140
|
+
return (0, _util.shadow)(this, "cropBox", this._getBoundingBox("CropBox") || this.mediaBox);
|
141
|
+
}
|
142
|
+
|
143
|
+
get userUnit() {
|
144
|
+
let obj = this.pageDict.get("UserUnit");
|
145
|
+
|
146
|
+
if (!(0, _util.isNum)(obj) || obj <= 0) {
|
147
|
+
obj = DEFAULT_USER_UNIT;
|
148
|
+
}
|
149
|
+
|
150
|
+
return (0, _util.shadow)(this, "userUnit", obj);
|
151
|
+
}
|
152
|
+
|
153
|
+
get view() {
|
154
|
+
const {
|
155
|
+
cropBox,
|
156
|
+
mediaBox
|
157
|
+
} = this;
|
158
|
+
let view;
|
159
|
+
|
160
|
+
if (cropBox === mediaBox || (0, _util.isArrayEqual)(cropBox, mediaBox)) {
|
161
|
+
view = mediaBox;
|
162
|
+
} else {
|
163
|
+
const box = _util.Util.intersect(cropBox, mediaBox);
|
164
|
+
|
165
|
+
if (box && box[2] - box[0] !== 0 && box[3] - box[1] !== 0) {
|
166
|
+
view = box;
|
167
|
+
} else {
|
168
|
+
(0, _util.warn)("Empty /CropBox and /MediaBox intersection.");
|
128
169
|
}
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
170
|
+
}
|
171
|
+
|
172
|
+
return (0, _util.shadow)(this, "view", view || mediaBox);
|
173
|
+
}
|
174
|
+
|
175
|
+
get rotate() {
|
176
|
+
let rotate = this._getInheritableProperty("Rotate") || 0;
|
177
|
+
|
178
|
+
if (rotate % 90 !== 0) {
|
179
|
+
rotate = 0;
|
180
|
+
} else if (rotate >= 360) {
|
181
|
+
rotate = rotate % 360;
|
182
|
+
} else if (rotate < 0) {
|
183
|
+
rotate = (rotate % 360 + 360) % 360;
|
184
|
+
}
|
185
|
+
|
186
|
+
return (0, _util.shadow)(this, "rotate", rotate);
|
187
|
+
}
|
188
|
+
|
189
|
+
getContentStream() {
|
190
|
+
const content = this.content;
|
191
|
+
let stream;
|
192
|
+
|
193
|
+
if (Array.isArray(content)) {
|
194
|
+
const xref = this.xref;
|
195
|
+
const streams = [];
|
196
|
+
|
197
|
+
for (const stream of content) {
|
198
|
+
streams.push(xref.fetchIfRef(stream));
|
136
199
|
}
|
137
|
-
|
138
|
-
|
139
|
-
},
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
200
|
+
|
201
|
+
stream = new _stream.StreamsSequenceStream(streams);
|
202
|
+
} else if ((0, _primitives.isStream)(content)) {
|
203
|
+
stream = content;
|
204
|
+
} else {
|
205
|
+
stream = new _stream.NullStream();
|
206
|
+
}
|
207
|
+
|
208
|
+
return stream;
|
209
|
+
}
|
210
|
+
|
211
|
+
loadResources(keys) {
|
212
|
+
if (!this.resourcesPromise) {
|
213
|
+
this.resourcesPromise = this.pdfManager.ensure(this, "resources");
|
214
|
+
}
|
215
|
+
|
216
|
+
return this.resourcesPromise.then(() => {
|
217
|
+
const objectLoader = new _obj.ObjectLoader(this.resources, keys, this.xref);
|
218
|
+
return objectLoader.load();
|
219
|
+
});
|
220
|
+
}
|
221
|
+
|
222
|
+
getOperatorList({
|
223
|
+
handler,
|
224
|
+
sink,
|
225
|
+
task,
|
226
|
+
intent,
|
227
|
+
renderInteractiveForms
|
228
|
+
}) {
|
229
|
+
const contentStreamPromise = this.pdfManager.ensure(this, "getContentStream");
|
230
|
+
const resourcesPromise = this.loadResources(["ExtGState", "ColorSpace", "Pattern", "Shading", "XObject", "Font"]);
|
231
|
+
const partialEvaluator = new _evaluator.PartialEvaluator({
|
232
|
+
xref: this.xref,
|
233
|
+
handler,
|
234
|
+
pageIndex: this.pageIndex,
|
235
|
+
idFactory: this.idFactory,
|
236
|
+
fontCache: this.fontCache,
|
237
|
+
builtInCMapCache: this.builtInCMapCache,
|
238
|
+
options: this.evaluatorOptions,
|
239
|
+
pdfFunctionFactory: this.pdfFunctionFactory
|
240
|
+
});
|
241
|
+
const dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
|
242
|
+
const pageListPromise = dataPromises.then(([contentStream]) => {
|
243
|
+
const opList = new _operator_list.OperatorList(intent, sink, this.pageIndex);
|
244
|
+
handler.send("StartRenderPage", {
|
245
|
+
transparency: partialEvaluator.hasBlendModes(this.resources),
|
246
|
+
pageIndex: this.pageIndex,
|
247
|
+
intent
|
248
|
+
});
|
249
|
+
return partialEvaluator.getOperatorList({
|
250
|
+
stream: contentStream,
|
251
|
+
task,
|
252
|
+
resources: this.resources,
|
253
|
+
operatorList: opList
|
254
|
+
}).then(function () {
|
255
|
+
return opList;
|
256
|
+
});
|
257
|
+
});
|
258
|
+
return Promise.all([pageListPromise, this._parsedAnnotations]).then(function ([pageOpList, annotations]) {
|
259
|
+
if (annotations.length === 0) {
|
260
|
+
pageOpList.flush(true);
|
261
|
+
return {
|
262
|
+
length: pageOpList.totalLength
|
263
|
+
};
|
148
264
|
}
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
var xref = this.xref;
|
156
|
-
var i,
|
157
|
-
n = content.length;
|
158
|
-
var streams = [];
|
159
|
-
for (i = 0; i < n; ++i) {
|
160
|
-
streams.push(xref.fetchIfRef(content[i]));
|
265
|
+
|
266
|
+
const opListPromises = [];
|
267
|
+
|
268
|
+
for (const annotation of annotations) {
|
269
|
+
if (isAnnotationRenderable(annotation, intent)) {
|
270
|
+
opListPromises.push(annotation.getOperatorList(partialEvaluator, task, renderInteractiveForms));
|
161
271
|
}
|
162
|
-
stream = new _stream.StreamsSequenceStream(streams);
|
163
|
-
} else if ((0, _primitives.isStream)(content)) {
|
164
|
-
stream = content;
|
165
|
-
} else {
|
166
|
-
stream = new _stream.NullStream();
|
167
272
|
}
|
168
|
-
return stream;
|
169
|
-
},
|
170
|
-
loadResources: function Page_loadResources(keys) {
|
171
|
-
var _this = this;
|
172
273
|
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
274
|
+
return Promise.all(opListPromises).then(function (opLists) {
|
275
|
+
pageOpList.addOp(_util.OPS.beginAnnotations, []);
|
276
|
+
|
277
|
+
for (const opList of opLists) {
|
278
|
+
pageOpList.addOpList(opList);
|
279
|
+
}
|
280
|
+
|
281
|
+
pageOpList.addOp(_util.OPS.endAnnotations, []);
|
282
|
+
pageOpList.flush(true);
|
283
|
+
return {
|
284
|
+
length: pageOpList.totalLength
|
285
|
+
};
|
179
286
|
});
|
180
|
-
}
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
287
|
+
});
|
288
|
+
}
|
289
|
+
|
290
|
+
extractTextContent({
|
291
|
+
handler,
|
292
|
+
task,
|
293
|
+
normalizeWhitespace,
|
294
|
+
sink,
|
295
|
+
combineTextItems
|
296
|
+
}) {
|
297
|
+
const contentStreamPromise = this.pdfManager.ensure(this, "getContentStream");
|
298
|
+
const resourcesPromise = this.loadResources(["ExtGState", "XObject", "Font"]);
|
299
|
+
const dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
|
300
|
+
return dataPromises.then(([contentStream]) => {
|
301
|
+
const partialEvaluator = new _evaluator.PartialEvaluator({
|
193
302
|
xref: this.xref,
|
194
|
-
handler
|
303
|
+
handler,
|
195
304
|
pageIndex: this.pageIndex,
|
196
305
|
idFactory: this.idFactory,
|
197
306
|
fontCache: this.fontCache,
|
@@ -199,394 +308,453 @@ var Page = function PageClosure() {
|
|
199
308
|
options: this.evaluatorOptions,
|
200
309
|
pdfFunctionFactory: this.pdfFunctionFactory
|
201
310
|
});
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
transparency: partialEvaluator.hasBlendModes(_this2.resources),
|
210
|
-
pageIndex: _this2.pageIndex,
|
211
|
-
intent: intent
|
212
|
-
});
|
213
|
-
return partialEvaluator.getOperatorList({
|
214
|
-
stream: contentStream,
|
215
|
-
task: task,
|
216
|
-
resources: _this2.resources,
|
217
|
-
operatorList: opList
|
218
|
-
}).then(function () {
|
219
|
-
return opList;
|
220
|
-
});
|
311
|
+
return partialEvaluator.getTextContent({
|
312
|
+
stream: contentStream,
|
313
|
+
task,
|
314
|
+
resources: this.resources,
|
315
|
+
normalizeWhitespace,
|
316
|
+
combineTextItems,
|
317
|
+
sink
|
221
318
|
});
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
ii,
|
233
|
-
opListPromises = [];
|
234
|
-
for (i = 0, ii = annotations.length; i < ii; i++) {
|
235
|
-
if (isAnnotationRenderable(annotations[i], intent)) {
|
236
|
-
opListPromises.push(annotations[i].getOperatorList(partialEvaluator, task, renderInteractiveForms));
|
237
|
-
}
|
238
|
-
}
|
239
|
-
return Promise.all(opListPromises).then(function (opLists) {
|
240
|
-
pageOpList.addOp(_util.OPS.beginAnnotations, []);
|
241
|
-
for (i = 0, ii = opLists.length; i < ii; i++) {
|
242
|
-
pageOpList.addOpList(opLists[i]);
|
243
|
-
}
|
244
|
-
pageOpList.addOp(_util.OPS.endAnnotations, []);
|
245
|
-
pageOpList.flush(true);
|
246
|
-
return pageOpList;
|
247
|
-
});
|
248
|
-
});
|
249
|
-
},
|
250
|
-
extractTextContent: function extractTextContent(_ref7) {
|
251
|
-
var _this3 = this;
|
252
|
-
|
253
|
-
var handler = _ref7.handler,
|
254
|
-
task = _ref7.task,
|
255
|
-
normalizeWhitespace = _ref7.normalizeWhitespace,
|
256
|
-
sink = _ref7.sink,
|
257
|
-
combineTextItems = _ref7.combineTextItems;
|
258
|
-
|
259
|
-
var contentStreamPromise = this.pdfManager.ensure(this, 'getContentStream');
|
260
|
-
var resourcesPromise = this.loadResources(['ExtGState', 'XObject', 'Font']);
|
261
|
-
var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
|
262
|
-
return dataPromises.then(function (_ref8) {
|
263
|
-
var _ref9 = _slicedToArray(_ref8, 1),
|
264
|
-
contentStream = _ref9[0];
|
265
|
-
|
266
|
-
var partialEvaluator = new _evaluator.PartialEvaluator({
|
267
|
-
pdfManager: _this3.pdfManager,
|
268
|
-
xref: _this3.xref,
|
269
|
-
handler: handler,
|
270
|
-
pageIndex: _this3.pageIndex,
|
271
|
-
idFactory: _this3.idFactory,
|
272
|
-
fontCache: _this3.fontCache,
|
273
|
-
builtInCMapCache: _this3.builtInCMapCache,
|
274
|
-
options: _this3.evaluatorOptions,
|
275
|
-
pdfFunctionFactory: _this3.pdfFunctionFactory
|
276
|
-
});
|
277
|
-
return partialEvaluator.getTextContent({
|
278
|
-
stream: contentStream,
|
279
|
-
task: task,
|
280
|
-
resources: _this3.resources,
|
281
|
-
normalizeWhitespace: normalizeWhitespace,
|
282
|
-
combineTextItems: combineTextItems,
|
283
|
-
sink: sink
|
284
|
-
});
|
285
|
-
});
|
286
|
-
},
|
287
|
-
getAnnotationsData: function getAnnotationsData(intent) {
|
288
|
-
return this._parsedAnnotations.then(function (annotations) {
|
289
|
-
var annotationsData = [];
|
290
|
-
for (var i = 0, ii = annotations.length; i < ii; i++) {
|
291
|
-
if (!intent || isAnnotationRenderable(annotations[i], intent)) {
|
292
|
-
annotationsData.push(annotations[i].data);
|
293
|
-
}
|
294
|
-
}
|
295
|
-
return annotationsData;
|
296
|
-
});
|
297
|
-
},
|
298
|
-
|
299
|
-
get annotations() {
|
300
|
-
return (0, _util.shadow)(this, 'annotations', this._getInheritableProperty('Annots') || []);
|
301
|
-
},
|
302
|
-
get _parsedAnnotations() {
|
303
|
-
var _this4 = this;
|
304
|
-
|
305
|
-
var parsedAnnotations = this.pdfManager.ensure(this, 'annotations').then(function () {
|
306
|
-
var annotationRefs = _this4.annotations;
|
307
|
-
var annotationPromises = [];
|
308
|
-
for (var i = 0, ii = annotationRefs.length; i < ii; i++) {
|
309
|
-
annotationPromises.push(_annotation.AnnotationFactory.create(_this4.xref, annotationRefs[i], _this4.pdfManager, _this4.idFactory));
|
319
|
+
});
|
320
|
+
}
|
321
|
+
|
322
|
+
getAnnotationsData(intent) {
|
323
|
+
return this._parsedAnnotations.then(function (annotations) {
|
324
|
+
const annotationsData = [];
|
325
|
+
|
326
|
+
for (let i = 0, ii = annotations.length; i < ii; i++) {
|
327
|
+
if (!intent || isAnnotationRenderable(annotations[i], intent)) {
|
328
|
+
annotationsData.push(annotations[i].data);
|
310
329
|
}
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
330
|
+
}
|
331
|
+
|
332
|
+
return annotationsData;
|
333
|
+
});
|
334
|
+
}
|
335
|
+
|
336
|
+
get annotations() {
|
337
|
+
return (0, _util.shadow)(this, "annotations", this._getInheritableProperty("Annots") || []);
|
338
|
+
}
|
339
|
+
|
340
|
+
get _parsedAnnotations() {
|
341
|
+
const parsedAnnotations = this.pdfManager.ensure(this, "annotations").then(() => {
|
342
|
+
const annotationRefs = this.annotations;
|
343
|
+
const annotationPromises = [];
|
344
|
+
|
345
|
+
for (let i = 0, ii = annotationRefs.length; i < ii; i++) {
|
346
|
+
annotationPromises.push(_annotation.AnnotationFactory.create(this.xref, annotationRefs[i], this.pdfManager, this.idFactory));
|
347
|
+
}
|
348
|
+
|
349
|
+
return Promise.all(annotationPromises).then(function (annotations) {
|
350
|
+
return annotations.filter(function isDefined(annotation) {
|
351
|
+
return !!annotation;
|
318
352
|
});
|
353
|
+
}, function (reason) {
|
354
|
+
(0, _util.warn)(`_parsedAnnotations: "${reason}".`);
|
355
|
+
return [];
|
319
356
|
});
|
320
|
-
|
357
|
+
});
|
358
|
+
return (0, _util.shadow)(this, "_parsedAnnotations", parsedAnnotations);
|
359
|
+
}
|
360
|
+
|
361
|
+
}
|
362
|
+
|
363
|
+
exports.Page = Page;
|
364
|
+
const PDF_HEADER_SIGNATURE = new Uint8Array([0x25, 0x50, 0x44, 0x46, 0x2d]);
|
365
|
+
const STARTXREF_SIGNATURE = new Uint8Array([0x73, 0x74, 0x61, 0x72, 0x74, 0x78, 0x72, 0x65, 0x66]);
|
366
|
+
const ENDOBJ_SIGNATURE = new Uint8Array([0x65, 0x6e, 0x64, 0x6f, 0x62, 0x6a]);
|
367
|
+
const FINGERPRINT_FIRST_BYTES = 1024;
|
368
|
+
const EMPTY_FINGERPRINT = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
|
369
|
+
const PDF_HEADER_VERSION_REGEXP = /^[1-9]\.[0-9]$/;
|
370
|
+
|
371
|
+
function find(stream, signature, limit = 1024, backwards = false) {
|
372
|
+
const signatureLength = signature.length;
|
373
|
+
const scanBytes = stream.peekBytes(limit);
|
374
|
+
const scanLength = scanBytes.length - signatureLength;
|
375
|
+
|
376
|
+
if (scanLength <= 0) {
|
377
|
+
return false;
|
378
|
+
}
|
379
|
+
|
380
|
+
if (backwards) {
|
381
|
+
const signatureEnd = signatureLength - 1;
|
382
|
+
let pos = scanBytes.length - 1;
|
383
|
+
|
384
|
+
while (pos >= signatureEnd) {
|
385
|
+
let j = 0;
|
386
|
+
|
387
|
+
while (j < signatureLength && scanBytes[pos - j] === signature[signatureEnd - j]) {
|
388
|
+
j++;
|
389
|
+
}
|
390
|
+
|
391
|
+
if (j >= signatureLength) {
|
392
|
+
stream.pos += pos - signatureEnd;
|
393
|
+
return true;
|
394
|
+
}
|
395
|
+
|
396
|
+
pos--;
|
321
397
|
}
|
322
|
-
}
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
398
|
+
} else {
|
399
|
+
let pos = 0;
|
400
|
+
|
401
|
+
while (pos <= scanLength) {
|
402
|
+
let j = 0;
|
403
|
+
|
404
|
+
while (j < signatureLength && scanBytes[pos + j] === signature[j]) {
|
405
|
+
j++;
|
406
|
+
}
|
407
|
+
|
408
|
+
if (j >= signatureLength) {
|
409
|
+
stream.pos += pos;
|
410
|
+
return true;
|
411
|
+
}
|
412
|
+
|
413
|
+
pos++;
|
414
|
+
}
|
415
|
+
}
|
416
|
+
|
417
|
+
return false;
|
418
|
+
}
|
419
|
+
|
420
|
+
class PDFDocument {
|
421
|
+
constructor(pdfManager, arg) {
|
422
|
+
let stream;
|
423
|
+
|
330
424
|
if ((0, _primitives.isStream)(arg)) {
|
331
425
|
stream = arg;
|
332
426
|
} else if ((0, _util.isArrayBuffer)(arg)) {
|
333
427
|
stream = new _stream.Stream(arg);
|
334
428
|
} else {
|
335
|
-
throw new Error(
|
429
|
+
throw new Error("PDFDocument: Unknown argument type");
|
336
430
|
}
|
431
|
+
|
337
432
|
if (stream.length <= 0) {
|
338
|
-
throw new
|
433
|
+
throw new _util.InvalidPDFException("The PDF file is empty, i.e. its size is zero bytes.");
|
339
434
|
}
|
435
|
+
|
340
436
|
this.pdfManager = pdfManager;
|
341
437
|
this.stream = stream;
|
342
438
|
this.xref = new _obj.XRef(stream, pdfManager);
|
343
|
-
var evaluatorOptions = pdfManager.evaluatorOptions;
|
344
439
|
this.pdfFunctionFactory = new _function.PDFFunctionFactory({
|
345
440
|
xref: this.xref,
|
346
|
-
isEvalSupported: evaluatorOptions.isEvalSupported
|
441
|
+
isEvalSupported: pdfManager.evaluatorOptions.isEvalSupported
|
347
442
|
});
|
348
443
|
this._pagePromises = [];
|
349
444
|
}
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
445
|
+
|
446
|
+
parse(recoveryMode) {
|
447
|
+
this.setup(recoveryMode);
|
448
|
+
const version = this.catalog.catDict.get("Version");
|
449
|
+
|
450
|
+
if ((0, _primitives.isName)(version)) {
|
451
|
+
this.pdfFormatVersion = version.name;
|
356
452
|
}
|
357
|
-
|
358
|
-
|
453
|
+
|
454
|
+
try {
|
455
|
+
this.acroForm = this.catalog.catDict.get("AcroForm");
|
456
|
+
|
457
|
+
if (this.acroForm) {
|
458
|
+
this.xfa = this.acroForm.get("XFA");
|
459
|
+
const fields = this.acroForm.get("Fields");
|
460
|
+
|
461
|
+
if ((!Array.isArray(fields) || fields.length === 0) && !this.xfa) {
|
462
|
+
this.acroForm = null;
|
463
|
+
}
|
464
|
+
}
|
465
|
+
} catch (ex) {
|
466
|
+
if (ex instanceof _core_utils.MissingDataException) {
|
467
|
+
throw ex;
|
468
|
+
}
|
469
|
+
|
470
|
+
(0, _util.info)("Cannot fetch AcroForm entry; assuming no AcroForms are present");
|
471
|
+
this.acroForm = null;
|
359
472
|
}
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
473
|
+
|
474
|
+
try {
|
475
|
+
const collection = this.catalog.catDict.get("Collection");
|
476
|
+
|
477
|
+
if ((0, _primitives.isDict)(collection) && collection.getKeys().length > 0) {
|
478
|
+
this.collection = collection;
|
479
|
+
}
|
480
|
+
} catch (ex) {
|
481
|
+
if (ex instanceof _core_utils.MissingDataException) {
|
482
|
+
throw ex;
|
483
|
+
}
|
484
|
+
|
485
|
+
(0, _util.info)("Cannot fetch Collection dictionary.");
|
365
486
|
}
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
CreationDate: _util.isString,
|
377
|
-
ModDate: _util.isString,
|
378
|
-
Trapped: _primitives.isName
|
379
|
-
};
|
380
|
-
PDFDocument.prototype = {
|
381
|
-
parse: function PDFDocument_parse(recoveryMode) {
|
382
|
-
this.setup(recoveryMode);
|
383
|
-
var version = this.catalog.catDict.get('Version');
|
384
|
-
if ((0, _primitives.isName)(version)) {
|
385
|
-
this.pdfFormatVersion = version.name;
|
487
|
+
}
|
488
|
+
|
489
|
+
get linearization() {
|
490
|
+
let linearization = null;
|
491
|
+
|
492
|
+
try {
|
493
|
+
linearization = _parser.Linearization.create(this.stream);
|
494
|
+
} catch (err) {
|
495
|
+
if (err instanceof _core_utils.MissingDataException) {
|
496
|
+
throw err;
|
386
497
|
}
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
498
|
+
|
499
|
+
(0, _util.info)(err);
|
500
|
+
}
|
501
|
+
|
502
|
+
return (0, _util.shadow)(this, "linearization", linearization);
|
503
|
+
}
|
504
|
+
|
505
|
+
get startXRef() {
|
506
|
+
const stream = this.stream;
|
507
|
+
let startXRef = 0;
|
508
|
+
|
509
|
+
if (this.linearization) {
|
510
|
+
stream.reset();
|
511
|
+
|
512
|
+
if (find(stream, ENDOBJ_SIGNATURE)) {
|
513
|
+
startXRef = stream.pos + 6 - stream.start;
|
402
514
|
}
|
403
|
-
}
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
515
|
+
} else {
|
516
|
+
const step = 1024;
|
517
|
+
const startXRefLength = STARTXREF_SIGNATURE.length;
|
518
|
+
let found = false,
|
519
|
+
pos = stream.end;
|
520
|
+
|
521
|
+
while (!found && pos > 0) {
|
522
|
+
pos -= step - startXRefLength;
|
523
|
+
|
524
|
+
if (pos < 0) {
|
525
|
+
pos = 0;
|
411
526
|
}
|
412
|
-
|
527
|
+
|
528
|
+
stream.pos = pos;
|
529
|
+
found = find(stream, STARTXREF_SIGNATURE, step, true);
|
413
530
|
}
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
pos = stream.end;
|
429
|
-
while (!found && pos > 0) {
|
430
|
-
pos -= step - 'startxref'.length;
|
431
|
-
if (pos < 0) {
|
432
|
-
pos = 0;
|
433
|
-
}
|
434
|
-
stream.pos = pos;
|
435
|
-
found = find(stream, 'startxref', step, true);
|
531
|
+
|
532
|
+
if (found) {
|
533
|
+
stream.skip(9);
|
534
|
+
let ch;
|
535
|
+
|
536
|
+
do {
|
537
|
+
ch = stream.getByte();
|
538
|
+
} while ((0, _core_utils.isWhiteSpace)(ch));
|
539
|
+
|
540
|
+
let str = "";
|
541
|
+
|
542
|
+
while (ch >= 0x20 && ch <= 0x39) {
|
543
|
+
str += String.fromCharCode(ch);
|
544
|
+
ch = stream.getByte();
|
436
545
|
}
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
} while ((0, _util.isSpace)(ch));
|
443
|
-
var str = '';
|
444
|
-
while (ch >= 0x20 && ch <= 0x39) {
|
445
|
-
str += String.fromCharCode(ch);
|
446
|
-
ch = stream.getByte();
|
447
|
-
}
|
448
|
-
startXRef = parseInt(str, 10);
|
449
|
-
if (isNaN(startXRef)) {
|
450
|
-
startXRef = 0;
|
451
|
-
}
|
546
|
+
|
547
|
+
startXRef = parseInt(str, 10);
|
548
|
+
|
549
|
+
if (isNaN(startXRef)) {
|
550
|
+
startXRef = 0;
|
452
551
|
}
|
453
552
|
}
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
553
|
+
}
|
554
|
+
|
555
|
+
return (0, _util.shadow)(this, "startXRef", startXRef);
|
556
|
+
}
|
557
|
+
|
558
|
+
checkHeader() {
|
559
|
+
const stream = this.stream;
|
560
|
+
stream.reset();
|
561
|
+
|
562
|
+
if (!find(stream, PDF_HEADER_SIGNATURE)) {
|
563
|
+
return;
|
564
|
+
}
|
565
|
+
|
566
|
+
stream.moveStart();
|
567
|
+
const MAX_PDF_VERSION_LENGTH = 12;
|
568
|
+
let version = "",
|
569
|
+
ch;
|
570
|
+
|
571
|
+
while ((ch = stream.getByte()) > 0x20) {
|
572
|
+
if (version.length >= MAX_PDF_VERSION_LENGTH) {
|
573
|
+
break;
|
474
574
|
}
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
575
|
+
|
576
|
+
version += String.fromCharCode(ch);
|
577
|
+
}
|
578
|
+
|
579
|
+
if (!this.pdfFormatVersion) {
|
580
|
+
this.pdfFormatVersion = version.substring(5);
|
581
|
+
}
|
582
|
+
}
|
583
|
+
|
584
|
+
parseStartXRef() {
|
585
|
+
this.xref.setStartXRef(this.startXRef);
|
586
|
+
}
|
587
|
+
|
588
|
+
setup(recoveryMode) {
|
589
|
+
this.xref.parse(recoveryMode);
|
590
|
+
this.catalog = new _obj.Catalog(this.pdfManager, this.xref);
|
591
|
+
}
|
592
|
+
|
593
|
+
get numPages() {
|
594
|
+
const linearization = this.linearization;
|
595
|
+
const num = linearization ? linearization.numPages : this.catalog.numPages;
|
596
|
+
return (0, _util.shadow)(this, "numPages", num);
|
597
|
+
}
|
598
|
+
|
599
|
+
get documentInfo() {
|
600
|
+
const DocumentInfoValidators = {
|
601
|
+
Title: _util.isString,
|
602
|
+
Author: _util.isString,
|
603
|
+
Subject: _util.isString,
|
604
|
+
Keywords: _util.isString,
|
605
|
+
Creator: _util.isString,
|
606
|
+
Producer: _util.isString,
|
607
|
+
CreationDate: _util.isString,
|
608
|
+
ModDate: _util.isString,
|
609
|
+
Trapped: _primitives.isName
|
610
|
+
};
|
611
|
+
let version = this.pdfFormatVersion;
|
612
|
+
|
613
|
+
if (typeof version !== "string" || !PDF_HEADER_VERSION_REGEXP.test(version)) {
|
614
|
+
(0, _util.warn)(`Invalid PDF header version number: ${version}`);
|
615
|
+
version = null;
|
616
|
+
}
|
617
|
+
|
618
|
+
const docInfo = {
|
619
|
+
PDFFormatVersion: version,
|
620
|
+
IsLinearized: !!this.linearization,
|
621
|
+
IsAcroFormPresent: !!this.acroForm,
|
622
|
+
IsXFAPresent: !!this.xfa,
|
623
|
+
IsCollectionPresent: !!this.collection
|
624
|
+
};
|
625
|
+
let infoDict;
|
626
|
+
|
627
|
+
try {
|
628
|
+
infoDict = this.xref.trailer.get("Info");
|
629
|
+
} catch (err) {
|
630
|
+
if (err instanceof _core_utils.MissingDataException) {
|
631
|
+
throw err;
|
504
632
|
}
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
633
|
+
|
634
|
+
(0, _util.info)("The document information dictionary is invalid.");
|
635
|
+
}
|
636
|
+
|
637
|
+
if ((0, _primitives.isDict)(infoDict)) {
|
638
|
+
for (const key of infoDict.getKeys()) {
|
639
|
+
const value = infoDict.get(key);
|
640
|
+
|
641
|
+
if (DocumentInfoValidators[key]) {
|
642
|
+
if (DocumentInfoValidators[key](value)) {
|
643
|
+
docInfo[key] = typeof value !== "string" ? value : (0, _util.stringToPDFString)(value);
|
644
|
+
} else {
|
645
|
+
(0, _util.info)(`Bad value in document info for "${key}".`);
|
646
|
+
}
|
647
|
+
} else if (typeof key === "string") {
|
648
|
+
let customValue;
|
649
|
+
|
650
|
+
if ((0, _util.isString)(value)) {
|
651
|
+
customValue = (0, _util.stringToPDFString)(value);
|
652
|
+
} else if ((0, _primitives.isName)(value) || (0, _util.isNum)(value) || (0, _util.isBool)(value)) {
|
653
|
+
customValue = value;
|
654
|
+
} else {
|
655
|
+
(0, _util.info)(`Unsupported value in document info for (custom) "${key}".`);
|
656
|
+
continue;
|
657
|
+
}
|
658
|
+
|
659
|
+
if (!docInfo["Custom"]) {
|
660
|
+
docInfo["Custom"] = Object.create(null);
|
514
661
|
}
|
662
|
+
|
663
|
+
docInfo["Custom"][key] = customValue;
|
515
664
|
}
|
516
665
|
}
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
666
|
+
}
|
667
|
+
|
668
|
+
return (0, _util.shadow)(this, "documentInfo", docInfo);
|
669
|
+
}
|
670
|
+
|
671
|
+
get fingerprint() {
|
672
|
+
let hash;
|
673
|
+
const idArray = this.xref.trailer.get("ID");
|
674
|
+
|
675
|
+
if (Array.isArray(idArray) && idArray[0] && (0, _util.isString)(idArray[0]) && idArray[0] !== EMPTY_FINGERPRINT) {
|
676
|
+
hash = (0, _util.stringToBytes)(idArray[0]);
|
677
|
+
} else {
|
678
|
+
hash = (0, _crypto.calculateMD5)(this.stream.getByteRange(0, FINGERPRINT_FIRST_BYTES), 0, FINGERPRINT_FIRST_BYTES);
|
679
|
+
}
|
680
|
+
|
681
|
+
const fingerprintBuf = [];
|
682
|
+
|
683
|
+
for (let i = 0, ii = hash.length; i < ii; i++) {
|
684
|
+
const hex = hash[i].toString(16);
|
685
|
+
fingerprintBuf.push(hex.padStart(2, "0"));
|
686
|
+
}
|
687
|
+
|
688
|
+
return (0, _util.shadow)(this, "fingerprint", fingerprintBuf.join(""));
|
689
|
+
}
|
690
|
+
|
691
|
+
_getLinearizationPage(pageIndex) {
|
692
|
+
const {
|
693
|
+
catalog,
|
694
|
+
linearization
|
695
|
+
} = this;
|
696
|
+
(0, _util.assert)(linearization && linearization.pageFirst === pageIndex);
|
697
|
+
|
698
|
+
const ref = _primitives.Ref.get(linearization.objectNumberFirst, 0);
|
699
|
+
|
700
|
+
return this.xref.fetchAsync(ref).then(obj => {
|
701
|
+
if ((0, _primitives.isDict)(obj, "Page") || (0, _primitives.isDict)(obj) && !obj.has("Type") && obj.has("Contents")) {
|
702
|
+
if (ref && !catalog.pageKidsCountCache.has(ref)) {
|
703
|
+
catalog.pageKidsCountCache.put(ref, 1);
|
529
704
|
}
|
530
|
-
|
531
|
-
|
532
|
-
for (var i = 0, n = hash.length; i < n; i++) {
|
533
|
-
var hex = hash[i].toString(16);
|
534
|
-
fileID += hex.length === 1 ? '0' + hex : hex;
|
705
|
+
|
706
|
+
return [obj, ref];
|
535
707
|
}
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
708
|
+
|
709
|
+
throw new _util.FormatError("The Linearization dictionary doesn't point " + "to a valid Page dictionary.");
|
710
|
+
}).catch(reason => {
|
711
|
+
(0, _util.info)(reason);
|
712
|
+
return catalog.getPageDict(pageIndex);
|
713
|
+
});
|
714
|
+
}
|
715
|
+
|
716
|
+
getPage(pageIndex) {
|
717
|
+
if (this._pagePromises[pageIndex] !== undefined) {
|
718
|
+
return this._pagePromises[pageIndex];
|
719
|
+
}
|
720
|
+
|
721
|
+
const {
|
722
|
+
catalog,
|
723
|
+
linearization
|
724
|
+
} = this;
|
725
|
+
const promise = linearization && linearization.pageFirst === pageIndex ? this._getLinearizationPage(pageIndex) : catalog.getPageDict(pageIndex);
|
726
|
+
return this._pagePromises[pageIndex] = promise.then(([pageDict, ref]) => {
|
727
|
+
return new Page({
|
728
|
+
pdfManager: this.pdfManager,
|
729
|
+
xref: this.xref,
|
730
|
+
pageIndex,
|
731
|
+
pageDict,
|
732
|
+
ref,
|
733
|
+
fontCache: catalog.fontCache,
|
734
|
+
builtInCMapCache: catalog.builtInCMapCache,
|
735
|
+
pdfFunctionFactory: this.pdfFunctionFactory
|
555
736
|
});
|
556
|
-
}
|
557
|
-
|
558
|
-
var _this5 = this;
|
737
|
+
});
|
738
|
+
}
|
559
739
|
|
560
|
-
|
561
|
-
|
740
|
+
checkFirstPage() {
|
741
|
+
return this.getPage(0).catch(async reason => {
|
742
|
+
if (reason instanceof _core_utils.XRefEntryException) {
|
743
|
+
this._pagePromises.length = 0;
|
744
|
+
await this.cleanup();
|
745
|
+
throw new _core_utils.XRefParseException();
|
562
746
|
}
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
pageIndex: pageIndex,
|
576
|
-
pageDict: pageDict,
|
577
|
-
ref: ref,
|
578
|
-
fontCache: catalog.fontCache,
|
579
|
-
builtInCMapCache: catalog.builtInCMapCache,
|
580
|
-
pdfFunctionFactory: _this5.pdfFunctionFactory
|
581
|
-
});
|
582
|
-
});
|
583
|
-
},
|
747
|
+
});
|
748
|
+
}
|
749
|
+
|
750
|
+
fontFallback(id, handler) {
|
751
|
+
return this.catalog.fontFallback(id, handler);
|
752
|
+
}
|
753
|
+
|
754
|
+
async cleanup() {
|
755
|
+
return this.catalog ? this.catalog.cleanup() : (0, _primitives.clearPrimitiveCaches)();
|
756
|
+
}
|
757
|
+
|
758
|
+
}
|
584
759
|
|
585
|
-
cleanup: function PDFDocument_cleanup() {
|
586
|
-
return this.catalog.cleanup();
|
587
|
-
}
|
588
|
-
};
|
589
|
-
return PDFDocument;
|
590
|
-
}();
|
591
|
-
exports.Page = Page;
|
592
760
|
exports.PDFDocument = PDFDocument;
|