pdfjs-dist 2.3.200 → 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/README.md +4 -0
- package/bower.json +1 -1
- package/build/pdf.js +6499 -17971
- 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 +19303 -29896
- 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 +1333 -4839
- 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 +683 -1066
- package/lib/core/arithmetic_decoder.js +81 -97
- package/lib/core/bidi.js +54 -46
- package/lib/core/ccitt.js +88 -81
- package/lib/core/ccitt_stream.js +15 -14
- package/lib/core/cff_parser.js +196 -193
- package/lib/core/charsets.js +4 -4
- package/lib/core/chunked_stream.js +441 -569
- package/lib/core/cmap.js +220 -279
- package/lib/core/colorspace.js +699 -863
- package/lib/core/core_utils.js +59 -80
- package/lib/core/crypto.js +379 -437
- package/lib/core/document.js +564 -673
- package/lib/core/encodings.js +15 -15
- package/lib/core/evaluator.js +983 -889
- package/lib/core/font_renderer.js +128 -171
- package/lib/core/fonts.js +451 -400
- package/lib/core/function.js +289 -285
- package/lib/core/glyphlist.js +4527 -4527
- package/lib/core/image.js +138 -117
- package/lib/core/image_utils.js +46 -63
- package/lib/core/jbig2.js +324 -332
- package/lib/core/jbig2_stream.js +18 -17
- package/lib/core/jpeg_stream.js +133 -24
- package/lib/core/jpg.js +238 -210
- package/lib/core/jpx.js +158 -157
- package/lib/core/jpx_stream.js +28 -28
- package/lib/core/metrics.js +2928 -2928
- package/lib/core/murmurhash3.js +87 -102
- package/lib/core/obj.js +1111 -1302
- package/lib/core/operator_list.js +55 -42
- package/lib/core/parser.js +956 -987
- package/lib/core/pattern.js +69 -69
- package/lib/core/pdf_manager.js +149 -316
- package/lib/core/primitives.js +45 -77
- package/lib/core/ps_parser.js +175 -214
- package/lib/core/standard_fonts.js +237 -236
- package/lib/core/stream.js +83 -77
- package/lib/core/type1_parser.js +78 -68
- package/lib/core/unicode.js +1654 -1654
- package/lib/core/worker.js +148 -196
- package/lib/core/worker_stream.js +101 -210
- package/lib/display/annotation_layer.js +733 -1155
- package/lib/display/api.js +1539 -1928
- package/lib/display/api_compatibility.js +10 -8
- package/lib/display/canvas.js +159 -158
- package/lib/display/content_disposition.js +36 -55
- package/lib/display/display_utils.js +298 -551
- package/lib/display/fetch_stream.js +181 -305
- package/lib/display/font_loader.js +273 -416
- package/lib/display/metadata.js +86 -98
- package/lib/display/network.js +376 -511
- package/lib/display/network_utils.js +20 -19
- package/lib/display/node_stream.js +276 -460
- package/lib/display/pattern_helper.js +76 -44
- package/lib/display/svg.js +1137 -1405
- package/lib/display/text_layer.js +75 -82
- package/lib/display/transport_stream.js +236 -374
- package/lib/display/webgl.js +70 -83
- package/lib/display/worker_options.js +3 -3
- package/lib/display/xml_parser.js +303 -392
- package/lib/examples/node/domstubs.js +37 -37
- package/lib/pdf.js +22 -21
- package/lib/pdf.worker.js +5 -5
- package/lib/shared/compatibility.js +2 -251
- package/lib/shared/is_node.js +7 -6
- package/lib/shared/message_handler.js +222 -194
- package/lib/shared/util.js +269 -405
- package/lib/test/unit/annotation_spec.js +1089 -1014
- package/lib/test/unit/api_spec.js +617 -544
- package/lib/test/unit/bidi_spec.js +7 -7
- package/lib/test/unit/cff_parser_spec.js +63 -62
- package/lib/test/unit/clitests_helper.js +7 -9
- package/lib/test/unit/cmap_spec.js +84 -86
- package/lib/test/unit/colorspace_spec.js +154 -154
- package/lib/test/unit/core_utils_spec.js +125 -105
- package/lib/test/unit/crypto_spec.js +181 -181
- package/lib/test/unit/custom_spec.js +22 -24
- package/lib/test/unit/display_svg_spec.js +35 -36
- package/lib/test/unit/display_utils_spec.js +139 -149
- package/lib/test/unit/document_spec.js +16 -16
- package/lib/test/unit/encodings_spec.js +12 -34
- package/lib/test/unit/evaluator_spec.js +81 -95
- package/lib/test/unit/fetch_stream_spec.js +30 -30
- package/lib/test/unit/function_spec.js +206 -204
- package/lib/test/unit/jasmine-boot.js +48 -32
- package/lib/test/unit/message_handler_spec.js +172 -162
- package/lib/test/unit/metadata_spec.js +69 -69
- package/lib/test/unit/murmurhash3_spec.js +12 -12
- package/lib/test/unit/network_spec.js +12 -12
- package/lib/test/unit/network_utils_spec.js +152 -152
- package/lib/test/unit/node_stream_spec.js +74 -90
- package/lib/test/unit/parser_spec.js +107 -113
- package/lib/test/unit/pdf_find_controller_spec.js +55 -86
- package/lib/test/unit/pdf_find_utils_spec.js +32 -32
- package/lib/test/unit/pdf_history_spec.js +32 -32
- package/lib/test/unit/primitives_spec.js +117 -115
- package/lib/test/unit/stream_spec.js +16 -14
- package/lib/test/unit/test_utils.js +119 -285
- package/lib/test/unit/testreporter.js +19 -19
- package/lib/test/unit/type1_parser_spec.js +41 -41
- package/lib/test/unit/ui_utils_spec.js +318 -426
- package/lib/test/unit/unicode_spec.js +42 -42
- package/lib/test/unit/util_spec.js +122 -143
- package/lib/web/annotation_layer_builder.js +66 -103
- package/lib/web/app.js +1166 -1196
- package/lib/web/app_options.js +61 -77
- package/lib/web/base_viewer.js +804 -850
- package/lib/web/chromecom.js +164 -249
- package/lib/web/debugger.js +149 -205
- package/lib/web/download_manager.js +38 -57
- package/lib/web/firefox_print_service.js +35 -30
- package/lib/web/firefoxcom.js +175 -374
- package/lib/web/genericcom.js +26 -108
- package/lib/web/genericl10n.js +24 -153
- package/lib/web/grab_to_pan.js +30 -30
- package/lib/web/interfaces.js +80 -258
- package/lib/web/overlay_manager.js +70 -246
- package/lib/web/password_prompt.js +38 -64
- package/lib/web/pdf_attachment_viewer.js +105 -130
- package/lib/web/pdf_cursor_tools.js +75 -102
- package/lib/web/pdf_document_properties.js +227 -376
- package/lib/web/pdf_find_bar.js +137 -171
- package/lib/web/pdf_find_controller.js +492 -549
- package/lib/web/pdf_find_utils.js +13 -13
- package/lib/web/pdf_history.js +395 -406
- package/lib/web/pdf_link_service.js +302 -349
- package/lib/web/pdf_outline_viewer.js +148 -209
- package/lib/web/pdf_page_view.js +449 -507
- package/lib/web/pdf_presentation_mode.js +304 -357
- package/lib/web/pdf_print_service.js +90 -104
- package/lib/web/pdf_rendering_queue.js +87 -108
- package/lib/web/pdf_sidebar.js +264 -304
- package/lib/web/pdf_sidebar_resizer.js +92 -119
- package/lib/web/pdf_single_page_viewer.js +77 -126
- package/lib/web/pdf_thumbnail_view.js +276 -297
- package/lib/web/pdf_thumbnail_viewer.js +186 -206
- package/lib/web/pdf_viewer.component.js +20 -21
- package/lib/web/pdf_viewer.js +55 -115
- package/lib/web/preferences.js +66 -273
- package/lib/web/secondary_toolbar.js +164 -196
- package/lib/web/text_layer_builder.js +284 -317
- package/lib/web/toolbar.js +216 -211
- package/lib/web/ui_utils.js +303 -404
- package/lib/web/view_history.js +49 -222
- package/lib/web/viewer_compatibility.js +7 -5
- package/package.json +2 -9
- package/web/pdf_viewer.css +25 -18
- package/web/pdf_viewer.js +3481 -4764
- package/web/pdf_viewer.js.map +1 -1
- package/webpack.js +14 -5
- package/lib/shared/streams_polyfill.js +0 -43
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.
|
@@ -26,64 +26,46 @@ Object.defineProperty(exports, "__esModule", {
|
|
26
26
|
});
|
27
27
|
exports.PDFDocument = exports.Page = void 0;
|
28
28
|
|
29
|
-
var _util = require("../shared/util");
|
29
|
+
var _util = require("../shared/util.js");
|
30
30
|
|
31
|
-
var _obj = require("./obj");
|
31
|
+
var _obj = require("./obj.js");
|
32
32
|
|
33
|
-
var _primitives = require("./primitives");
|
33
|
+
var _primitives = require("./primitives.js");
|
34
34
|
|
35
|
-
var _core_utils = require("./core_utils");
|
35
|
+
var _core_utils = require("./core_utils.js");
|
36
36
|
|
37
|
-
var
|
37
|
+
var _stream = require("./stream.js");
|
38
38
|
|
39
|
-
var _annotation = require("./annotation");
|
39
|
+
var _annotation = require("./annotation.js");
|
40
40
|
|
41
|
-
var _crypto = require("./crypto");
|
41
|
+
var _crypto = require("./crypto.js");
|
42
42
|
|
43
|
-
var _parser = require("./parser");
|
43
|
+
var _parser = require("./parser.js");
|
44
44
|
|
45
|
-
var _operator_list = require("./operator_list");
|
45
|
+
var _operator_list = require("./operator_list.js");
|
46
46
|
|
47
|
-
var _evaluator = require("./evaluator");
|
47
|
+
var _evaluator = require("./evaluator.js");
|
48
48
|
|
49
|
-
var _function = require("./function");
|
49
|
+
var _function = require("./function.js");
|
50
50
|
|
51
|
-
|
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];
|
51
|
+
const DEFAULT_USER_UNIT = 1.0;
|
52
|
+
const LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
|
67
53
|
|
68
54
|
function isAnnotationRenderable(annotation, intent) {
|
69
|
-
return intent ===
|
55
|
+
return intent === "display" && annotation.viewable || intent === "print" && annotation.printable;
|
70
56
|
}
|
71
57
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
pdfFunctionFactory = _ref.pdfFunctionFactory;
|
84
|
-
|
85
|
-
_classCallCheck(this, Page);
|
86
|
-
|
58
|
+
class Page {
|
59
|
+
constructor({
|
60
|
+
pdfManager,
|
61
|
+
xref,
|
62
|
+
pageIndex,
|
63
|
+
pageDict,
|
64
|
+
ref,
|
65
|
+
fontCache,
|
66
|
+
builtInCMapCache,
|
67
|
+
pdfFunctionFactory
|
68
|
+
}) {
|
87
69
|
this.pdfManager = pdfManager;
|
88
70
|
this.pageIndex = pageIndex;
|
89
71
|
this.pageDict = pageDict;
|
@@ -94,126 +76,231 @@ function () {
|
|
94
76
|
this.pdfFunctionFactory = pdfFunctionFactory;
|
95
77
|
this.evaluatorOptions = pdfManager.evaluatorOptions;
|
96
78
|
this.resourcesPromise = null;
|
97
|
-
|
79
|
+
const idCounters = {
|
98
80
|
obj: 0
|
99
81
|
};
|
100
82
|
this.idFactory = {
|
101
|
-
createObjId
|
102
|
-
return
|
83
|
+
createObjId() {
|
84
|
+
return `p${pageIndex}_${++idCounters.obj}`;
|
103
85
|
},
|
104
|
-
|
105
|
-
|
86
|
+
|
87
|
+
getDocId() {
|
88
|
+
return `g_${pdfManager.docId}`;
|
106
89
|
}
|
90
|
+
|
107
91
|
};
|
108
92
|
}
|
109
93
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
getArray: getArray,
|
118
|
-
stopWhenFound: false
|
119
|
-
});
|
94
|
+
_getInheritableProperty(key, getArray = false) {
|
95
|
+
const value = (0, _core_utils.getInheritableProperty)({
|
96
|
+
dict: this.pageDict,
|
97
|
+
key,
|
98
|
+
getArray,
|
99
|
+
stopWhenFound: false
|
100
|
+
});
|
120
101
|
|
121
|
-
|
122
|
-
|
123
|
-
|
102
|
+
if (!Array.isArray(value)) {
|
103
|
+
return value;
|
104
|
+
}
|
124
105
|
|
125
|
-
|
126
|
-
|
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;
|
127
127
|
}
|
128
128
|
|
129
|
-
|
129
|
+
(0, _util.warn)(`Empty /${name} entry.`);
|
130
130
|
}
|
131
|
-
}, {
|
132
|
-
key: "_getBoundingBox",
|
133
|
-
value: function _getBoundingBox(name) {
|
134
|
-
var box = this._getInheritableProperty(name, true);
|
135
|
-
|
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
131
|
|
141
|
-
|
142
|
-
|
132
|
+
return null;
|
133
|
+
}
|
134
|
+
|
135
|
+
get mediaBox() {
|
136
|
+
return (0, _util.shadow)(this, "mediaBox", this._getBoundingBox("MediaBox") || LETTER_SIZE_MEDIABOX);
|
137
|
+
}
|
143
138
|
|
144
|
-
|
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;
|
145
148
|
}
|
146
|
-
}, {
|
147
|
-
key: "getContentStream",
|
148
|
-
value: function getContentStream() {
|
149
|
-
var content = this.content;
|
150
|
-
var stream;
|
151
|
-
|
152
|
-
if (Array.isArray(content)) {
|
153
|
-
var xref = this.xref;
|
154
|
-
var streams = [];
|
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
|
-
}
|
177
|
-
}
|
178
149
|
|
179
|
-
|
180
|
-
|
181
|
-
|
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;
|
182
167
|
} else {
|
183
|
-
|
168
|
+
(0, _util.warn)("Empty /CropBox and /MediaBox intersection.");
|
184
169
|
}
|
170
|
+
}
|
171
|
+
|
172
|
+
return (0, _util.shadow)(this, "view", view || mediaBox);
|
173
|
+
}
|
185
174
|
|
186
|
-
|
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;
|
187
184
|
}
|
188
|
-
}, {
|
189
|
-
key: "loadResources",
|
190
|
-
value: function loadResources(keys) {
|
191
|
-
var _this = this;
|
192
185
|
|
193
|
-
|
194
|
-
|
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));
|
195
199
|
}
|
196
200
|
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
+
stream = new _stream.StreamsSequenceStream(streams);
|
202
|
+
} else if ((0, _primitives.isStream)(content)) {
|
203
|
+
stream = content;
|
204
|
+
} else {
|
205
|
+
stream = new _stream.NullStream();
|
201
206
|
}
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
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
|
+
};
|
264
|
+
}
|
265
|
+
|
266
|
+
const opListPromises = [];
|
267
|
+
|
268
|
+
for (const annotation of annotations) {
|
269
|
+
if (isAnnotationRenderable(annotation, intent)) {
|
270
|
+
opListPromises.push(annotation.getOperatorList(partialEvaluator, task, renderInteractiveForms));
|
271
|
+
}
|
272
|
+
}
|
273
|
+
|
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
|
+
};
|
286
|
+
});
|
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({
|
215
302
|
xref: this.xref,
|
216
|
-
handler
|
303
|
+
handler,
|
217
304
|
pageIndex: this.pageIndex,
|
218
305
|
idFactory: this.idFactory,
|
219
306
|
fontCache: this.fontCache,
|
@@ -221,289 +308,129 @@ function () {
|
|
221
308
|
options: this.evaluatorOptions,
|
222
309
|
pdfFunctionFactory: this.pdfFunctionFactory
|
223
310
|
});
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
transparency: partialEvaluator.hasBlendModes(_this2.resources),
|
232
|
-
pageIndex: _this2.pageIndex,
|
233
|
-
intent: intent
|
234
|
-
});
|
235
|
-
return partialEvaluator.getOperatorList({
|
236
|
-
stream: contentStream,
|
237
|
-
task: task,
|
238
|
-
resources: _this2.resources,
|
239
|
-
operatorList: opList
|
240
|
-
}).then(function () {
|
241
|
-
return opList;
|
242
|
-
});
|
311
|
+
return partialEvaluator.getTextContent({
|
312
|
+
stream: contentStream,
|
313
|
+
task,
|
314
|
+
resources: this.resources,
|
315
|
+
normalizeWhitespace,
|
316
|
+
combineTextItems,
|
317
|
+
sink
|
243
318
|
});
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
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);
|
254
329
|
}
|
330
|
+
}
|
255
331
|
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
var _iteratorError2 = undefined;
|
332
|
+
return annotationsData;
|
333
|
+
});
|
334
|
+
}
|
260
335
|
|
261
|
-
|
262
|
-
|
263
|
-
|
336
|
+
get annotations() {
|
337
|
+
return (0, _util.shadow)(this, "annotations", this._getInheritableProperty("Annots") || []);
|
338
|
+
}
|
264
339
|
|
265
|
-
|
266
|
-
|
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
|
-
}
|
281
|
-
}
|
282
|
-
}
|
340
|
+
get _parsedAnnotations() {
|
341
|
+
const parsedAnnotations = this.pdfManager.ensure(this, "annotations").then(() => {
|
342
|
+
const annotationRefs = this.annotations;
|
343
|
+
const annotationPromises = [];
|
283
344
|
|
284
|
-
|
285
|
-
|
286
|
-
|
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
|
-
}
|
308
|
-
}
|
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
|
+
}
|
309
348
|
|
310
|
-
|
311
|
-
|
312
|
-
return
|
313
|
-
length: pageOpList.totalLength
|
314
|
-
};
|
349
|
+
return Promise.all(annotationPromises).then(function (annotations) {
|
350
|
+
return annotations.filter(function isDefined(annotation) {
|
351
|
+
return !!annotation;
|
315
352
|
});
|
353
|
+
}, function (reason) {
|
354
|
+
(0, _util.warn)(`_parsedAnnotations: "${reason}".`);
|
355
|
+
return [];
|
316
356
|
});
|
317
|
-
}
|
318
|
-
|
319
|
-
|
320
|
-
value: function extractTextContent(_ref7) {
|
321
|
-
var _this3 = this;
|
322
|
-
|
323
|
-
var handler = _ref7.handler,
|
324
|
-
task = _ref7.task,
|
325
|
-
normalizeWhitespace = _ref7.normalizeWhitespace,
|
326
|
-
sink = _ref7.sink,
|
327
|
-
combineTextItems = _ref7.combineTextItems;
|
328
|
-
var contentStreamPromise = this.pdfManager.ensure(this, 'getContentStream');
|
329
|
-
var resourcesPromise = this.loadResources(['ExtGState', 'XObject', 'Font']);
|
330
|
-
var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
|
331
|
-
return dataPromises.then(function (_ref8) {
|
332
|
-
var _ref9 = _slicedToArray(_ref8, 1),
|
333
|
-
contentStream = _ref9[0];
|
334
|
-
|
335
|
-
var partialEvaluator = new _evaluator.PartialEvaluator({
|
336
|
-
xref: _this3.xref,
|
337
|
-
handler: handler,
|
338
|
-
pageIndex: _this3.pageIndex,
|
339
|
-
idFactory: _this3.idFactory,
|
340
|
-
fontCache: _this3.fontCache,
|
341
|
-
builtInCMapCache: _this3.builtInCMapCache,
|
342
|
-
options: _this3.evaluatorOptions,
|
343
|
-
pdfFunctionFactory: _this3.pdfFunctionFactory
|
344
|
-
});
|
345
|
-
return partialEvaluator.getTextContent({
|
346
|
-
stream: contentStream,
|
347
|
-
task: task,
|
348
|
-
resources: _this3.resources,
|
349
|
-
normalizeWhitespace: normalizeWhitespace,
|
350
|
-
combineTextItems: combineTextItems,
|
351
|
-
sink: sink
|
352
|
-
});
|
353
|
-
});
|
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
|
-
}
|
365
|
-
}
|
357
|
+
});
|
358
|
+
return (0, _util.shadow)(this, "_parsedAnnotations", parsedAnnotations);
|
359
|
+
}
|
366
360
|
|
367
|
-
|
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');
|
361
|
+
}
|
394
362
|
|
395
|
-
|
396
|
-
|
397
|
-
|
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
|
+
}
|
398
379
|
|
399
|
-
|
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);
|
380
|
+
if (backwards) {
|
381
|
+
const signatureEnd = signatureLength - 1;
|
382
|
+
let pos = scanBytes.length - 1;
|
412
383
|
|
413
|
-
|
414
|
-
|
415
|
-
} else {
|
416
|
-
(0, _util.warn)('Empty /CropBox and /MediaBox intersection.');
|
417
|
-
}
|
418
|
-
}
|
384
|
+
while (pos >= signatureEnd) {
|
385
|
+
let j = 0;
|
419
386
|
|
420
|
-
|
421
|
-
|
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;
|
387
|
+
while (j < signatureLength && scanBytes[pos - j] === signature[signatureEnd - j]) {
|
388
|
+
j++;
|
433
389
|
}
|
434
390
|
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
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
|
-
}
|
391
|
+
if (j >= signatureLength) {
|
392
|
+
stream.pos += pos - signatureEnd;
|
393
|
+
return true;
|
394
|
+
}
|
454
395
|
|
455
|
-
|
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);
|
396
|
+
pos--;
|
465
397
|
}
|
466
|
-
}
|
398
|
+
} else {
|
399
|
+
let pos = 0;
|
467
400
|
|
468
|
-
|
469
|
-
|
401
|
+
while (pos <= scanLength) {
|
402
|
+
let j = 0;
|
470
403
|
|
471
|
-
|
472
|
-
|
473
|
-
|
404
|
+
while (j < signatureLength && scanBytes[pos + j] === signature[j]) {
|
405
|
+
j++;
|
406
|
+
}
|
474
407
|
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
|
408
|
+
if (j >= signatureLength) {
|
409
|
+
stream.pos += pos;
|
410
|
+
return true;
|
411
|
+
}
|
480
412
|
|
481
|
-
|
482
|
-
|
413
|
+
pos++;
|
414
|
+
}
|
483
415
|
}
|
484
416
|
|
485
|
-
|
486
|
-
return true;
|
417
|
+
return false;
|
487
418
|
}
|
488
419
|
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
function PDFDocument(pdfManager, arg) {
|
493
|
-
_classCallCheck(this, PDFDocument);
|
494
|
-
|
495
|
-
var stream;
|
420
|
+
class PDFDocument {
|
421
|
+
constructor(pdfManager, arg) {
|
422
|
+
let stream;
|
496
423
|
|
497
424
|
if ((0, _primitives.isStream)(arg)) {
|
498
425
|
stream = arg;
|
499
426
|
} else if ((0, _util.isArrayBuffer)(arg)) {
|
500
|
-
stream = new
|
427
|
+
stream = new _stream.Stream(arg);
|
501
428
|
} else {
|
502
|
-
throw new Error(
|
429
|
+
throw new Error("PDFDocument: Unknown argument type");
|
503
430
|
}
|
504
431
|
|
505
432
|
if (stream.length <= 0) {
|
506
|
-
throw new
|
433
|
+
throw new _util.InvalidPDFException("The PDF file is empty, i.e. its size is zero bytes.");
|
507
434
|
}
|
508
435
|
|
509
436
|
this.pdfManager = pdfManager;
|
@@ -516,354 +443,318 @@ function () {
|
|
516
443
|
this._pagePromises = [];
|
517
444
|
}
|
518
445
|
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
this.setup(recoveryMode);
|
523
|
-
var version = this.catalog.catDict.get('Version');
|
446
|
+
parse(recoveryMode) {
|
447
|
+
this.setup(recoveryMode);
|
448
|
+
const version = this.catalog.catDict.get("Version");
|
524
449
|
|
525
|
-
|
526
|
-
|
527
|
-
|
450
|
+
if ((0, _primitives.isName)(version)) {
|
451
|
+
this.pdfFormatVersion = version.name;
|
452
|
+
}
|
528
453
|
|
529
|
-
|
530
|
-
|
454
|
+
try {
|
455
|
+
this.acroForm = this.catalog.catDict.get("AcroForm");
|
531
456
|
|
532
|
-
|
533
|
-
|
534
|
-
|
457
|
+
if (this.acroForm) {
|
458
|
+
this.xfa = this.acroForm.get("XFA");
|
459
|
+
const fields = this.acroForm.get("Fields");
|
535
460
|
|
536
|
-
|
537
|
-
|
538
|
-
}
|
539
|
-
}
|
540
|
-
} catch (ex) {
|
541
|
-
if (ex instanceof _core_utils.MissingDataException) {
|
542
|
-
throw ex;
|
461
|
+
if ((!Array.isArray(fields) || fields.length === 0) && !this.xfa) {
|
462
|
+
this.acroForm = null;
|
543
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;
|
472
|
+
}
|
473
|
+
|
474
|
+
try {
|
475
|
+
const collection = this.catalog.catDict.get("Collection");
|
544
476
|
|
545
|
-
|
546
|
-
this.
|
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;
|
547
483
|
}
|
548
484
|
|
549
|
-
|
550
|
-
|
485
|
+
(0, _util.info)("Cannot fetch Collection dictionary.");
|
486
|
+
}
|
487
|
+
}
|
551
488
|
|
552
|
-
|
553
|
-
|
554
|
-
}
|
555
|
-
} catch (ex) {
|
556
|
-
if (ex instanceof _core_utils.MissingDataException) {
|
557
|
-
throw ex;
|
558
|
-
}
|
489
|
+
get linearization() {
|
490
|
+
let linearization = null;
|
559
491
|
|
560
|
-
|
492
|
+
try {
|
493
|
+
linearization = _parser.Linearization.create(this.stream);
|
494
|
+
} catch (err) {
|
495
|
+
if (err instanceof _core_utils.MissingDataException) {
|
496
|
+
throw err;
|
561
497
|
}
|
498
|
+
|
499
|
+
(0, _util.info)(err);
|
562
500
|
}
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
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) {
|
567
510
|
stream.reset();
|
568
511
|
|
569
|
-
if (
|
570
|
-
|
512
|
+
if (find(stream, ENDOBJ_SIGNATURE)) {
|
513
|
+
startXRef = stream.pos + 6 - stream.start;
|
571
514
|
}
|
515
|
+
} else {
|
516
|
+
const step = 1024;
|
517
|
+
const startXRefLength = STARTXREF_SIGNATURE.length;
|
518
|
+
let found = false,
|
519
|
+
pos = stream.end;
|
572
520
|
|
573
|
-
|
574
|
-
|
575
|
-
var version = '',
|
576
|
-
ch;
|
521
|
+
while (!found && pos > 0) {
|
522
|
+
pos -= step - startXRefLength;
|
577
523
|
|
578
|
-
|
579
|
-
|
580
|
-
break;
|
524
|
+
if (pos < 0) {
|
525
|
+
pos = 0;
|
581
526
|
}
|
582
527
|
|
583
|
-
|
528
|
+
stream.pos = pos;
|
529
|
+
found = find(stream, STARTXREF_SIGNATURE, step, true);
|
584
530
|
}
|
585
531
|
|
586
|
-
if (
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
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);
|
614
|
-
}
|
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 = "";
|
615
541
|
|
616
|
-
|
542
|
+
while (ch >= 0x20 && ch <= 0x39) {
|
543
|
+
str += String.fromCharCode(ch);
|
544
|
+
ch = stream.getByte();
|
617
545
|
}
|
618
546
|
|
619
|
-
|
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;
|
547
|
+
startXRef = parseInt(str, 10);
|
629
548
|
|
630
|
-
|
631
|
-
|
549
|
+
if (isNaN(startXRef)) {
|
550
|
+
startXRef = 0;
|
551
|
+
}
|
632
552
|
}
|
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
553
|
}
|
654
|
-
}, {
|
655
|
-
key: "checkFirstPage",
|
656
|
-
value: function checkFirstPage() {
|
657
|
-
var _this6 = this;
|
658
554
|
|
659
|
-
|
660
|
-
|
661
|
-
_this6._pagePromises.length = 0;
|
555
|
+
return (0, _util.shadow)(this, "startXRef", startXRef);
|
556
|
+
}
|
662
557
|
|
663
|
-
|
558
|
+
checkHeader() {
|
559
|
+
const stream = this.stream;
|
560
|
+
stream.reset();
|
664
561
|
|
665
|
-
|
666
|
-
|
667
|
-
});
|
562
|
+
if (!find(stream, PDF_HEADER_SIGNATURE)) {
|
563
|
+
return;
|
668
564
|
}
|
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;
|
689
|
-
}
|
690
565
|
|
691
|
-
|
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;
|
692
574
|
}
|
693
575
|
|
694
|
-
|
576
|
+
version += String.fromCharCode(ch);
|
695
577
|
}
|
696
|
-
}, {
|
697
|
-
key: "startXRef",
|
698
|
-
get: function get() {
|
699
|
-
var stream = this.stream;
|
700
|
-
var startXRef = 0;
|
701
578
|
|
702
|
-
|
703
|
-
|
579
|
+
if (!this.pdfFormatVersion) {
|
580
|
+
this.pdfFormatVersion = version.substring(5);
|
581
|
+
}
|
582
|
+
}
|
704
583
|
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
} else {
|
709
|
-
var step = 1024;
|
710
|
-
var startXRefLength = 'startxref'.length;
|
711
|
-
var found = false,
|
712
|
-
pos = stream.end;
|
584
|
+
parseStartXRef() {
|
585
|
+
this.xref.setStartXRef(this.startXRef);
|
586
|
+
}
|
713
587
|
|
714
|
-
|
715
|
-
|
588
|
+
setup(recoveryMode) {
|
589
|
+
this.xref.parse(recoveryMode);
|
590
|
+
this.catalog = new _obj.Catalog(this.pdfManager, this.xref);
|
591
|
+
}
|
716
592
|
|
717
|
-
|
718
|
-
|
719
|
-
|
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
|
+
}
|
720
598
|
|
721
|
-
|
722
|
-
|
723
|
-
|
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;
|
724
612
|
|
725
|
-
|
726
|
-
|
727
|
-
|
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
|
+
}
|
728
617
|
|
729
|
-
|
730
|
-
|
731
|
-
|
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;
|
732
626
|
|
733
|
-
|
627
|
+
try {
|
628
|
+
infoDict = this.xref.trailer.get("Info");
|
629
|
+
} catch (err) {
|
630
|
+
if (err instanceof _core_utils.MissingDataException) {
|
631
|
+
throw err;
|
632
|
+
}
|
734
633
|
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
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);
|
739
640
|
|
740
|
-
|
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
|
+
}
|
741
658
|
|
742
|
-
if (
|
743
|
-
|
659
|
+
if (!docInfo["Custom"]) {
|
660
|
+
docInfo["Custom"] = Object.create(null);
|
744
661
|
}
|
662
|
+
|
663
|
+
docInfo["Custom"][key] = customValue;
|
745
664
|
}
|
746
665
|
}
|
666
|
+
}
|
747
667
|
|
748
|
-
|
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);
|
749
679
|
}
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
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"));
|
756
686
|
}
|
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
|
-
};
|
771
|
-
var docInfo = {
|
772
|
-
PDFFormatVersion: this.pdfFormatVersion,
|
773
|
-
IsLinearized: !!this.linearization,
|
774
|
-
IsAcroFormPresent: !!this.acroForm,
|
775
|
-
IsXFAPresent: !!this.xfa,
|
776
|
-
IsCollectionPresent: !!this.collection
|
777
|
-
};
|
778
|
-
var infoDict;
|
779
|
-
|
780
|
-
try {
|
781
|
-
infoDict = this.xref.trailer.get('Info');
|
782
|
-
} catch (err) {
|
783
|
-
if (err instanceof _core_utils.MissingDataException) {
|
784
|
-
throw err;
|
785
|
-
}
|
786
687
|
|
787
|
-
|
788
|
-
|
688
|
+
return (0, _util.shadow)(this, "fingerprint", fingerprintBuf.join(""));
|
689
|
+
}
|
789
690
|
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
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;
|
836
|
-
}
|
837
|
-
}
|
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);
|
838
704
|
}
|
705
|
+
|
706
|
+
return [obj, ref];
|
839
707
|
}
|
840
708
|
|
841
|
-
|
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];
|
842
719
|
}
|
843
|
-
}, {
|
844
|
-
key: "fingerprint",
|
845
|
-
get: function get() {
|
846
|
-
var hash;
|
847
|
-
var idArray = this.xref.trailer.get('ID');
|
848
|
-
|
849
|
-
if (Array.isArray(idArray) && idArray[0] && (0, _util.isString)(idArray[0]) && idArray[0] !== EMPTY_FINGERPRINT) {
|
850
|
-
hash = (0, _util.stringToBytes)(idArray[0]);
|
851
|
-
} else {
|
852
|
-
hash = (0, _crypto.calculateMD5)(this.stream.getByteRange(0, FINGERPRINT_FIRST_BYTES), 0, FINGERPRINT_FIRST_BYTES);
|
853
|
-
}
|
854
720
|
|
855
|
-
|
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
|
736
|
+
});
|
737
|
+
});
|
738
|
+
}
|
856
739
|
|
857
|
-
|
858
|
-
|
859
|
-
|
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();
|
860
746
|
}
|
747
|
+
});
|
748
|
+
}
|
861
749
|
|
862
|
-
|
863
|
-
|
864
|
-
}
|
750
|
+
fontFallback(id, handler) {
|
751
|
+
return this.catalog.fontFallback(id, handler);
|
752
|
+
}
|
865
753
|
|
866
|
-
|
867
|
-
|
754
|
+
async cleanup() {
|
755
|
+
return this.catalog ? this.catalog.cleanup() : (0, _primitives.clearPrimitiveCaches)();
|
756
|
+
}
|
757
|
+
|
758
|
+
}
|
868
759
|
|
869
760
|
exports.PDFDocument = PDFDocument;
|