pdfjs-dist 2.2.228 → 2.6.347
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 +8816 -19300
- 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 +27185 -35746
- package/build/pdf.worker.js.map +1 -1
- package/build/pdf.worker.min.js +22 -1
- package/es5/build/pdf.js +26665 -0
- package/es5/build/pdf.js.map +1 -0
- package/es5/build/pdf.min.js +22 -0
- package/{lib/shared/global_scope.js → es5/build/pdf.worker.entry.js} +5 -10
- package/es5/build/pdf.worker.js +61231 -0
- package/es5/build/pdf.worker.js.map +1 -0
- package/es5/build/pdf.worker.min.js +22 -0
- package/es5/image_decoders/pdf.image_decoders.js +12529 -0
- package/es5/image_decoders/pdf.image_decoders.js.map +1 -0
- package/es5/image_decoders/pdf.image_decoders.min.js +22 -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/pdf_viewer.css +406 -0
- package/es5/web/pdf_viewer.js +7886 -0
- package/es5/web/pdf_viewer.js.map +1 -0
- package/image_decoders/pdf.image_decoders.js +1498 -4832
- 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 +1144 -927
- 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 +747 -716
- package/lib/core/charsets.js +4 -4
- package/lib/core/chunked_stream.js +462 -553
- package/lib/core/cmap.js +231 -277
- package/lib/core/colorspace.js +715 -857
- package/lib/core/core_utils.js +57 -52
- package/lib/core/crypto.js +416 -437
- package/lib/core/document.js +629 -670
- package/lib/core/encodings.js +15 -15
- package/lib/core/evaluator.js +3229 -2800
- package/lib/core/font_renderer.js +135 -178
- package/lib/core/fonts.js +602 -534
- package/lib/core/function.js +355 -279
- package/lib/core/glyphlist.js +4527 -4526
- package/lib/core/image.js +442 -439
- package/lib/core/image_utils.js +221 -61
- package/lib/core/jbig2.js +325 -316
- package/lib/core/jbig2_stream.js +18 -17
- package/lib/core/jpeg_stream.js +21 -26
- package/lib/core/jpg.js +289 -233
- package/lib/core/jpx.js +161 -143
- 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 +1343 -1300
- package/lib/core/operator_list.js +90 -67
- package/lib/core/parser.js +990 -987
- package/lib/core/pattern.js +105 -77
- package/lib/core/pdf_manager.js +149 -316
- package/lib/core/primitives.js +156 -104
- package/lib/core/ps_parser.js +175 -214
- package/lib/core/standard_fonts.js +237 -236
- package/lib/core/stream.js +94 -74
- package/lib/core/type1_parser.js +89 -69
- package/lib/core/unicode.js +1654 -1654
- package/lib/core/worker.js +275 -290
- package/lib/core/worker_stream.js +101 -210
- package/lib/core/writer.js +242 -0
- package/lib/display/annotation_layer.js +772 -1041
- package/lib/display/annotation_storage.js +89 -0
- package/lib/display/api.js +1575 -1868
- package/lib/display/api_compatibility.js +12 -17
- package/lib/display/canvas.js +370 -222
- package/lib/display/content_disposition.js +40 -59
- package/lib/display/display_utils.js +341 -536
- package/lib/display/fetch_stream.js +188 -304
- package/lib/display/font_loader.js +282 -414
- package/lib/display/metadata.js +81 -99
- package/lib/display/network.js +362 -511
- package/lib/display/network_utils.js +25 -18
- package/lib/display/node_stream.js +283 -465
- package/lib/display/node_utils.js +87 -0
- package/lib/display/optional_content_config.js +184 -0
- package/lib/display/pattern_helper.js +93 -44
- package/lib/display/svg.js +1163 -1401
- package/lib/display/text_layer.js +154 -137
- package/lib/display/transport_stream.js +237 -375
- 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 +220 -58
- package/lib/pdf.worker.js +14 -6
- package/lib/shared/compatibility.js +3 -246
- package/lib/shared/is_node.js +7 -6
- package/lib/shared/message_handler.js +327 -332
- package/lib/shared/util.js +271 -306
- package/lib/test/unit/annotation_spec.js +1902 -763
- package/lib/test/unit/annotation_storage_spec.js +83 -0
- package/lib/test/unit/api_spec.js +790 -592
- package/lib/test/unit/bidi_spec.js +7 -7
- package/lib/test/unit/cff_parser_spec.js +73 -72
- package/lib/test/unit/clitests_helper.js +7 -9
- package/lib/test/unit/cmap_spec.js +86 -88
- package/lib/test/unit/colorspace_spec.js +346 -154
- package/lib/test/unit/core_utils_spec.js +125 -105
- package/lib/test/unit/crypto_spec.js +232 -185
- package/lib/test/unit/custom_spec.js +150 -24
- package/lib/test/unit/display_svg_spec.js +34 -39
- package/lib/test/unit/display_utils_spec.js +139 -149
- package/lib/test/unit/document_spec.js +128 -17
- package/lib/test/unit/encodings_spec.js +12 -34
- package/lib/test/unit/evaluator_spec.js +112 -91
- package/lib/test/unit/fetch_stream_spec.js +31 -29
- 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 +173 -159
- package/lib/test/unit/metadata_spec.js +71 -71
- package/lib/test/unit/murmurhash3_spec.js +12 -12
- package/lib/test/unit/network_spec.js +13 -11
- package/lib/test/unit/network_utils_spec.js +158 -144
- package/lib/test/unit/node_stream_spec.js +76 -90
- package/lib/test/unit/parser_spec.js +108 -114
- 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 +337 -156
- package/lib/test/unit/stream_spec.js +16 -14
- package/lib/test/unit/test_utils.js +91 -304
- package/lib/test/unit/testreporter.js +33 -22
- package/lib/test/unit/type1_parser_spec.js +42 -42
- package/lib/test/unit/ui_utils_spec.js +299 -461
- package/lib/test/unit/unicode_spec.js +42 -42
- package/lib/test/unit/util_spec.js +129 -149
- package/lib/test/unit/writer_spec.js +84 -0
- package/lib/web/annotation_layer_builder.js +78 -111
- package/lib/web/app.js +1542 -1267
- package/lib/web/app_options.js +76 -91
- package/lib/web/base_tree_viewer.js +100 -0
- package/lib/web/base_viewer.js +869 -834
- package/lib/web/chromecom.js +165 -252
- package/lib/web/debugger.js +149 -205
- package/lib/web/download_manager.js +34 -58
- package/lib/web/firefox_print_service.js +62 -34
- package/lib/web/firefoxcom.js +206 -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 -254
- package/lib/web/overlay_manager.js +70 -246
- package/lib/web/password_prompt.js +38 -64
- package/lib/web/pdf_attachment_viewer.js +150 -126
- package/lib/web/pdf_cursor_tools.js +75 -102
- package/lib/web/pdf_document_properties.js +229 -383
- package/lib/web/pdf_find_bar.js +136 -170
- package/lib/web/pdf_find_controller.js +492 -548
- package/lib/web/pdf_find_utils.js +13 -13
- package/lib/web/pdf_history.js +397 -406
- package/lib/web/pdf_layer_viewer.js +208 -0
- package/lib/web/pdf_link_service.js +304 -348
- package/lib/web/pdf_outline_viewer.js +119 -212
- package/lib/web/pdf_page_view.js +474 -513
- package/lib/web/pdf_presentation_mode.js +308 -357
- package/lib/web/pdf_print_service.js +96 -110
- package/lib/web/pdf_rendering_queue.js +87 -108
- package/lib/web/pdf_sidebar.js +286 -302
- 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 +289 -297
- package/lib/web/pdf_thumbnail_viewer.js +202 -206
- package/lib/web/pdf_viewer.component.js +20 -21
- package/lib/web/pdf_viewer.js +55 -115
- package/lib/web/preferences.js +69 -273
- package/lib/web/secondary_toolbar.js +164 -196
- package/lib/web/text_layer_builder.js +284 -319
- package/lib/web/toolbar.js +217 -210
- package/lib/web/ui_utils.js +274 -421
- package/lib/web/view_history.js +52 -226
- package/lib/web/viewer_compatibility.js +21 -6
- package/package.json +4 -9
- package/types/display/annotation_layer.d.ts +61 -0
- package/types/display/annotation_storage.d.ts +36 -0
- package/types/display/api.d.ts +1107 -0
- package/types/display/api_compatibility.d.ts +1 -0
- package/types/display/canvas.d.ts +4 -0
- package/types/display/content_disposition.d.ts +7 -0
- package/types/display/display_utils.d.ts +243 -0
- package/types/display/fetch_stream.d.ts +67 -0
- package/types/display/font_loader.d.ts +19 -0
- package/types/display/metadata.d.ts +9 -0
- package/types/display/network.d.ts +80 -0
- package/types/display/network_utils.d.ts +14 -0
- package/types/display/node_stream.d.ts +72 -0
- package/types/display/node_utils.d.ts +6 -0
- package/types/display/optional_content_config.d.ts +12 -0
- package/types/display/pattern_helper.d.ts +5 -0
- package/types/display/svg.d.ts +2 -0
- package/types/display/text_layer.d.ts +83 -0
- package/types/display/transport_stream.d.ts +57 -0
- package/types/display/webgl.d.ts +20 -0
- package/types/display/worker_options.d.ts +27 -0
- package/types/display/xml_parser.d.ts +35 -0
- package/types/pdf.d.ts +33 -0
- package/types/shared/compatibility.d.ts +1 -0
- package/types/shared/is_node.d.ts +1 -0
- package/types/shared/message_handler.d.ts +62 -0
- package/types/shared/util.d.ts +421 -0
- package/web/images/shadow.png +0 -0
- package/web/pdf_viewer.css +29 -27
- package/web/pdf_viewer.js +3524 -4746
- package/web/pdf_viewer.js.map +1 -1
- package/webpack.js +6 -5
- package/external/streams/streams-lib.js +0 -3962
- package/external/url/url-lib.js +0 -627
- package/lib/shared/streams_polyfill.js +0 -43
- package/lib/shared/url_polyfill.js +0 -56
- package/web/images/texture.png +0 -0
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,45 @@ 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
|
-
|
50
|
-
|
51
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
|
52
|
-
|
53
|
-
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
|
54
|
-
|
55
|
-
function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
56
|
-
|
57
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
58
|
-
|
59
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
60
|
-
|
61
|
-
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
62
|
-
|
63
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
64
|
-
|
65
|
-
var DEFAULT_USER_UNIT = 1.0;
|
66
|
-
var LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
|
49
|
+
const DEFAULT_USER_UNIT = 1.0;
|
50
|
+
const LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
|
67
51
|
|
68
52
|
function isAnnotationRenderable(annotation, intent) {
|
69
|
-
return intent ===
|
53
|
+
return intent === "display" && annotation.viewable || intent === "print" && annotation.printable;
|
70
54
|
}
|
71
55
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
_classCallCheck(this, Page);
|
86
|
-
|
56
|
+
class Page {
|
57
|
+
constructor({
|
58
|
+
pdfManager,
|
59
|
+
xref,
|
60
|
+
pageIndex,
|
61
|
+
pageDict,
|
62
|
+
ref,
|
63
|
+
globalIdFactory,
|
64
|
+
fontCache,
|
65
|
+
builtInCMapCache,
|
66
|
+
globalImageCache
|
67
|
+
}) {
|
87
68
|
this.pdfManager = pdfManager;
|
88
69
|
this.pageIndex = pageIndex;
|
89
70
|
this.pageDict = pageDict;
|
@@ -91,768 +72,746 @@ function () {
|
|
91
72
|
this.ref = ref;
|
92
73
|
this.fontCache = fontCache;
|
93
74
|
this.builtInCMapCache = builtInCMapCache;
|
94
|
-
this.
|
75
|
+
this.globalImageCache = globalImageCache;
|
95
76
|
this.evaluatorOptions = pdfManager.evaluatorOptions;
|
96
77
|
this.resourcesPromise = null;
|
97
|
-
|
78
|
+
const idCounters = {
|
98
79
|
obj: 0
|
99
80
|
};
|
100
|
-
this.
|
101
|
-
|
102
|
-
return
|
103
|
-
},
|
104
|
-
getDocId: function getDocId() {
|
105
|
-
return "g_".concat(pdfManager.docId);
|
81
|
+
this._localIdFactory = class extends globalIdFactory {
|
82
|
+
static createObjId() {
|
83
|
+
return `p${pageIndex}_${++idCounters.obj}`;
|
106
84
|
}
|
85
|
+
|
107
86
|
};
|
108
87
|
}
|
109
88
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
getArray: getArray,
|
118
|
-
stopWhenFound: false
|
119
|
-
});
|
89
|
+
_getInheritableProperty(key, getArray = false) {
|
90
|
+
const value = (0, _core_utils.getInheritableProperty)({
|
91
|
+
dict: this.pageDict,
|
92
|
+
key,
|
93
|
+
getArray,
|
94
|
+
stopWhenFound: false
|
95
|
+
});
|
120
96
|
|
121
|
-
|
122
|
-
|
123
|
-
|
97
|
+
if (!Array.isArray(value)) {
|
98
|
+
return value;
|
99
|
+
}
|
100
|
+
|
101
|
+
if (value.length === 1 || !(0, _primitives.isDict)(value[0])) {
|
102
|
+
return value[0];
|
103
|
+
}
|
104
|
+
|
105
|
+
return _primitives.Dict.merge({
|
106
|
+
xref: this.xref,
|
107
|
+
dictArray: value
|
108
|
+
});
|
109
|
+
}
|
110
|
+
|
111
|
+
get content() {
|
112
|
+
return this.pageDict.get("Contents");
|
113
|
+
}
|
124
114
|
|
125
|
-
|
126
|
-
|
115
|
+
get resources() {
|
116
|
+
return (0, _util.shadow)(this, "resources", this._getInheritableProperty("Resources") || _primitives.Dict.empty);
|
117
|
+
}
|
118
|
+
|
119
|
+
_getBoundingBox(name) {
|
120
|
+
const box = this._getInheritableProperty(name, true);
|
121
|
+
|
122
|
+
if (Array.isArray(box) && box.length === 4) {
|
123
|
+
if (box[2] - box[0] !== 0 && box[3] - box[1] !== 0) {
|
124
|
+
return box;
|
127
125
|
}
|
128
126
|
|
129
|
-
|
127
|
+
(0, _util.warn)(`Empty /${name} entry.`);
|
130
128
|
}
|
131
|
-
}, {
|
132
|
-
key: "getContentStream",
|
133
|
-
value: function getContentStream() {
|
134
|
-
var content = this.content;
|
135
|
-
var stream;
|
136
|
-
|
137
|
-
if (Array.isArray(content)) {
|
138
|
-
var xref = this.xref;
|
139
|
-
var streams = [];
|
140
|
-
var _iteratorNormalCompletion = true;
|
141
|
-
var _didIteratorError = false;
|
142
|
-
var _iteratorError = undefined;
|
143
|
-
|
144
|
-
try {
|
145
|
-
for (var _iterator = content[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
146
|
-
var _stream = _step.value;
|
147
|
-
streams.push(xref.fetchIfRef(_stream));
|
148
|
-
}
|
149
|
-
} catch (err) {
|
150
|
-
_didIteratorError = true;
|
151
|
-
_iteratorError = err;
|
152
|
-
} finally {
|
153
|
-
try {
|
154
|
-
if (!_iteratorNormalCompletion && _iterator["return"] != null) {
|
155
|
-
_iterator["return"]();
|
156
|
-
}
|
157
|
-
} finally {
|
158
|
-
if (_didIteratorError) {
|
159
|
-
throw _iteratorError;
|
160
|
-
}
|
161
|
-
}
|
162
|
-
}
|
163
129
|
|
164
|
-
|
165
|
-
|
166
|
-
|
130
|
+
return null;
|
131
|
+
}
|
132
|
+
|
133
|
+
get mediaBox() {
|
134
|
+
return (0, _util.shadow)(this, "mediaBox", this._getBoundingBox("MediaBox") || LETTER_SIZE_MEDIABOX);
|
135
|
+
}
|
136
|
+
|
137
|
+
get cropBox() {
|
138
|
+
return (0, _util.shadow)(this, "cropBox", this._getBoundingBox("CropBox") || this.mediaBox);
|
139
|
+
}
|
140
|
+
|
141
|
+
get userUnit() {
|
142
|
+
let obj = this.pageDict.get("UserUnit");
|
143
|
+
|
144
|
+
if (!(0, _util.isNum)(obj) || obj <= 0) {
|
145
|
+
obj = DEFAULT_USER_UNIT;
|
146
|
+
}
|
147
|
+
|
148
|
+
return (0, _util.shadow)(this, "userUnit", obj);
|
149
|
+
}
|
150
|
+
|
151
|
+
get view() {
|
152
|
+
const {
|
153
|
+
cropBox,
|
154
|
+
mediaBox
|
155
|
+
} = this;
|
156
|
+
let view;
|
157
|
+
|
158
|
+
if (cropBox === mediaBox || (0, _util.isArrayEqual)(cropBox, mediaBox)) {
|
159
|
+
view = mediaBox;
|
160
|
+
} else {
|
161
|
+
const box = _util.Util.intersect(cropBox, mediaBox);
|
162
|
+
|
163
|
+
if (box && box[2] - box[0] !== 0 && box[3] - box[1] !== 0) {
|
164
|
+
view = box;
|
167
165
|
} else {
|
168
|
-
|
166
|
+
(0, _util.warn)("Empty /CropBox and /MediaBox intersection.");
|
169
167
|
}
|
168
|
+
}
|
169
|
+
|
170
|
+
return (0, _util.shadow)(this, "view", view || mediaBox);
|
171
|
+
}
|
170
172
|
|
171
|
-
|
173
|
+
get rotate() {
|
174
|
+
let rotate = this._getInheritableProperty("Rotate") || 0;
|
175
|
+
|
176
|
+
if (rotate % 90 !== 0) {
|
177
|
+
rotate = 0;
|
178
|
+
} else if (rotate >= 360) {
|
179
|
+
rotate = rotate % 360;
|
180
|
+
} else if (rotate < 0) {
|
181
|
+
rotate = (rotate % 360 + 360) % 360;
|
172
182
|
}
|
173
|
-
}, {
|
174
|
-
key: "loadResources",
|
175
|
-
value: function loadResources(keys) {
|
176
|
-
var _this = this;
|
177
183
|
|
178
|
-
|
179
|
-
|
184
|
+
return (0, _util.shadow)(this, "rotate", rotate);
|
185
|
+
}
|
186
|
+
|
187
|
+
getContentStream() {
|
188
|
+
const content = this.content;
|
189
|
+
let stream;
|
190
|
+
|
191
|
+
if (Array.isArray(content)) {
|
192
|
+
const xref = this.xref;
|
193
|
+
const streams = [];
|
194
|
+
|
195
|
+
for (const subStream of content) {
|
196
|
+
streams.push(xref.fetchIfRef(subStream));
|
180
197
|
}
|
181
198
|
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
199
|
+
stream = new _stream.StreamsSequenceStream(streams);
|
200
|
+
} else if ((0, _primitives.isStream)(content)) {
|
201
|
+
stream = content;
|
202
|
+
} else {
|
203
|
+
stream = new _stream.NullStream();
|
186
204
|
}
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
205
|
+
|
206
|
+
return stream;
|
207
|
+
}
|
208
|
+
|
209
|
+
save(handler, task, annotationStorage) {
|
210
|
+
const partialEvaluator = new _evaluator.PartialEvaluator({
|
211
|
+
xref: this.xref,
|
212
|
+
handler,
|
213
|
+
pageIndex: this.pageIndex,
|
214
|
+
idFactory: this._localIdFactory,
|
215
|
+
fontCache: this.fontCache,
|
216
|
+
builtInCMapCache: this.builtInCMapCache,
|
217
|
+
globalImageCache: this.globalImageCache,
|
218
|
+
options: this.evaluatorOptions
|
219
|
+
});
|
220
|
+
return this._parsedAnnotations.then(function (annotations) {
|
221
|
+
const newRefsPromises = [];
|
222
|
+
|
223
|
+
for (const annotation of annotations) {
|
224
|
+
if (!isAnnotationRenderable(annotation, "print")) {
|
225
|
+
continue;
|
226
|
+
}
|
227
|
+
|
228
|
+
newRefsPromises.push(annotation.save(partialEvaluator, task, annotationStorage).catch(function (reason) {
|
229
|
+
(0, _util.warn)("save - ignoring annotation data during " + `"${task.name}" task: "${reason}".`);
|
230
|
+
return null;
|
231
|
+
}));
|
232
|
+
}
|
233
|
+
|
234
|
+
return Promise.all(newRefsPromises);
|
235
|
+
});
|
236
|
+
}
|
237
|
+
|
238
|
+
loadResources(keys) {
|
239
|
+
if (!this.resourcesPromise) {
|
240
|
+
this.resourcesPromise = this.pdfManager.ensure(this, "resources");
|
241
|
+
}
|
242
|
+
|
243
|
+
return this.resourcesPromise.then(() => {
|
244
|
+
const objectLoader = new _obj.ObjectLoader(this.resources, keys, this.xref);
|
245
|
+
return objectLoader.load();
|
246
|
+
});
|
247
|
+
}
|
248
|
+
|
249
|
+
getOperatorList({
|
250
|
+
handler,
|
251
|
+
sink,
|
252
|
+
task,
|
253
|
+
intent,
|
254
|
+
renderInteractiveForms,
|
255
|
+
annotationStorage
|
256
|
+
}) {
|
257
|
+
const contentStreamPromise = this.pdfManager.ensure(this, "getContentStream");
|
258
|
+
const resourcesPromise = this.loadResources(["ExtGState", "ColorSpace", "Pattern", "Shading", "XObject", "Font"]);
|
259
|
+
const partialEvaluator = new _evaluator.PartialEvaluator({
|
260
|
+
xref: this.xref,
|
261
|
+
handler,
|
262
|
+
pageIndex: this.pageIndex,
|
263
|
+
idFactory: this._localIdFactory,
|
264
|
+
fontCache: this.fontCache,
|
265
|
+
builtInCMapCache: this.builtInCMapCache,
|
266
|
+
globalImageCache: this.globalImageCache,
|
267
|
+
options: this.evaluatorOptions
|
268
|
+
});
|
269
|
+
const dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
|
270
|
+
const pageListPromise = dataPromises.then(([contentStream]) => {
|
271
|
+
const opList = new _operator_list.OperatorList(intent, sink);
|
272
|
+
handler.send("StartRenderPage", {
|
273
|
+
transparency: partialEvaluator.hasBlendModes(this.resources),
|
201
274
|
pageIndex: this.pageIndex,
|
202
|
-
|
203
|
-
fontCache: this.fontCache,
|
204
|
-
builtInCMapCache: this.builtInCMapCache,
|
205
|
-
options: this.evaluatorOptions,
|
206
|
-
pdfFunctionFactory: this.pdfFunctionFactory
|
275
|
+
intent
|
207
276
|
});
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
transparency: partialEvaluator.hasBlendModes(_this2.resources),
|
216
|
-
pageIndex: _this2.pageIndex,
|
217
|
-
intent: intent
|
218
|
-
});
|
219
|
-
return partialEvaluator.getOperatorList({
|
220
|
-
stream: contentStream,
|
221
|
-
task: task,
|
222
|
-
resources: _this2.resources,
|
223
|
-
operatorList: opList
|
224
|
-
}).then(function () {
|
225
|
-
return opList;
|
226
|
-
});
|
277
|
+
return partialEvaluator.getOperatorList({
|
278
|
+
stream: contentStream,
|
279
|
+
task,
|
280
|
+
resources: this.resources,
|
281
|
+
operatorList: opList
|
282
|
+
}).then(function () {
|
283
|
+
return opList;
|
227
284
|
});
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
}
|
285
|
+
});
|
286
|
+
return Promise.all([pageListPromise, this._parsedAnnotations]).then(function ([pageOpList, annotations]) {
|
287
|
+
if (annotations.length === 0) {
|
288
|
+
pageOpList.flush(true);
|
289
|
+
return {
|
290
|
+
length: pageOpList.totalLength
|
291
|
+
};
|
292
|
+
}
|
237
293
|
|
238
|
-
|
239
|
-
var _iteratorNormalCompletion2 = true;
|
240
|
-
var _didIteratorError2 = false;
|
241
|
-
var _iteratorError2 = undefined;
|
294
|
+
const opListPromises = [];
|
242
295
|
|
243
|
-
|
244
|
-
|
245
|
-
|
296
|
+
for (const annotation of annotations) {
|
297
|
+
if (isAnnotationRenderable(annotation, intent)) {
|
298
|
+
opListPromises.push(annotation.getOperatorList(partialEvaluator, task, renderInteractiveForms, annotationStorage).catch(function (reason) {
|
299
|
+
(0, _util.warn)("getOperatorList - ignoring annotation data during " + `"${task.name}" task: "${reason}".`);
|
300
|
+
return null;
|
301
|
+
}));
|
302
|
+
}
|
303
|
+
}
|
246
304
|
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
_didIteratorError2 = true;
|
253
|
-
_iteratorError2 = err;
|
254
|
-
} finally {
|
255
|
-
try {
|
256
|
-
if (!_iteratorNormalCompletion2 && _iterator2["return"] != null) {
|
257
|
-
_iterator2["return"]();
|
258
|
-
}
|
259
|
-
} finally {
|
260
|
-
if (_didIteratorError2) {
|
261
|
-
throw _iteratorError2;
|
262
|
-
}
|
263
|
-
}
|
305
|
+
return Promise.all(opListPromises).then(function (opLists) {
|
306
|
+
pageOpList.addOp(_util.OPS.beginAnnotations, []);
|
307
|
+
|
308
|
+
for (const opList of opLists) {
|
309
|
+
pageOpList.addOpList(opList);
|
264
310
|
}
|
265
311
|
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
var opList = _step3.value;
|
275
|
-
pageOpList.addOpList(opList);
|
276
|
-
}
|
277
|
-
} catch (err) {
|
278
|
-
_didIteratorError3 = true;
|
279
|
-
_iteratorError3 = err;
|
280
|
-
} finally {
|
281
|
-
try {
|
282
|
-
if (!_iteratorNormalCompletion3 && _iterator3["return"] != null) {
|
283
|
-
_iterator3["return"]();
|
284
|
-
}
|
285
|
-
} finally {
|
286
|
-
if (_didIteratorError3) {
|
287
|
-
throw _iteratorError3;
|
288
|
-
}
|
289
|
-
}
|
290
|
-
}
|
312
|
+
pageOpList.addOp(_util.OPS.endAnnotations, []);
|
313
|
+
pageOpList.flush(true);
|
314
|
+
return {
|
315
|
+
length: pageOpList.totalLength
|
316
|
+
};
|
317
|
+
});
|
318
|
+
});
|
319
|
+
}
|
291
320
|
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
321
|
+
extractTextContent({
|
322
|
+
handler,
|
323
|
+
task,
|
324
|
+
normalizeWhitespace,
|
325
|
+
sink,
|
326
|
+
combineTextItems
|
327
|
+
}) {
|
328
|
+
const contentStreamPromise = this.pdfManager.ensure(this, "getContentStream");
|
329
|
+
const resourcesPromise = this.loadResources(["ExtGState", "XObject", "Font"]);
|
330
|
+
const dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
|
331
|
+
return dataPromises.then(([contentStream]) => {
|
332
|
+
const partialEvaluator = new _evaluator.PartialEvaluator({
|
333
|
+
xref: this.xref,
|
334
|
+
handler,
|
335
|
+
pageIndex: this.pageIndex,
|
336
|
+
idFactory: this._localIdFactory,
|
337
|
+
fontCache: this.fontCache,
|
338
|
+
builtInCMapCache: this.builtInCMapCache,
|
339
|
+
globalImageCache: this.globalImageCache,
|
340
|
+
options: this.evaluatorOptions
|
296
341
|
});
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
task = _ref7.task,
|
305
|
-
normalizeWhitespace = _ref7.normalizeWhitespace,
|
306
|
-
sink = _ref7.sink,
|
307
|
-
combineTextItems = _ref7.combineTextItems;
|
308
|
-
var contentStreamPromise = this.pdfManager.ensure(this, 'getContentStream');
|
309
|
-
var resourcesPromise = this.loadResources(['ExtGState', 'XObject', 'Font']);
|
310
|
-
var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
|
311
|
-
return dataPromises.then(function (_ref8) {
|
312
|
-
var _ref9 = _slicedToArray(_ref8, 1),
|
313
|
-
contentStream = _ref9[0];
|
314
|
-
|
315
|
-
var partialEvaluator = new _evaluator.PartialEvaluator({
|
316
|
-
xref: _this3.xref,
|
317
|
-
handler: handler,
|
318
|
-
pageIndex: _this3.pageIndex,
|
319
|
-
idFactory: _this3.idFactory,
|
320
|
-
fontCache: _this3.fontCache,
|
321
|
-
builtInCMapCache: _this3.builtInCMapCache,
|
322
|
-
options: _this3.evaluatorOptions,
|
323
|
-
pdfFunctionFactory: _this3.pdfFunctionFactory
|
324
|
-
});
|
325
|
-
return partialEvaluator.getTextContent({
|
326
|
-
stream: contentStream,
|
327
|
-
task: task,
|
328
|
-
resources: _this3.resources,
|
329
|
-
normalizeWhitespace: normalizeWhitespace,
|
330
|
-
combineTextItems: combineTextItems,
|
331
|
-
sink: sink
|
332
|
-
});
|
342
|
+
return partialEvaluator.getTextContent({
|
343
|
+
stream: contentStream,
|
344
|
+
task,
|
345
|
+
resources: this.resources,
|
346
|
+
normalizeWhitespace,
|
347
|
+
combineTextItems,
|
348
|
+
sink
|
333
349
|
});
|
334
|
-
}
|
335
|
-
}
|
336
|
-
key: "getAnnotationsData",
|
337
|
-
value: function getAnnotationsData(intent) {
|
338
|
-
return this._parsedAnnotations.then(function (annotations) {
|
339
|
-
var annotationsData = [];
|
340
|
-
|
341
|
-
for (var i = 0, ii = annotations.length; i < ii; i++) {
|
342
|
-
if (!intent || isAnnotationRenderable(annotations[i], intent)) {
|
343
|
-
annotationsData.push(annotations[i].data);
|
344
|
-
}
|
345
|
-
}
|
350
|
+
});
|
351
|
+
}
|
346
352
|
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
}, {
|
351
|
-
key: "content",
|
352
|
-
get: function get() {
|
353
|
-
return this.pageDict.get('Contents');
|
354
|
-
}
|
355
|
-
}, {
|
356
|
-
key: "resources",
|
357
|
-
get: function get() {
|
358
|
-
return (0, _util.shadow)(this, 'resources', this._getInheritableProperty('Resources') || _primitives.Dict.empty);
|
359
|
-
}
|
360
|
-
}, {
|
361
|
-
key: "mediaBox",
|
362
|
-
get: function get() {
|
363
|
-
var mediaBox = this._getInheritableProperty('MediaBox', true);
|
353
|
+
getAnnotationsData(intent) {
|
354
|
+
return this._parsedAnnotations.then(function (annotations) {
|
355
|
+
const annotationsData = [];
|
364
356
|
|
365
|
-
|
366
|
-
|
357
|
+
for (let i = 0, ii = annotations.length; i < ii; i++) {
|
358
|
+
if (!intent || isAnnotationRenderable(annotations[i], intent)) {
|
359
|
+
annotationsData.push(annotations[i].data);
|
360
|
+
}
|
367
361
|
}
|
368
362
|
|
369
|
-
return
|
370
|
-
}
|
371
|
-
}
|
372
|
-
key: "cropBox",
|
373
|
-
get: function get() {
|
374
|
-
var cropBox = this._getInheritableProperty('CropBox', true);
|
363
|
+
return annotationsData;
|
364
|
+
});
|
365
|
+
}
|
375
366
|
|
376
|
-
|
377
|
-
|
378
|
-
|
367
|
+
get annotations() {
|
368
|
+
return (0, _util.shadow)(this, "annotations", this._getInheritableProperty("Annots") || []);
|
369
|
+
}
|
379
370
|
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
key: "userUnit",
|
384
|
-
get: function get() {
|
385
|
-
var obj = this.pageDict.get('UserUnit');
|
371
|
+
get _parsedAnnotations() {
|
372
|
+
const parsedAnnotations = this.pdfManager.ensure(this, "annotations").then(() => {
|
373
|
+
const annotationPromises = [];
|
386
374
|
|
387
|
-
|
388
|
-
|
375
|
+
for (const annotationRef of this.annotations) {
|
376
|
+
annotationPromises.push(_annotation.AnnotationFactory.create(this.xref, annotationRef, this.pdfManager, this._localIdFactory).catch(function (reason) {
|
377
|
+
(0, _util.warn)(`_parsedAnnotations: "${reason}".`);
|
378
|
+
return null;
|
379
|
+
}));
|
389
380
|
}
|
390
381
|
|
391
|
-
return (
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
cropBox = this.cropBox;
|
398
|
-
|
399
|
-
if (mediaBox === cropBox) {
|
400
|
-
return (0, _util.shadow)(this, 'view', mediaBox);
|
401
|
-
}
|
382
|
+
return Promise.all(annotationPromises).then(function (annotations) {
|
383
|
+
return annotations.filter(annotation => !!annotation);
|
384
|
+
});
|
385
|
+
});
|
386
|
+
return (0, _util.shadow)(this, "_parsedAnnotations", parsedAnnotations);
|
387
|
+
}
|
402
388
|
|
403
|
-
|
389
|
+
}
|
404
390
|
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
391
|
+
exports.Page = Page;
|
392
|
+
const PDF_HEADER_SIGNATURE = new Uint8Array([0x25, 0x50, 0x44, 0x46, 0x2d]);
|
393
|
+
const STARTXREF_SIGNATURE = new Uint8Array([0x73, 0x74, 0x61, 0x72, 0x74, 0x78, 0x72, 0x65, 0x66]);
|
394
|
+
const ENDOBJ_SIGNATURE = new Uint8Array([0x65, 0x6e, 0x64, 0x6f, 0x62, 0x6a]);
|
395
|
+
const FINGERPRINT_FIRST_BYTES = 1024;
|
396
|
+
const EMPTY_FINGERPRINT = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
|
397
|
+
const PDF_HEADER_VERSION_REGEXP = /^[1-9]\.[0-9]$/;
|
398
|
+
|
399
|
+
function find(stream, signature, limit = 1024, backwards = false) {
|
400
|
+
const signatureLength = signature.length;
|
401
|
+
const scanBytes = stream.peekBytes(limit);
|
402
|
+
const scanLength = scanBytes.length - signatureLength;
|
403
|
+
|
404
|
+
if (scanLength <= 0) {
|
405
|
+
return false;
|
406
|
+
}
|
419
407
|
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
key: "annotations",
|
424
|
-
get: function get() {
|
425
|
-
return (0, _util.shadow)(this, 'annotations', this._getInheritableProperty('Annots') || []);
|
426
|
-
}
|
427
|
-
}, {
|
428
|
-
key: "_parsedAnnotations",
|
429
|
-
get: function get() {
|
430
|
-
var _this4 = this;
|
408
|
+
if (backwards) {
|
409
|
+
const signatureEnd = signatureLength - 1;
|
410
|
+
let pos = scanBytes.length - 1;
|
431
411
|
|
432
|
-
|
433
|
-
|
434
|
-
var annotationPromises = [];
|
412
|
+
while (pos >= signatureEnd) {
|
413
|
+
let j = 0;
|
435
414
|
|
436
|
-
|
437
|
-
|
438
|
-
|
415
|
+
while (j < signatureLength && scanBytes[pos - j] === signature[signatureEnd - j]) {
|
416
|
+
j++;
|
417
|
+
}
|
439
418
|
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
return [];
|
447
|
-
});
|
448
|
-
});
|
449
|
-
return (0, _util.shadow)(this, '_parsedAnnotations', parsedAnnotations);
|
419
|
+
if (j >= signatureLength) {
|
420
|
+
stream.pos += pos - signatureEnd;
|
421
|
+
return true;
|
422
|
+
}
|
423
|
+
|
424
|
+
pos--;
|
450
425
|
}
|
451
|
-
}
|
426
|
+
} else {
|
427
|
+
let pos = 0;
|
452
428
|
|
453
|
-
|
454
|
-
|
429
|
+
while (pos <= scanLength) {
|
430
|
+
let j = 0;
|
455
431
|
|
456
|
-
|
457
|
-
|
458
|
-
|
432
|
+
while (j < signatureLength && scanBytes[pos + j] === signature[j]) {
|
433
|
+
j++;
|
434
|
+
}
|
459
435
|
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
|
436
|
+
if (j >= signatureLength) {
|
437
|
+
stream.pos += pos;
|
438
|
+
return true;
|
439
|
+
}
|
465
440
|
|
466
|
-
|
467
|
-
|
441
|
+
pos++;
|
442
|
+
}
|
468
443
|
}
|
469
444
|
|
470
|
-
|
471
|
-
return true;
|
445
|
+
return false;
|
472
446
|
}
|
473
447
|
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
function PDFDocument(pdfManager, arg) {
|
478
|
-
_classCallCheck(this, PDFDocument);
|
479
|
-
|
480
|
-
var stream;
|
448
|
+
class PDFDocument {
|
449
|
+
constructor(pdfManager, arg) {
|
450
|
+
let stream;
|
481
451
|
|
482
452
|
if ((0, _primitives.isStream)(arg)) {
|
483
453
|
stream = arg;
|
484
454
|
} else if ((0, _util.isArrayBuffer)(arg)) {
|
485
|
-
stream = new
|
455
|
+
stream = new _stream.Stream(arg);
|
486
456
|
} else {
|
487
|
-
throw new Error(
|
457
|
+
throw new Error("PDFDocument: Unknown argument type");
|
488
458
|
}
|
489
459
|
|
490
460
|
if (stream.length <= 0) {
|
491
|
-
throw new
|
461
|
+
throw new _util.InvalidPDFException("The PDF file is empty, i.e. its size is zero bytes.");
|
492
462
|
}
|
493
463
|
|
494
464
|
this.pdfManager = pdfManager;
|
495
465
|
this.stream = stream;
|
496
466
|
this.xref = new _obj.XRef(stream, pdfManager);
|
497
|
-
this.pdfFunctionFactory = new _function.PDFFunctionFactory({
|
498
|
-
xref: this.xref,
|
499
|
-
isEvalSupported: pdfManager.evaluatorOptions.isEvalSupported
|
500
|
-
});
|
501
467
|
this._pagePromises = [];
|
502
|
-
|
468
|
+
this._version = null;
|
469
|
+
const idCounters = {
|
470
|
+
font: 0
|
471
|
+
};
|
472
|
+
this._globalIdFactory = class {
|
473
|
+
static getDocId() {
|
474
|
+
return `g_${pdfManager.docId}`;
|
475
|
+
}
|
503
476
|
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
this.setup(recoveryMode);
|
508
|
-
var version = this.catalog.catDict.get('Version');
|
477
|
+
static createFontId() {
|
478
|
+
return `f${++idCounters.font}`;
|
479
|
+
}
|
509
480
|
|
510
|
-
|
511
|
-
|
481
|
+
static createObjId() {
|
482
|
+
(0, _util.unreachable)("Abstract method `createObjId` called.");
|
512
483
|
}
|
513
484
|
|
514
|
-
|
515
|
-
|
485
|
+
};
|
486
|
+
}
|
487
|
+
|
488
|
+
parse(recoveryMode) {
|
489
|
+
this.xref.parse(recoveryMode);
|
490
|
+
this.catalog = new _obj.Catalog(this.pdfManager, this.xref);
|
516
491
|
|
517
|
-
|
518
|
-
|
519
|
-
|
492
|
+
if (this.catalog.version) {
|
493
|
+
this._version = this.catalog.version;
|
494
|
+
}
|
495
|
+
}
|
520
496
|
|
521
|
-
|
522
|
-
|
523
|
-
}
|
524
|
-
}
|
525
|
-
} catch (ex) {
|
526
|
-
if (ex instanceof _core_utils.MissingDataException) {
|
527
|
-
throw ex;
|
528
|
-
}
|
497
|
+
get linearization() {
|
498
|
+
let linearization = null;
|
529
499
|
|
530
|
-
|
531
|
-
|
500
|
+
try {
|
501
|
+
linearization = _parser.Linearization.create(this.stream);
|
502
|
+
} catch (err) {
|
503
|
+
if (err instanceof _core_utils.MissingDataException) {
|
504
|
+
throw err;
|
532
505
|
}
|
533
506
|
|
534
|
-
|
535
|
-
|
507
|
+
(0, _util.info)(err);
|
508
|
+
}
|
536
509
|
|
537
|
-
|
538
|
-
|
539
|
-
}
|
540
|
-
} catch (ex) {
|
541
|
-
if (ex instanceof _core_utils.MissingDataException) {
|
542
|
-
throw ex;
|
543
|
-
}
|
510
|
+
return (0, _util.shadow)(this, "linearization", linearization);
|
511
|
+
}
|
544
512
|
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
value: function checkHeader() {
|
551
|
-
var stream = this.stream;
|
513
|
+
get startXRef() {
|
514
|
+
const stream = this.stream;
|
515
|
+
let startXRef = 0;
|
516
|
+
|
517
|
+
if (this.linearization) {
|
552
518
|
stream.reset();
|
553
519
|
|
554
|
-
if (
|
555
|
-
|
520
|
+
if (find(stream, ENDOBJ_SIGNATURE)) {
|
521
|
+
startXRef = stream.pos + 6 - stream.start;
|
556
522
|
}
|
523
|
+
} else {
|
524
|
+
const step = 1024;
|
525
|
+
const startXRefLength = STARTXREF_SIGNATURE.length;
|
526
|
+
let found = false,
|
527
|
+
pos = stream.end;
|
557
528
|
|
558
|
-
|
559
|
-
|
560
|
-
var version = '',
|
561
|
-
ch;
|
529
|
+
while (!found && pos > 0) {
|
530
|
+
pos -= step - startXRefLength;
|
562
531
|
|
563
|
-
|
564
|
-
|
565
|
-
break;
|
532
|
+
if (pos < 0) {
|
533
|
+
pos = 0;
|
566
534
|
}
|
567
535
|
|
568
|
-
|
536
|
+
stream.pos = pos;
|
537
|
+
found = find(stream, STARTXREF_SIGNATURE, step, true);
|
569
538
|
}
|
570
539
|
|
571
|
-
if (
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
}, {
|
581
|
-
key: "setup",
|
582
|
-
value: function setup(recoveryMode) {
|
583
|
-
this.xref.parse(recoveryMode);
|
584
|
-
this.catalog = new _obj.Catalog(this.pdfManager, this.xref);
|
585
|
-
}
|
586
|
-
}, {
|
587
|
-
key: "_getLinearizationPage",
|
588
|
-
value: function _getLinearizationPage(pageIndex) {
|
589
|
-
var catalog = this.catalog,
|
590
|
-
linearization = this.linearization;
|
591
|
-
(0, _util.assert)(linearization && linearization.pageFirst === pageIndex);
|
592
|
-
|
593
|
-
var ref = _primitives.Ref.get(linearization.objectNumberFirst, 0);
|
594
|
-
|
595
|
-
return this.xref.fetchAsync(ref).then(function (obj) {
|
596
|
-
if ((0, _primitives.isDict)(obj, 'Page') || (0, _primitives.isDict)(obj) && !obj.has('Type') && obj.has('Contents')) {
|
597
|
-
if (ref && !catalog.pageKidsCountCache.has(ref)) {
|
598
|
-
catalog.pageKidsCountCache.put(ref, 1);
|
599
|
-
}
|
540
|
+
if (found) {
|
541
|
+
stream.skip(9);
|
542
|
+
let ch;
|
543
|
+
|
544
|
+
do {
|
545
|
+
ch = stream.getByte();
|
546
|
+
} while ((0, _core_utils.isWhiteSpace)(ch));
|
547
|
+
|
548
|
+
let str = "";
|
600
549
|
|
601
|
-
|
550
|
+
while (ch >= 0x20 && ch <= 0x39) {
|
551
|
+
str += String.fromCharCode(ch);
|
552
|
+
ch = stream.getByte();
|
602
553
|
}
|
603
554
|
|
604
|
-
|
605
|
-
})["catch"](function (reason) {
|
606
|
-
(0, _util.info)(reason);
|
607
|
-
return catalog.getPageDict(pageIndex);
|
608
|
-
});
|
609
|
-
}
|
610
|
-
}, {
|
611
|
-
key: "getPage",
|
612
|
-
value: function getPage(pageIndex) {
|
613
|
-
var _this5 = this;
|
555
|
+
startXRef = parseInt(str, 10);
|
614
556
|
|
615
|
-
|
616
|
-
|
557
|
+
if (isNaN(startXRef)) {
|
558
|
+
startXRef = 0;
|
559
|
+
}
|
617
560
|
}
|
618
|
-
|
619
|
-
var catalog = this.catalog,
|
620
|
-
linearization = this.linearization;
|
621
|
-
var promise = linearization && linearization.pageFirst === pageIndex ? this._getLinearizationPage(pageIndex) : catalog.getPageDict(pageIndex);
|
622
|
-
return this._pagePromises[pageIndex] = promise.then(function (_ref10) {
|
623
|
-
var _ref11 = _slicedToArray(_ref10, 2),
|
624
|
-
pageDict = _ref11[0],
|
625
|
-
ref = _ref11[1];
|
626
|
-
|
627
|
-
return new Page({
|
628
|
-
pdfManager: _this5.pdfManager,
|
629
|
-
xref: _this5.xref,
|
630
|
-
pageIndex: pageIndex,
|
631
|
-
pageDict: pageDict,
|
632
|
-
ref: ref,
|
633
|
-
fontCache: catalog.fontCache,
|
634
|
-
builtInCMapCache: catalog.builtInCMapCache,
|
635
|
-
pdfFunctionFactory: _this5.pdfFunctionFactory
|
636
|
-
});
|
637
|
-
});
|
638
561
|
}
|
639
|
-
}, {
|
640
|
-
key: "checkFirstPage",
|
641
|
-
value: function checkFirstPage() {
|
642
|
-
var _this6 = this;
|
643
562
|
|
644
|
-
|
645
|
-
|
646
|
-
_this6._pagePromises.length = 0;
|
563
|
+
return (0, _util.shadow)(this, "startXRef", startXRef);
|
564
|
+
}
|
647
565
|
|
648
|
-
|
566
|
+
checkHeader() {
|
567
|
+
const stream = this.stream;
|
568
|
+
stream.reset();
|
649
569
|
|
650
|
-
|
651
|
-
|
652
|
-
});
|
653
|
-
}
|
654
|
-
}, {
|
655
|
-
key: "fontFallback",
|
656
|
-
value: function fontFallback(id, handler) {
|
657
|
-
return this.catalog.fontFallback(id, handler);
|
570
|
+
if (!find(stream, PDF_HEADER_SIGNATURE)) {
|
571
|
+
return;
|
658
572
|
}
|
659
|
-
}, {
|
660
|
-
key: "cleanup",
|
661
|
-
value: function cleanup() {
|
662
|
-
return this.catalog.cleanup();
|
663
|
-
}
|
664
|
-
}, {
|
665
|
-
key: "linearization",
|
666
|
-
get: function get() {
|
667
|
-
var linearization = null;
|
668
|
-
|
669
|
-
try {
|
670
|
-
linearization = _parser.Linearization.create(this.stream);
|
671
|
-
} catch (err) {
|
672
|
-
if (err instanceof _core_utils.MissingDataException) {
|
673
|
-
throw err;
|
674
|
-
}
|
675
573
|
|
676
|
-
|
574
|
+
stream.moveStart();
|
575
|
+
const MAX_PDF_VERSION_LENGTH = 12;
|
576
|
+
let version = "",
|
577
|
+
ch;
|
578
|
+
|
579
|
+
while ((ch = stream.getByte()) > 0x20) {
|
580
|
+
if (version.length >= MAX_PDF_VERSION_LENGTH) {
|
581
|
+
break;
|
677
582
|
}
|
678
583
|
|
679
|
-
|
584
|
+
version += String.fromCharCode(ch);
|
680
585
|
}
|
681
|
-
}, {
|
682
|
-
key: "startXRef",
|
683
|
-
get: function get() {
|
684
|
-
var stream = this.stream;
|
685
|
-
var startXRef = 0;
|
686
586
|
|
687
|
-
|
688
|
-
|
587
|
+
if (!this._version) {
|
588
|
+
this._version = version.substring(5);
|
589
|
+
}
|
590
|
+
}
|
689
591
|
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
} else {
|
694
|
-
var step = 1024;
|
695
|
-
var startXRefLength = 'startxref'.length;
|
696
|
-
var found = false,
|
697
|
-
pos = stream.end;
|
592
|
+
parseStartXRef() {
|
593
|
+
this.xref.setStartXRef(this.startXRef);
|
594
|
+
}
|
698
595
|
|
699
|
-
|
700
|
-
|
596
|
+
get numPages() {
|
597
|
+
const linearization = this.linearization;
|
598
|
+
const num = linearization ? linearization.numPages : this.catalog.numPages;
|
599
|
+
return (0, _util.shadow)(this, "numPages", num);
|
600
|
+
}
|
701
601
|
|
702
|
-
|
703
|
-
|
704
|
-
|
602
|
+
_hasOnlyDocumentSignatures(fields, recursionDepth = 0) {
|
603
|
+
const RECURSION_LIMIT = 10;
|
604
|
+
return fields.every(field => {
|
605
|
+
field = this.xref.fetchIfRef(field);
|
705
606
|
|
706
|
-
|
707
|
-
|
607
|
+
if (field.has("Kids")) {
|
608
|
+
if (++recursionDepth > RECURSION_LIMIT) {
|
609
|
+
(0, _util.warn)("_hasOnlyDocumentSignatures: maximum recursion depth reached");
|
610
|
+
return false;
|
708
611
|
}
|
709
612
|
|
710
|
-
|
711
|
-
|
712
|
-
var ch;
|
613
|
+
return this._hasOnlyDocumentSignatures(field.get("Kids"), recursionDepth);
|
614
|
+
}
|
713
615
|
|
714
|
-
|
715
|
-
|
716
|
-
|
616
|
+
const isSignature = (0, _primitives.isName)(field.get("FT"), "Sig");
|
617
|
+
const rectangle = field.get("Rect");
|
618
|
+
const isInvisible = Array.isArray(rectangle) && rectangle.every(value => value === 0);
|
619
|
+
return isSignature && isInvisible;
|
620
|
+
});
|
621
|
+
}
|
717
622
|
|
718
|
-
|
623
|
+
get formInfo() {
|
624
|
+
const formInfo = {
|
625
|
+
hasAcroForm: false,
|
626
|
+
hasXfa: false
|
627
|
+
};
|
628
|
+
const acroForm = this.catalog.acroForm;
|
719
629
|
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
}
|
630
|
+
if (!acroForm) {
|
631
|
+
return (0, _util.shadow)(this, "formInfo", formInfo);
|
632
|
+
}
|
724
633
|
|
725
|
-
|
634
|
+
try {
|
635
|
+
const xfa = acroForm.get("XFA");
|
636
|
+
const hasXfa = Array.isArray(xfa) && xfa.length > 0 || (0, _primitives.isStream)(xfa) && !xfa.isEmpty;
|
637
|
+
formInfo.hasXfa = hasXfa;
|
638
|
+
const fields = acroForm.get("Fields");
|
639
|
+
const hasFields = Array.isArray(fields) && fields.length > 0;
|
640
|
+
const sigFlags = acroForm.get("SigFlags");
|
726
641
|
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
642
|
+
const hasOnlyDocumentSignatures = !!(sigFlags & 0x1) && this._hasOnlyDocumentSignatures(fields);
|
643
|
+
|
644
|
+
formInfo.hasAcroForm = hasFields && !hasOnlyDocumentSignatures;
|
645
|
+
} catch (ex) {
|
646
|
+
if (ex instanceof _core_utils.MissingDataException) {
|
647
|
+
throw ex;
|
731
648
|
}
|
732
649
|
|
733
|
-
|
650
|
+
(0, _util.info)("Cannot fetch form information.");
|
734
651
|
}
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
652
|
+
|
653
|
+
return (0, _util.shadow)(this, "formInfo", formInfo);
|
654
|
+
}
|
655
|
+
|
656
|
+
get documentInfo() {
|
657
|
+
const DocumentInfoValidators = {
|
658
|
+
Title: _util.isString,
|
659
|
+
Author: _util.isString,
|
660
|
+
Subject: _util.isString,
|
661
|
+
Keywords: _util.isString,
|
662
|
+
Creator: _util.isString,
|
663
|
+
Producer: _util.isString,
|
664
|
+
CreationDate: _util.isString,
|
665
|
+
ModDate: _util.isString,
|
666
|
+
Trapped: _primitives.isName
|
667
|
+
};
|
668
|
+
let version = this._version;
|
669
|
+
|
670
|
+
if (typeof version !== "string" || !PDF_HEADER_VERSION_REGEXP.test(version)) {
|
671
|
+
(0, _util.warn)(`Invalid PDF header version number: ${version}`);
|
672
|
+
version = null;
|
741
673
|
}
|
742
|
-
}, {
|
743
|
-
key: "documentInfo",
|
744
|
-
get: function get() {
|
745
|
-
var DocumentInfoValidators = {
|
746
|
-
Title: _util.isString,
|
747
|
-
Author: _util.isString,
|
748
|
-
Subject: _util.isString,
|
749
|
-
Keywords: _util.isString,
|
750
|
-
Creator: _util.isString,
|
751
|
-
Producer: _util.isString,
|
752
|
-
CreationDate: _util.isString,
|
753
|
-
ModDate: _util.isString,
|
754
|
-
Trapped: _primitives.isName
|
755
|
-
};
|
756
|
-
var docInfo = {
|
757
|
-
PDFFormatVersion: this.pdfFormatVersion,
|
758
|
-
IsLinearized: !!this.linearization,
|
759
|
-
IsAcroFormPresent: !!this.acroForm,
|
760
|
-
IsXFAPresent: !!this.xfa,
|
761
|
-
IsCollectionPresent: !!this.collection
|
762
|
-
};
|
763
|
-
var infoDict;
|
764
|
-
|
765
|
-
try {
|
766
|
-
infoDict = this.xref.trailer.get('Info');
|
767
|
-
} catch (err) {
|
768
|
-
if (err instanceof _core_utils.MissingDataException) {
|
769
|
-
throw err;
|
770
|
-
}
|
771
674
|
|
772
|
-
|
675
|
+
const docInfo = {
|
676
|
+
PDFFormatVersion: version,
|
677
|
+
IsLinearized: !!this.linearization,
|
678
|
+
IsAcroFormPresent: this.formInfo.hasAcroForm,
|
679
|
+
IsXFAPresent: this.formInfo.hasXfa,
|
680
|
+
IsCollectionPresent: !!this.catalog.collection
|
681
|
+
};
|
682
|
+
let infoDict;
|
683
|
+
|
684
|
+
try {
|
685
|
+
infoDict = this.xref.trailer.get("Info");
|
686
|
+
} catch (err) {
|
687
|
+
if (err instanceof _core_utils.MissingDataException) {
|
688
|
+
throw err;
|
773
689
|
}
|
774
690
|
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
docInfo[key] = typeof value !== 'string' ? value : (0, _util.stringToPDFString)(value);
|
788
|
-
} else {
|
789
|
-
(0, _util.info)("Bad value in document info for \"".concat(key, "\"."));
|
790
|
-
}
|
791
|
-
} else if (typeof key === 'string') {
|
792
|
-
var customValue = void 0;
|
793
|
-
|
794
|
-
if ((0, _util.isString)(value)) {
|
795
|
-
customValue = (0, _util.stringToPDFString)(value);
|
796
|
-
} else if ((0, _primitives.isName)(value) || (0, _util.isNum)(value) || (0, _util.isBool)(value)) {
|
797
|
-
customValue = value;
|
798
|
-
} else {
|
799
|
-
(0, _util.info)("Unsupported value in document info for (custom) \"".concat(key, "\"."));
|
800
|
-
continue;
|
801
|
-
}
|
802
|
-
|
803
|
-
if (!docInfo['Custom']) {
|
804
|
-
docInfo['Custom'] = Object.create(null);
|
805
|
-
}
|
806
|
-
|
807
|
-
docInfo['Custom'][key] = customValue;
|
808
|
-
}
|
691
|
+
(0, _util.info)("The document information dictionary is invalid.");
|
692
|
+
}
|
693
|
+
|
694
|
+
if ((0, _primitives.isDict)(infoDict)) {
|
695
|
+
for (const key of infoDict.getKeys()) {
|
696
|
+
const value = infoDict.get(key);
|
697
|
+
|
698
|
+
if (DocumentInfoValidators[key]) {
|
699
|
+
if (DocumentInfoValidators[key](value)) {
|
700
|
+
docInfo[key] = typeof value !== "string" ? value : (0, _util.stringToPDFString)(value);
|
701
|
+
} else {
|
702
|
+
(0, _util.info)(`Bad value in document info for "${key}".`);
|
809
703
|
}
|
810
|
-
}
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
throw _iteratorError4;
|
821
|
-
}
|
704
|
+
} else if (typeof key === "string") {
|
705
|
+
let customValue;
|
706
|
+
|
707
|
+
if ((0, _util.isString)(value)) {
|
708
|
+
customValue = (0, _util.stringToPDFString)(value);
|
709
|
+
} else if ((0, _primitives.isName)(value) || (0, _util.isNum)(value) || (0, _util.isBool)(value)) {
|
710
|
+
customValue = value;
|
711
|
+
} else {
|
712
|
+
(0, _util.info)(`Unsupported value in document info for (custom) "${key}".`);
|
713
|
+
continue;
|
822
714
|
}
|
715
|
+
|
716
|
+
if (!docInfo.Custom) {
|
717
|
+
docInfo.Custom = Object.create(null);
|
718
|
+
}
|
719
|
+
|
720
|
+
docInfo.Custom[key] = customValue;
|
823
721
|
}
|
824
722
|
}
|
723
|
+
}
|
825
724
|
|
826
|
-
|
725
|
+
return (0, _util.shadow)(this, "documentInfo", docInfo);
|
726
|
+
}
|
727
|
+
|
728
|
+
get fingerprint() {
|
729
|
+
let hash;
|
730
|
+
const idArray = this.xref.trailer.get("ID");
|
731
|
+
|
732
|
+
if (Array.isArray(idArray) && idArray[0] && (0, _util.isString)(idArray[0]) && idArray[0] !== EMPTY_FINGERPRINT) {
|
733
|
+
hash = (0, _util.stringToBytes)(idArray[0]);
|
734
|
+
} else {
|
735
|
+
hash = (0, _crypto.calculateMD5)(this.stream.getByteRange(0, FINGERPRINT_FIRST_BYTES), 0, FINGERPRINT_FIRST_BYTES);
|
827
736
|
}
|
828
|
-
|
829
|
-
|
830
|
-
|
831
|
-
|
832
|
-
|
833
|
-
|
834
|
-
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
737
|
+
|
738
|
+
const fingerprintBuf = [];
|
739
|
+
|
740
|
+
for (let i = 0, ii = hash.length; i < ii; i++) {
|
741
|
+
const hex = hash[i].toString(16);
|
742
|
+
fingerprintBuf.push(hex.padStart(2, "0"));
|
743
|
+
}
|
744
|
+
|
745
|
+
return (0, _util.shadow)(this, "fingerprint", fingerprintBuf.join(""));
|
746
|
+
}
|
747
|
+
|
748
|
+
_getLinearizationPage(pageIndex) {
|
749
|
+
const {
|
750
|
+
catalog,
|
751
|
+
linearization
|
752
|
+
} = this;
|
753
|
+
|
754
|
+
const ref = _primitives.Ref.get(linearization.objectNumberFirst, 0);
|
755
|
+
|
756
|
+
return this.xref.fetchAsync(ref).then(obj => {
|
757
|
+
if ((0, _primitives.isDict)(obj, "Page") || (0, _primitives.isDict)(obj) && !obj.has("Type") && obj.has("Contents")) {
|
758
|
+
if (ref && !catalog.pageKidsCountCache.has(ref)) {
|
759
|
+
catalog.pageKidsCountCache.put(ref, 1);
|
839
760
|
}
|
840
761
|
|
841
|
-
|
762
|
+
return [obj, ref];
|
842
763
|
}
|
843
764
|
|
844
|
-
|
765
|
+
throw new _util.FormatError("The Linearization dictionary doesn't point " + "to a valid Page dictionary.");
|
766
|
+
}).catch(reason => {
|
767
|
+
(0, _util.info)(reason);
|
768
|
+
return catalog.getPageDict(pageIndex);
|
769
|
+
});
|
770
|
+
}
|
845
771
|
|
846
|
-
|
847
|
-
|
848
|
-
|
772
|
+
getPage(pageIndex) {
|
773
|
+
if (this._pagePromises[pageIndex] !== undefined) {
|
774
|
+
return this._pagePromises[pageIndex];
|
775
|
+
}
|
776
|
+
|
777
|
+
const {
|
778
|
+
catalog,
|
779
|
+
linearization
|
780
|
+
} = this;
|
781
|
+
const promise = linearization && linearization.pageFirst === pageIndex ? this._getLinearizationPage(pageIndex) : catalog.getPageDict(pageIndex);
|
782
|
+
return this._pagePromises[pageIndex] = promise.then(([pageDict, ref]) => {
|
783
|
+
return new Page({
|
784
|
+
pdfManager: this.pdfManager,
|
785
|
+
xref: this.xref,
|
786
|
+
pageIndex,
|
787
|
+
pageDict,
|
788
|
+
ref,
|
789
|
+
globalIdFactory: this._globalIdFactory,
|
790
|
+
fontCache: catalog.fontCache,
|
791
|
+
builtInCMapCache: catalog.builtInCMapCache,
|
792
|
+
globalImageCache: catalog.globalImageCache
|
793
|
+
});
|
794
|
+
});
|
795
|
+
}
|
796
|
+
|
797
|
+
checkFirstPage() {
|
798
|
+
return this.getPage(0).catch(async reason => {
|
799
|
+
if (reason instanceof _core_utils.XRefEntryException) {
|
800
|
+
this._pagePromises.length = 0;
|
801
|
+
await this.cleanup();
|
802
|
+
throw new _core_utils.XRefParseException();
|
849
803
|
}
|
804
|
+
});
|
805
|
+
}
|
850
806
|
|
851
|
-
|
852
|
-
|
853
|
-
}
|
807
|
+
fontFallback(id, handler) {
|
808
|
+
return this.catalog.fontFallback(id, handler);
|
809
|
+
}
|
854
810
|
|
855
|
-
|
856
|
-
|
811
|
+
async cleanup(manuallyTriggered = false) {
|
812
|
+
return this.catalog ? this.catalog.cleanup(manuallyTriggered) : (0, _primitives.clearPrimitiveCaches)();
|
813
|
+
}
|
814
|
+
|
815
|
+
}
|
857
816
|
|
858
817
|
exports.PDFDocument = PDFDocument;
|