pdfjs-dist 2.1.266 → 2.5.207
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of pdfjs-dist might be problematic. Click here for more details.
- package/CODE_OF_CONDUCT.md +15 -0
- package/README.md +4 -0
- package/bower.json +1 -1
- package/build/pdf.js +8382 -18492
- 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 +20417 -29816
- package/build/pdf.worker.js.map +1 -1
- package/build/pdf.worker.min.js +22 -1
- package/es5/build/pdf.js +25688 -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 +58239 -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 +403 -0
- package/es5/web/pdf_viewer.js +7742 -0
- package/es5/web/pdf_viewer.js.map +1 -0
- package/image_decoders/pdf.image_decoders.js +1475 -4897
- 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 +750 -899
- 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 +235 -183
- package/lib/core/charsets.js +4 -4
- package/lib/core/chunked_stream.js +447 -542
- package/lib/core/cmap.js +222 -264
- package/lib/core/colorspace.js +699 -863
- package/lib/core/core_utils.js +152 -0
- package/lib/core/crypto.js +379 -437
- package/lib/core/document.js +573 -660
- package/lib/core/encodings.js +15 -15
- package/lib/core/evaluator.js +1103 -868
- package/lib/core/font_renderer.js +135 -178
- package/lib/core/fonts.js +570 -491
- package/lib/core/function.js +291 -288
- package/lib/core/glyphlist.js +4527 -4526
- package/lib/core/image.js +145 -149
- package/lib/core/image_utils.js +170 -0
- 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 +284 -232
- package/lib/core/jpx.js +161 -143
- package/lib/core/jpx_stream.js +28 -28
- package/lib/core/metrics.js +2929 -2929
- package/lib/core/murmurhash3.js +90 -101
- package/lib/core/obj.js +1183 -1157
- package/lib/core/operator_list.js +99 -67
- package/lib/core/parser.js +972 -911
- package/lib/core/pattern.js +87 -70
- package/lib/core/pdf_manager.js +150 -315
- package/lib/core/primitives.js +83 -56
- 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 +87 -69
- package/lib/core/unicode.js +1654 -1654
- package/lib/core/worker.js +193 -390
- package/lib/core/worker_stream.js +168 -0
- package/lib/display/annotation_layer.js +741 -972
- package/lib/display/api.js +1500 -1791
- package/lib/display/api_compatibility.js +12 -17
- package/lib/display/canvas.js +165 -165
- package/lib/display/content_disposition.js +40 -59
- package/lib/display/display_utils.js +515 -0
- package/lib/display/fetch_stream.js +183 -298
- package/lib/display/font_loader.js +273 -413
- package/lib/display/metadata.js +86 -98
- package/lib/display/network.js +266 -359
- package/lib/display/network_utils.js +25 -18
- package/lib/display/node_stream.js +285 -458
- package/lib/display/pattern_helper.js +113 -65
- package/lib/display/svg.js +1166 -901
- package/lib/display/text_layer.js +156 -132
- package/lib/display/transport_stream.js +262 -278
- 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 +40 -37
- package/lib/pdf.js +226 -59
- 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 +266 -416
- package/lib/test/unit/annotation_spec.js +1555 -701
- package/lib/test/unit/api_spec.js +802 -604
- package/lib/test/unit/bidi_spec.js +7 -7
- package/lib/test/unit/cff_parser_spec.js +84 -69
- package/lib/test/unit/clitests_helper.js +7 -9
- package/lib/test/unit/cmap_spec.js +74 -76
- package/lib/test/unit/colorspace_spec.js +166 -161
- package/lib/test/unit/core_utils_spec.js +211 -0
- package/lib/test/unit/crypto_spec.js +181 -181
- package/lib/test/unit/custom_spec.js +20 -22
- package/lib/test/unit/display_svg_spec.js +34 -39
- package/lib/test/unit/display_utils_spec.js +263 -0
- package/lib/test/unit/document_spec.js +16 -21
- package/lib/test/unit/encodings_spec.js +12 -34
- package/lib/test/unit/evaluator_spec.js +83 -83
- package/lib/test/unit/fetch_stream_spec.js +111 -0
- package/lib/test/unit/function_spec.js +206 -204
- package/lib/test/unit/jasmine-boot.js +46 -30
- package/lib/test/unit/message_handler_spec.js +173 -159
- 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 +13 -61
- package/lib/test/unit/network_utils_spec.js +183 -119
- package/lib/test/unit/node_stream_spec.js +78 -92
- package/lib/test/unit/parser_spec.js +172 -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 +140 -125
- package/lib/test/unit/stream_spec.js +16 -14
- package/lib/test/unit/test_utils.js +131 -143
- package/lib/test/unit/testreporter.js +19 -19
- package/lib/test/unit/type1_parser_spec.js +42 -42
- package/lib/test/unit/ui_utils_spec.js +297 -459
- package/lib/test/unit/unicode_spec.js +38 -38
- package/lib/test/unit/util_spec.js +121 -305
- package/lib/web/annotation_layer_builder.js +66 -103
- package/lib/web/app.js +1328 -1214
- package/lib/web/app_options.js +105 -107
- package/lib/web/base_viewer.js +824 -838
- package/lib/web/chromecom.js +165 -252
- package/lib/web/debugger.js +149 -205
- package/lib/web/download_manager.js +39 -55
- package/lib/web/firefox_print_service.js +37 -27
- package/lib/web/firefoxcom.js +212 -363
- package/lib/web/genericcom.js +26 -108
- package/lib/web/genericl10n.js +24 -153
- package/lib/web/grab_to_pan.js +32 -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 +113 -131
- package/lib/web/pdf_cursor_tools.js +75 -102
- package/lib/web/pdf_document_properties.js +221 -306
- package/lib/web/pdf_find_bar.js +136 -170
- package/lib/web/pdf_find_controller.js +491 -548
- package/lib/web/pdf_find_utils.js +13 -13
- package/lib/web/pdf_history.js +397 -406
- package/lib/web/pdf_link_service.js +304 -348
- package/lib/web/pdf_outline_viewer.js +140 -175
- package/lib/web/pdf_page_view.js +452 -523
- package/lib/web/pdf_presentation_mode.js +308 -357
- package/lib/web/pdf_print_service.js +90 -104
- package/lib/web/pdf_rendering_queue.js +84 -108
- package/lib/web/pdf_sidebar.js +276 -306
- 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 +82 -286
- package/lib/web/secondary_toolbar.js +164 -196
- package/lib/web/text_layer_builder.js +282 -339
- package/lib/web/toolbar.js +217 -210
- package/lib/web/ui_utils.js +267 -420
- package/lib/web/view_history.js +52 -226
- package/lib/web/viewer_compatibility.js +21 -6
- package/package.json +2 -9
- package/web/pdf_viewer.css +35 -25
- package/web/pdf_viewer.js +3489 -4855
- package/web/pdf_viewer.js.map +1 -1
- package/webpack.js +14 -5
- package/external/streams/streams-lib.js +0 -3962
- package/external/url/url-lib.js +0 -627
- package/lib/display/dom_utils.js +0 -494
- package/lib/shared/streams_polyfill.js +0 -43
- package/lib/shared/url_polyfill.js +0 -56
- package/lib/test/unit/dom_utils_spec.js +0 -89
package/lib/core/obj.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,1018 +26,1105 @@ Object.defineProperty(exports, "__esModule", {
|
|
26
26
|
});
|
27
27
|
exports.FileSpec = exports.XRef = exports.ObjectLoader = exports.Catalog = void 0;
|
28
28
|
|
29
|
-
var
|
29
|
+
var _util = require("../shared/util.js");
|
30
30
|
|
31
|
-
var
|
31
|
+
var _primitives = require("./primitives.js");
|
32
32
|
|
33
|
-
var
|
33
|
+
var _parser = require("./parser.js");
|
34
34
|
|
35
|
-
var
|
35
|
+
var _core_utils = require("./core_utils.js");
|
36
36
|
|
37
|
-
var
|
37
|
+
var _crypto = require("./crypto.js");
|
38
38
|
|
39
|
-
var
|
39
|
+
var _colorspace = require("./colorspace.js");
|
40
40
|
|
41
|
-
var
|
41
|
+
var _image_utils = require("./image_utils.js");
|
42
42
|
|
43
|
-
function
|
43
|
+
function fetchDestination(dest) {
|
44
|
+
return (0, _primitives.isDict)(dest) ? dest.get("D") : dest;
|
45
|
+
}
|
44
46
|
|
45
|
-
|
47
|
+
class Catalog {
|
48
|
+
constructor(pdfManager, xref) {
|
49
|
+
this.pdfManager = pdfManager;
|
50
|
+
this.xref = xref;
|
51
|
+
this.catDict = xref.getCatalogObj();
|
46
52
|
|
47
|
-
|
53
|
+
if (!(0, _primitives.isDict)(this.catDict)) {
|
54
|
+
throw new _util.FormatError("Catalog object is not a dictionary.");
|
55
|
+
}
|
48
56
|
|
49
|
-
|
57
|
+
this.fontCache = new _primitives.RefSetCache();
|
58
|
+
this.builtInCMapCache = new Map();
|
59
|
+
this.globalImageCache = new _image_utils.GlobalImageCache();
|
60
|
+
this.pageKidsCountCache = new _primitives.RefSetCache();
|
61
|
+
}
|
50
62
|
|
51
|
-
|
63
|
+
get metadata() {
|
64
|
+
const streamRef = this.catDict.getRaw("Metadata");
|
52
65
|
|
53
|
-
|
66
|
+
if (!(0, _primitives.isRef)(streamRef)) {
|
67
|
+
return (0, _util.shadow)(this, "metadata", null);
|
68
|
+
}
|
54
69
|
|
55
|
-
|
70
|
+
const suppressEncryption = !(this.xref.encrypt && this.xref.encrypt.encryptMetadata);
|
71
|
+
const stream = this.xref.fetch(streamRef, suppressEncryption);
|
72
|
+
let metadata;
|
56
73
|
|
57
|
-
|
74
|
+
if (stream && (0, _primitives.isDict)(stream.dict)) {
|
75
|
+
const type = stream.dict.get("Type");
|
76
|
+
const subtype = stream.dict.get("Subtype");
|
58
77
|
|
59
|
-
|
78
|
+
if ((0, _primitives.isName)(type, "Metadata") && (0, _primitives.isName)(subtype, "XML")) {
|
79
|
+
try {
|
80
|
+
metadata = (0, _util.stringToUTF8String)((0, _util.bytesToString)(stream.getBytes()));
|
81
|
+
} catch (e) {
|
82
|
+
if (e instanceof _core_utils.MissingDataException) {
|
83
|
+
throw e;
|
84
|
+
}
|
60
85
|
|
61
|
-
|
86
|
+
(0, _util.info)("Skipping invalid metadata.");
|
87
|
+
}
|
88
|
+
}
|
89
|
+
}
|
62
90
|
|
63
|
-
|
91
|
+
return (0, _util.shadow)(this, "metadata", metadata);
|
92
|
+
}
|
64
93
|
|
65
|
-
|
94
|
+
get toplevelPagesDict() {
|
95
|
+
const pagesObj = this.catDict.get("Pages");
|
66
96
|
|
67
|
-
|
97
|
+
if (!(0, _primitives.isDict)(pagesObj)) {
|
98
|
+
throw new _util.FormatError("Invalid top-level pages dictionary.");
|
99
|
+
}
|
68
100
|
|
69
|
-
|
101
|
+
return (0, _util.shadow)(this, "toplevelPagesDict", pagesObj);
|
102
|
+
}
|
70
103
|
|
71
|
-
|
104
|
+
get documentOutline() {
|
105
|
+
let obj = null;
|
72
106
|
|
73
|
-
|
107
|
+
try {
|
108
|
+
obj = this._readDocumentOutline();
|
109
|
+
} catch (ex) {
|
110
|
+
if (ex instanceof _core_utils.MissingDataException) {
|
111
|
+
throw ex;
|
112
|
+
}
|
74
113
|
|
75
|
-
|
76
|
-
|
77
|
-
}
|
114
|
+
(0, _util.warn)("Unable to read document outline.");
|
115
|
+
}
|
78
116
|
|
79
|
-
|
80
|
-
|
81
|
-
function () {
|
82
|
-
function Catalog(pdfManager, xref) {
|
83
|
-
_classCallCheck(this, Catalog);
|
117
|
+
return (0, _util.shadow)(this, "documentOutline", obj);
|
118
|
+
}
|
84
119
|
|
85
|
-
|
86
|
-
|
87
|
-
this.catDict = xref.getCatalogObj();
|
120
|
+
_readDocumentOutline() {
|
121
|
+
let obj = this.catDict.get("Outlines");
|
88
122
|
|
89
|
-
if (!(0, _primitives.isDict)(
|
90
|
-
|
123
|
+
if (!(0, _primitives.isDict)(obj)) {
|
124
|
+
return null;
|
91
125
|
}
|
92
126
|
|
93
|
-
|
94
|
-
this.builtInCMapCache = new Map();
|
95
|
-
this.pageKidsCountCache = new _primitives.RefSetCache();
|
96
|
-
}
|
127
|
+
obj = obj.getRaw("First");
|
97
128
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
var obj = this.catDict.get('Outlines');
|
129
|
+
if (!(0, _primitives.isRef)(obj)) {
|
130
|
+
return null;
|
131
|
+
}
|
102
132
|
|
103
|
-
|
104
|
-
|
105
|
-
|
133
|
+
const root = {
|
134
|
+
items: []
|
135
|
+
};
|
136
|
+
const queue = [{
|
137
|
+
obj,
|
138
|
+
parent: root
|
139
|
+
}];
|
140
|
+
const processed = new _primitives.RefSet();
|
141
|
+
processed.put(obj);
|
142
|
+
const xref = this.xref,
|
143
|
+
blackColor = new Uint8ClampedArray(3);
|
106
144
|
|
107
|
-
|
145
|
+
while (queue.length > 0) {
|
146
|
+
const i = queue.shift();
|
147
|
+
const outlineDict = xref.fetchIfRef(i.obj);
|
108
148
|
|
109
|
-
if (
|
110
|
-
|
149
|
+
if (outlineDict === null) {
|
150
|
+
continue;
|
151
|
+
}
|
152
|
+
|
153
|
+
if (!outlineDict.has("Title")) {
|
154
|
+
throw new _util.FormatError("Invalid outline item encountered.");
|
111
155
|
}
|
112
156
|
|
113
|
-
|
157
|
+
const data = {
|
158
|
+
url: null,
|
159
|
+
dest: null
|
160
|
+
};
|
161
|
+
Catalog.parseDestDictionary({
|
162
|
+
destDict: outlineDict,
|
163
|
+
resultObj: data,
|
164
|
+
docBaseUrl: this.pdfManager.docBaseUrl
|
165
|
+
});
|
166
|
+
const title = outlineDict.get("Title");
|
167
|
+
const flags = outlineDict.get("F") || 0;
|
168
|
+
const color = outlineDict.getArray("C");
|
169
|
+
const count = outlineDict.get("Count");
|
170
|
+
let rgbColor = blackColor;
|
171
|
+
|
172
|
+
if (Array.isArray(color) && color.length === 3 && (color[0] !== 0 || color[1] !== 0 || color[2] !== 0)) {
|
173
|
+
rgbColor = _colorspace.ColorSpace.singletons.rgb.getRgb(color, 0);
|
174
|
+
}
|
175
|
+
|
176
|
+
const outlineItem = {
|
177
|
+
dest: data.dest,
|
178
|
+
url: data.url,
|
179
|
+
unsafeUrl: data.unsafeUrl,
|
180
|
+
newWindow: data.newWindow,
|
181
|
+
title: (0, _util.stringToPDFString)(title),
|
182
|
+
color: rgbColor,
|
183
|
+
count: Number.isInteger(count) ? count : undefined,
|
184
|
+
bold: !!(flags & 2),
|
185
|
+
italic: !!(flags & 1),
|
114
186
|
items: []
|
115
187
|
};
|
116
|
-
|
117
|
-
|
118
|
-
parent: root
|
119
|
-
}];
|
120
|
-
var processed = new _primitives.RefSet();
|
121
|
-
processed.put(obj);
|
122
|
-
var xref = this.xref,
|
123
|
-
blackColor = new Uint8ClampedArray(3);
|
188
|
+
i.parent.items.push(outlineItem);
|
189
|
+
obj = outlineDict.getRaw("First");
|
124
190
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
191
|
+
if ((0, _primitives.isRef)(obj) && !processed.has(obj)) {
|
192
|
+
queue.push({
|
193
|
+
obj,
|
194
|
+
parent: outlineItem
|
195
|
+
});
|
196
|
+
processed.put(obj);
|
197
|
+
}
|
132
198
|
|
133
|
-
|
134
|
-
throw new _util.FormatError('Invalid outline item encountered.');
|
135
|
-
}
|
199
|
+
obj = outlineDict.getRaw("Next");
|
136
200
|
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
Catalog.parseDestDictionary({
|
142
|
-
destDict: outlineDict,
|
143
|
-
resultObj: data,
|
144
|
-
docBaseUrl: this.pdfManager.docBaseUrl
|
201
|
+
if ((0, _primitives.isRef)(obj) && !processed.has(obj)) {
|
202
|
+
queue.push({
|
203
|
+
obj,
|
204
|
+
parent: i.parent
|
145
205
|
});
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
var rgbColor = blackColor;
|
150
|
-
|
151
|
-
if (Array.isArray(color) && color.length === 3 && (color[0] !== 0 || color[1] !== 0 || color[2] !== 0)) {
|
152
|
-
rgbColor = _colorspace.ColorSpace.singletons.rgb.getRgb(color, 0);
|
153
|
-
}
|
154
|
-
|
155
|
-
var outlineItem = {
|
156
|
-
dest: data.dest,
|
157
|
-
url: data.url,
|
158
|
-
unsafeUrl: data.unsafeUrl,
|
159
|
-
newWindow: data.newWindow,
|
160
|
-
title: (0, _util.stringToPDFString)(title),
|
161
|
-
color: rgbColor,
|
162
|
-
count: outlineDict.get('Count'),
|
163
|
-
bold: !!(flags & 2),
|
164
|
-
italic: !!(flags & 1),
|
165
|
-
items: []
|
166
|
-
};
|
167
|
-
i.parent.items.push(outlineItem);
|
168
|
-
obj = outlineDict.getRaw('First');
|
206
|
+
processed.put(obj);
|
207
|
+
}
|
208
|
+
}
|
169
209
|
|
170
|
-
|
171
|
-
|
172
|
-
obj: obj,
|
173
|
-
parent: outlineItem
|
174
|
-
});
|
175
|
-
processed.put(obj);
|
176
|
-
}
|
210
|
+
return root.items.length > 0 ? root.items : null;
|
211
|
+
}
|
177
212
|
|
178
|
-
|
213
|
+
get permissions() {
|
214
|
+
let permissions = null;
|
179
215
|
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
processed.put(obj);
|
186
|
-
}
|
216
|
+
try {
|
217
|
+
permissions = this._readPermissions();
|
218
|
+
} catch (ex) {
|
219
|
+
if (ex instanceof _core_utils.MissingDataException) {
|
220
|
+
throw ex;
|
187
221
|
}
|
188
222
|
|
189
|
-
|
223
|
+
(0, _util.warn)("Unable to read permissions.");
|
190
224
|
}
|
191
|
-
}, {
|
192
|
-
key: "_readPermissions",
|
193
|
-
value: function _readPermissions() {
|
194
|
-
var encrypt = this.xref.trailer.get('Encrypt');
|
195
225
|
|
196
|
-
|
197
|
-
|
198
|
-
}
|
226
|
+
return (0, _util.shadow)(this, "permissions", permissions);
|
227
|
+
}
|
199
228
|
|
200
|
-
|
229
|
+
_readPermissions() {
|
230
|
+
const encrypt = this.xref.trailer.get("Encrypt");
|
201
231
|
|
202
|
-
|
203
|
-
|
204
|
-
|
232
|
+
if (!(0, _primitives.isDict)(encrypt)) {
|
233
|
+
return null;
|
234
|
+
}
|
235
|
+
|
236
|
+
let flags = encrypt.get("P");
|
237
|
+
|
238
|
+
if (!(0, _util.isNum)(flags)) {
|
239
|
+
return null;
|
240
|
+
}
|
205
241
|
|
206
|
-
|
207
|
-
|
242
|
+
flags += 2 ** 32;
|
243
|
+
const permissions = [];
|
208
244
|
|
209
|
-
|
210
|
-
|
245
|
+
for (const key in _util.PermissionFlag) {
|
246
|
+
const value = _util.PermissionFlag[key];
|
211
247
|
|
212
|
-
|
213
|
-
|
214
|
-
}
|
248
|
+
if (flags & value) {
|
249
|
+
permissions.push(value);
|
215
250
|
}
|
251
|
+
}
|
216
252
|
|
217
|
-
|
253
|
+
return permissions;
|
254
|
+
}
|
255
|
+
|
256
|
+
get numPages() {
|
257
|
+
const obj = this.toplevelPagesDict.get("Count");
|
258
|
+
|
259
|
+
if (!Number.isInteger(obj)) {
|
260
|
+
throw new _util.FormatError("Page count in top-level pages dictionary is not an integer.");
|
218
261
|
}
|
219
|
-
}, {
|
220
|
-
key: "getDestination",
|
221
|
-
value: function getDestination(destinationId) {
|
222
|
-
var obj = this._readDests();
|
223
262
|
|
224
|
-
|
225
|
-
|
263
|
+
return (0, _util.shadow)(this, "numPages", obj);
|
264
|
+
}
|
265
|
+
|
266
|
+
get destinations() {
|
267
|
+
const obj = this._readDests(),
|
268
|
+
dests = Object.create(null);
|
269
|
+
|
270
|
+
if (obj instanceof NameTree) {
|
271
|
+
const names = obj.getAll();
|
272
|
+
|
273
|
+
for (const name in names) {
|
274
|
+
dests[name] = fetchDestination(names[name]);
|
226
275
|
}
|
276
|
+
} else if (obj instanceof _primitives.Dict) {
|
277
|
+
obj.forEach(function (key, value) {
|
278
|
+
if (value) {
|
279
|
+
dests[key] = fetchDestination(value);
|
280
|
+
}
|
281
|
+
});
|
282
|
+
}
|
227
283
|
|
228
|
-
|
284
|
+
return (0, _util.shadow)(this, "destinations", dests);
|
285
|
+
}
|
286
|
+
|
287
|
+
getDestination(destinationId) {
|
288
|
+
const obj = this._readDests();
|
289
|
+
|
290
|
+
if (obj instanceof NameTree || obj instanceof _primitives.Dict) {
|
291
|
+
return fetchDestination(obj.get(destinationId) || null);
|
229
292
|
}
|
230
|
-
}, {
|
231
|
-
key: "_readDests",
|
232
|
-
value: function _readDests() {
|
233
|
-
var obj = this.catDict.get('Names');
|
234
293
|
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
294
|
+
return null;
|
295
|
+
}
|
296
|
+
|
297
|
+
_readDests() {
|
298
|
+
const obj = this.catDict.get("Names");
|
299
|
+
|
300
|
+
if (obj && obj.has("Dests")) {
|
301
|
+
return new NameTree(obj.getRaw("Dests"), this.xref);
|
302
|
+
} else if (this.catDict.has("Dests")) {
|
303
|
+
return this.catDict.get("Dests");
|
240
304
|
}
|
241
|
-
}, {
|
242
|
-
key: "_readPageLabels",
|
243
|
-
value: function _readPageLabels() {
|
244
|
-
var obj = this.catDict.getRaw('PageLabels');
|
245
305
|
|
246
|
-
|
247
|
-
|
306
|
+
return undefined;
|
307
|
+
}
|
308
|
+
|
309
|
+
get pageLabels() {
|
310
|
+
let obj = null;
|
311
|
+
|
312
|
+
try {
|
313
|
+
obj = this._readPageLabels();
|
314
|
+
} catch (ex) {
|
315
|
+
if (ex instanceof _core_utils.MissingDataException) {
|
316
|
+
throw ex;
|
248
317
|
}
|
249
318
|
|
250
|
-
|
251
|
-
|
252
|
-
prefix = '';
|
253
|
-
var numberTree = new NumberTree(obj, this.xref);
|
254
|
-
var nums = numberTree.getAll();
|
255
|
-
var currentLabel = '',
|
256
|
-
currentIndex = 1;
|
319
|
+
(0, _util.warn)("Unable to read page labels.");
|
320
|
+
}
|
257
321
|
|
258
|
-
|
259
|
-
|
260
|
-
var labelDict = nums[i];
|
322
|
+
return (0, _util.shadow)(this, "pageLabels", obj);
|
323
|
+
}
|
261
324
|
|
262
|
-
|
263
|
-
|
264
|
-
}
|
325
|
+
_readPageLabels() {
|
326
|
+
const obj = this.catDict.getRaw("PageLabels");
|
265
327
|
|
266
|
-
|
267
|
-
|
268
|
-
|
328
|
+
if (!obj) {
|
329
|
+
return null;
|
330
|
+
}
|
269
331
|
|
270
|
-
|
271
|
-
|
332
|
+
const pageLabels = new Array(this.numPages);
|
333
|
+
let style = null,
|
334
|
+
prefix = "";
|
335
|
+
const numberTree = new NumberTree(obj, this.xref);
|
336
|
+
const nums = numberTree.getAll();
|
337
|
+
let currentLabel = "",
|
338
|
+
currentIndex = 1;
|
272
339
|
|
273
|
-
|
274
|
-
|
275
|
-
|
340
|
+
for (let i = 0, ii = this.numPages; i < ii; i++) {
|
341
|
+
if (i in nums) {
|
342
|
+
const labelDict = nums[i];
|
276
343
|
|
277
|
-
|
278
|
-
|
279
|
-
|
344
|
+
if (!(0, _primitives.isDict)(labelDict)) {
|
345
|
+
throw new _util.FormatError("PageLabel is not a dictionary.");
|
346
|
+
}
|
347
|
+
|
348
|
+
if (labelDict.has("Type") && !(0, _primitives.isName)(labelDict.get("Type"), "PageLabel")) {
|
349
|
+
throw new _util.FormatError("Invalid type in PageLabel dictionary.");
|
350
|
+
}
|
351
|
+
|
352
|
+
if (labelDict.has("S")) {
|
353
|
+
const s = labelDict.get("S");
|
354
|
+
|
355
|
+
if (!(0, _primitives.isName)(s)) {
|
356
|
+
throw new _util.FormatError("Invalid style in PageLabel dictionary.");
|
280
357
|
}
|
281
358
|
|
282
|
-
|
283
|
-
|
359
|
+
style = s.name;
|
360
|
+
} else {
|
361
|
+
style = null;
|
362
|
+
}
|
284
363
|
|
285
|
-
|
286
|
-
|
287
|
-
}
|
364
|
+
if (labelDict.has("P")) {
|
365
|
+
const p = labelDict.get("P");
|
288
366
|
|
289
|
-
|
290
|
-
|
291
|
-
prefix = '';
|
367
|
+
if (!(0, _util.isString)(p)) {
|
368
|
+
throw new _util.FormatError("Invalid prefix in PageLabel dictionary.");
|
292
369
|
}
|
293
370
|
|
294
|
-
|
295
|
-
|
371
|
+
prefix = (0, _util.stringToPDFString)(p);
|
372
|
+
} else {
|
373
|
+
prefix = "";
|
374
|
+
}
|
296
375
|
|
297
|
-
|
298
|
-
|
299
|
-
}
|
376
|
+
if (labelDict.has("St")) {
|
377
|
+
const st = labelDict.get("St");
|
300
378
|
|
301
|
-
|
302
|
-
|
303
|
-
currentIndex = 1;
|
379
|
+
if (!(Number.isInteger(st) && st >= 1)) {
|
380
|
+
throw new _util.FormatError("Invalid start in PageLabel dictionary.");
|
304
381
|
}
|
382
|
+
|
383
|
+
currentIndex = st;
|
384
|
+
} else {
|
385
|
+
currentIndex = 1;
|
305
386
|
}
|
387
|
+
}
|
306
388
|
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
389
|
+
switch (style) {
|
390
|
+
case "D":
|
391
|
+
currentLabel = currentIndex;
|
392
|
+
break;
|
311
393
|
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
394
|
+
case "R":
|
395
|
+
case "r":
|
396
|
+
currentLabel = (0, _core_utils.toRomanNumerals)(currentIndex, style === "r");
|
397
|
+
break;
|
316
398
|
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
399
|
+
case "A":
|
400
|
+
case "a":
|
401
|
+
const LIMIT = 26;
|
402
|
+
const A_UPPER_CASE = 0x41,
|
321
403
|
A_LOWER_CASE = 0x61;
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
404
|
+
const baseCharCode = style === "a" ? A_LOWER_CASE : A_UPPER_CASE;
|
405
|
+
const letterIndex = currentIndex - 1;
|
406
|
+
const character = String.fromCharCode(baseCharCode + letterIndex % LIMIT);
|
407
|
+
const charBuf = [];
|
326
408
|
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
currentLabel = charBuf.join('');
|
332
|
-
break;
|
409
|
+
for (let j = 0, jj = letterIndex / LIMIT | 0; j <= jj; j++) {
|
410
|
+
charBuf.push(character);
|
411
|
+
}
|
333
412
|
|
334
|
-
|
335
|
-
|
336
|
-
throw new _util.FormatError("Invalid style \"".concat(style, "\" in PageLabel dictionary."));
|
337
|
-
}
|
413
|
+
currentLabel = charBuf.join("");
|
414
|
+
break;
|
338
415
|
|
339
|
-
|
340
|
-
|
416
|
+
default:
|
417
|
+
if (style) {
|
418
|
+
throw new _util.FormatError(`Invalid style "${style}" in PageLabel dictionary.`);
|
419
|
+
}
|
341
420
|
|
342
|
-
|
343
|
-
currentIndex++;
|
421
|
+
currentLabel = "";
|
344
422
|
}
|
345
423
|
|
346
|
-
|
424
|
+
pageLabels[i] = prefix + currentLabel;
|
425
|
+
currentIndex++;
|
347
426
|
}
|
348
|
-
}, {
|
349
|
-
key: "fontFallback",
|
350
|
-
value: function fontFallback(id, handler) {
|
351
|
-
var promises = [];
|
352
|
-
this.fontCache.forEach(function (promise) {
|
353
|
-
promises.push(promise);
|
354
|
-
});
|
355
|
-
return Promise.all(promises).then(function (translatedFonts) {
|
356
|
-
var _iteratorNormalCompletion = true;
|
357
|
-
var _didIteratorError = false;
|
358
|
-
var _iteratorError = undefined;
|
359
|
-
|
360
|
-
try {
|
361
|
-
for (var _iterator = translatedFonts[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
362
|
-
var translatedFont = _step.value;
|
363
427
|
|
364
|
-
|
365
|
-
|
366
|
-
return;
|
367
|
-
}
|
368
|
-
}
|
369
|
-
} catch (err) {
|
370
|
-
_didIteratorError = true;
|
371
|
-
_iteratorError = err;
|
372
|
-
} finally {
|
373
|
-
try {
|
374
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
375
|
-
_iterator.return();
|
376
|
-
}
|
377
|
-
} finally {
|
378
|
-
if (_didIteratorError) {
|
379
|
-
throw _iteratorError;
|
380
|
-
}
|
381
|
-
}
|
382
|
-
}
|
383
|
-
});
|
384
|
-
}
|
385
|
-
}, {
|
386
|
-
key: "cleanup",
|
387
|
-
value: function cleanup() {
|
388
|
-
var _this = this;
|
389
|
-
|
390
|
-
this.pageKidsCountCache.clear();
|
391
|
-
var promises = [];
|
392
|
-
this.fontCache.forEach(function (promise) {
|
393
|
-
promises.push(promise);
|
394
|
-
});
|
395
|
-
return Promise.all(promises).then(function (translatedFonts) {
|
396
|
-
for (var i = 0, ii = translatedFonts.length; i < ii; i++) {
|
397
|
-
var font = translatedFonts[i].dict;
|
398
|
-
delete font.translated;
|
399
|
-
}
|
428
|
+
return pageLabels;
|
429
|
+
}
|
400
430
|
|
401
|
-
|
431
|
+
get pageLayout() {
|
432
|
+
const obj = this.catDict.get("PageLayout");
|
433
|
+
let pageLayout = "";
|
402
434
|
|
403
|
-
|
404
|
-
|
435
|
+
if ((0, _primitives.isName)(obj)) {
|
436
|
+
switch (obj.name) {
|
437
|
+
case "SinglePage":
|
438
|
+
case "OneColumn":
|
439
|
+
case "TwoColumnLeft":
|
440
|
+
case "TwoColumnRight":
|
441
|
+
case "TwoPageLeft":
|
442
|
+
case "TwoPageRight":
|
443
|
+
pageLayout = obj.name;
|
444
|
+
}
|
405
445
|
}
|
406
|
-
}, {
|
407
|
-
key: "getPageDict",
|
408
|
-
value: function getPageDict(pageIndex) {
|
409
|
-
var capability = (0, _util.createPromiseCapability)();
|
410
|
-
var nodesToVisit = [this.catDict.getRaw('Pages')];
|
411
|
-
var xref = this.xref,
|
412
|
-
pageKidsCountCache = this.pageKidsCountCache;
|
413
|
-
var count,
|
414
|
-
currentPageIndex = 0;
|
415
446
|
|
416
|
-
|
417
|
-
|
418
|
-
var currentNode = nodesToVisit.pop();
|
447
|
+
return (0, _util.shadow)(this, "pageLayout", pageLayout);
|
448
|
+
}
|
419
449
|
|
420
|
-
|
421
|
-
|
450
|
+
get pageMode() {
|
451
|
+
const obj = this.catDict.get("PageMode");
|
452
|
+
let pageMode = "UseNone";
|
422
453
|
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
454
|
+
if ((0, _primitives.isName)(obj)) {
|
455
|
+
switch (obj.name) {
|
456
|
+
case "UseNone":
|
457
|
+
case "UseOutlines":
|
458
|
+
case "UseThumbs":
|
459
|
+
case "FullScreen":
|
460
|
+
case "UseOC":
|
461
|
+
case "UseAttachments":
|
462
|
+
pageMode = obj.name;
|
463
|
+
}
|
464
|
+
}
|
427
465
|
|
428
|
-
|
429
|
-
|
430
|
-
if (pageIndex === currentPageIndex) {
|
431
|
-
if (currentNode && !pageKidsCountCache.has(currentNode)) {
|
432
|
-
pageKidsCountCache.put(currentNode, 1);
|
433
|
-
}
|
434
|
-
|
435
|
-
capability.resolve([obj, currentNode]);
|
436
|
-
} else {
|
437
|
-
currentPageIndex++;
|
438
|
-
next();
|
439
|
-
}
|
466
|
+
return (0, _util.shadow)(this, "pageMode", pageMode);
|
467
|
+
}
|
440
468
|
|
441
|
-
|
442
|
-
|
469
|
+
get viewerPreferences() {
|
470
|
+
const ViewerPreferencesValidators = {
|
471
|
+
HideToolbar: _util.isBool,
|
472
|
+
HideMenubar: _util.isBool,
|
473
|
+
HideWindowUI: _util.isBool,
|
474
|
+
FitWindow: _util.isBool,
|
475
|
+
CenterWindow: _util.isBool,
|
476
|
+
DisplayDocTitle: _util.isBool,
|
477
|
+
NonFullScreenPageMode: _primitives.isName,
|
478
|
+
Direction: _primitives.isName,
|
479
|
+
ViewArea: _primitives.isName,
|
480
|
+
ViewClip: _primitives.isName,
|
481
|
+
PrintArea: _primitives.isName,
|
482
|
+
PrintClip: _primitives.isName,
|
483
|
+
PrintScaling: _primitives.isName,
|
484
|
+
Duplex: _primitives.isName,
|
485
|
+
PickTrayByPDFSize: _util.isBool,
|
486
|
+
PrintPageRange: Array.isArray,
|
487
|
+
NumCopies: Number.isInteger
|
488
|
+
};
|
489
|
+
const obj = this.catDict.get("ViewerPreferences");
|
490
|
+
let prefs = null;
|
443
491
|
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
};
|
450
|
-
}
|
492
|
+
if ((0, _primitives.isDict)(obj)) {
|
493
|
+
for (const key in ViewerPreferencesValidators) {
|
494
|
+
if (!obj.has(key)) {
|
495
|
+
continue;
|
496
|
+
}
|
451
497
|
|
452
|
-
|
453
|
-
capability.reject(new _util.FormatError('Page dictionary kid reference points to wrong type of object.'));
|
454
|
-
return {
|
455
|
-
v: void 0
|
456
|
-
};
|
457
|
-
}
|
498
|
+
const value = obj.get(key);
|
458
499
|
|
459
|
-
|
500
|
+
if (!ViewerPreferencesValidators[key](value)) {
|
501
|
+
(0, _util.info)(`Bad value in ViewerPreferences for "${key}".`);
|
502
|
+
continue;
|
503
|
+
}
|
460
504
|
|
461
|
-
|
462
|
-
var objId = currentNode.objId;
|
505
|
+
let prefValue;
|
463
506
|
|
464
|
-
|
465
|
-
|
466
|
-
|
507
|
+
switch (key) {
|
508
|
+
case "NonFullScreenPageMode":
|
509
|
+
switch (value.name) {
|
510
|
+
case "UseNone":
|
511
|
+
case "UseOutlines":
|
512
|
+
case "UseThumbs":
|
513
|
+
case "UseOC":
|
514
|
+
prefValue = value.name;
|
515
|
+
break;
|
467
516
|
|
468
|
-
|
469
|
-
|
470
|
-
return "continue";
|
517
|
+
default:
|
518
|
+
prefValue = "UseNone";
|
471
519
|
}
|
472
|
-
}
|
473
520
|
|
474
|
-
|
521
|
+
break;
|
475
522
|
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
};
|
483
|
-
}
|
523
|
+
case "Direction":
|
524
|
+
switch (value.name) {
|
525
|
+
case "L2R":
|
526
|
+
case "R2L":
|
527
|
+
prefValue = value.name;
|
528
|
+
break;
|
484
529
|
|
485
|
-
|
486
|
-
|
530
|
+
default:
|
531
|
+
prefValue = "L2R";
|
487
532
|
}
|
488
533
|
|
489
|
-
|
490
|
-
return {
|
491
|
-
v: void 0
|
492
|
-
};
|
493
|
-
}
|
494
|
-
|
495
|
-
for (var last = kids.length - 1; last >= 0; last--) {
|
496
|
-
nodesToVisit.push(kids[last]);
|
497
|
-
}
|
498
|
-
};
|
534
|
+
break;
|
499
535
|
|
500
|
-
|
501
|
-
|
536
|
+
case "ViewArea":
|
537
|
+
case "ViewClip":
|
538
|
+
case "PrintArea":
|
539
|
+
case "PrintClip":
|
540
|
+
switch (value.name) {
|
541
|
+
case "MediaBox":
|
542
|
+
case "CropBox":
|
543
|
+
case "BleedBox":
|
544
|
+
case "TrimBox":
|
545
|
+
case "ArtBox":
|
546
|
+
prefValue = value.name;
|
547
|
+
break;
|
502
548
|
|
503
|
-
|
504
|
-
|
505
|
-
|
549
|
+
default:
|
550
|
+
prefValue = "CropBox";
|
551
|
+
}
|
506
552
|
|
507
|
-
|
508
|
-
if (_typeof(_ret) === "object") return _ret.v;
|
509
|
-
}
|
510
|
-
}
|
553
|
+
break;
|
511
554
|
|
512
|
-
|
513
|
-
|
555
|
+
case "PrintScaling":
|
556
|
+
switch (value.name) {
|
557
|
+
case "None":
|
558
|
+
case "AppDefault":
|
559
|
+
prefValue = value.name;
|
560
|
+
break;
|
514
561
|
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
}, {
|
519
|
-
key: "getPageIndex",
|
520
|
-
value: function getPageIndex(pageRef) {
|
521
|
-
var xref = this.xref;
|
522
|
-
|
523
|
-
function pagesBeforeRef(kidRef) {
|
524
|
-
var total = 0,
|
525
|
-
parentRef;
|
526
|
-
return xref.fetchAsync(kidRef).then(function (node) {
|
527
|
-
if ((0, _primitives.isRefsEqual)(kidRef, pageRef) && !(0, _primitives.isDict)(node, 'Page') && !((0, _primitives.isDict)(node) && !node.has('Type') && node.has('Contents'))) {
|
528
|
-
throw new _util.FormatError('The reference does not point to a /Page dictionary.');
|
529
|
-
}
|
562
|
+
default:
|
563
|
+
prefValue = "AppDefault";
|
564
|
+
}
|
530
565
|
|
531
|
-
|
532
|
-
return null;
|
533
|
-
}
|
566
|
+
break;
|
534
567
|
|
535
|
-
|
536
|
-
|
537
|
-
|
568
|
+
case "Duplex":
|
569
|
+
switch (value.name) {
|
570
|
+
case "Simplex":
|
571
|
+
case "DuplexFlipShortEdge":
|
572
|
+
case "DuplexFlipLongEdge":
|
573
|
+
prefValue = value.name;
|
574
|
+
break;
|
538
575
|
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
if (!parent) {
|
543
|
-
return null;
|
544
|
-
}
|
576
|
+
default:
|
577
|
+
prefValue = "None";
|
578
|
+
}
|
545
579
|
|
546
|
-
|
547
|
-
throw new _util.FormatError('Parent must be a dictionary.');
|
548
|
-
}
|
580
|
+
break;
|
549
581
|
|
550
|
-
|
551
|
-
|
552
|
-
if (!kids) {
|
553
|
-
return null;
|
554
|
-
}
|
582
|
+
case "PrintPageRange":
|
583
|
+
const length = value.length;
|
555
584
|
|
556
|
-
|
557
|
-
|
585
|
+
if (length % 2 !== 0) {
|
586
|
+
break;
|
587
|
+
}
|
558
588
|
|
559
|
-
|
560
|
-
|
589
|
+
const isValid = value.every((page, i, arr) => {
|
590
|
+
return Number.isInteger(page) && page > 0 && (i === 0 || page >= arr[i - 1]) && page <= this.numPages;
|
591
|
+
});
|
561
592
|
|
562
|
-
if (
|
563
|
-
|
593
|
+
if (isValid) {
|
594
|
+
prefValue = value;
|
564
595
|
}
|
565
596
|
|
566
|
-
|
567
|
-
|
568
|
-
|
597
|
+
break;
|
598
|
+
|
599
|
+
case "NumCopies":
|
600
|
+
if (value > 0) {
|
601
|
+
prefValue = value;
|
569
602
|
}
|
570
603
|
|
571
|
-
|
572
|
-
if (!(0, _primitives.isDict)(kid)) {
|
573
|
-
throw new _util.FormatError('Kid node must be a dictionary.');
|
574
|
-
}
|
604
|
+
break;
|
575
605
|
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
}
|
581
|
-
}));
|
582
|
-
}
|
606
|
+
default:
|
607
|
+
if (typeof value !== "boolean") {
|
608
|
+
throw new _util.FormatError(`viewerPreferences - expected a boolean value for: ${key}`);
|
609
|
+
}
|
583
610
|
|
584
|
-
|
585
|
-
|
611
|
+
prefValue = value;
|
612
|
+
}
|
613
|
+
|
614
|
+
if (prefValue !== undefined) {
|
615
|
+
if (!prefs) {
|
616
|
+
prefs = Object.create(null);
|
586
617
|
}
|
587
618
|
|
588
|
-
|
589
|
-
|
590
|
-
});
|
591
|
-
}
|
619
|
+
prefs[key] = prefValue;
|
620
|
+
} else {
|
621
|
+
(0, _util.info)(`Bad value in ViewerPreferences for "${key}".`);
|
622
|
+
}
|
592
623
|
}
|
624
|
+
}
|
625
|
+
|
626
|
+
return (0, _util.shadow)(this, "viewerPreferences", prefs);
|
627
|
+
}
|
593
628
|
|
594
|
-
|
629
|
+
get openAction() {
|
630
|
+
const obj = this.catDict.get("OpenAction");
|
631
|
+
let openAction = null;
|
632
|
+
|
633
|
+
if ((0, _primitives.isDict)(obj)) {
|
634
|
+
const destDict = new _primitives.Dict(this.xref);
|
635
|
+
destDict.set("A", obj);
|
636
|
+
const resultObj = {
|
637
|
+
url: null,
|
638
|
+
dest: null,
|
639
|
+
action: null
|
640
|
+
};
|
641
|
+
Catalog.parseDestDictionary({
|
642
|
+
destDict,
|
643
|
+
resultObj
|
644
|
+
});
|
595
645
|
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
}
|
646
|
+
if (Array.isArray(resultObj.dest)) {
|
647
|
+
if (!openAction) {
|
648
|
+
openAction = Object.create(null);
|
649
|
+
}
|
601
650
|
|
602
|
-
|
603
|
-
|
604
|
-
|
651
|
+
openAction.dest = resultObj.dest;
|
652
|
+
} else if (resultObj.action) {
|
653
|
+
if (!openAction) {
|
654
|
+
openAction = Object.create(null);
|
655
|
+
}
|
605
656
|
|
606
|
-
|
607
|
-
|
608
|
-
|
657
|
+
openAction.action = resultObj.action;
|
658
|
+
}
|
659
|
+
} else if (Array.isArray(obj)) {
|
660
|
+
if (!openAction) {
|
661
|
+
openAction = Object.create(null);
|
609
662
|
}
|
610
663
|
|
611
|
-
|
664
|
+
openAction.dest = obj;
|
612
665
|
}
|
613
|
-
}, {
|
614
|
-
key: "metadata",
|
615
|
-
get: function get() {
|
616
|
-
var streamRef = this.catDict.getRaw('Metadata');
|
617
666
|
|
618
|
-
|
619
|
-
|
620
|
-
}
|
667
|
+
return (0, _util.shadow)(this, "openAction", openAction);
|
668
|
+
}
|
621
669
|
|
622
|
-
|
623
|
-
|
624
|
-
|
670
|
+
get attachments() {
|
671
|
+
const obj = this.catDict.get("Names");
|
672
|
+
let attachments = null;
|
625
673
|
|
626
|
-
|
627
|
-
|
628
|
-
|
674
|
+
if (obj && obj.has("EmbeddedFiles")) {
|
675
|
+
const nameTree = new NameTree(obj.getRaw("EmbeddedFiles"), this.xref);
|
676
|
+
const names = nameTree.getAll();
|
629
677
|
|
630
|
-
|
631
|
-
|
632
|
-
metadata = (0, _util.stringToUTF8String)((0, _util.bytesToString)(stream.getBytes()));
|
633
|
-
} catch (e) {
|
634
|
-
if (e instanceof _util.MissingDataException) {
|
635
|
-
throw e;
|
636
|
-
}
|
678
|
+
for (const name in names) {
|
679
|
+
const fs = new FileSpec(names[name], this.xref);
|
637
680
|
|
638
|
-
|
639
|
-
|
681
|
+
if (!attachments) {
|
682
|
+
attachments = Object.create(null);
|
640
683
|
}
|
641
|
-
}
|
642
684
|
|
643
|
-
|
685
|
+
attachments[(0, _util.stringToPDFString)(name)] = fs.serializable;
|
686
|
+
}
|
644
687
|
}
|
645
|
-
}, {
|
646
|
-
key: "toplevelPagesDict",
|
647
|
-
get: function get() {
|
648
|
-
var pagesObj = this.catDict.get('Pages');
|
649
688
|
|
650
|
-
|
651
|
-
|
652
|
-
}
|
689
|
+
return (0, _util.shadow)(this, "attachments", attachments);
|
690
|
+
}
|
653
691
|
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
key: "documentOutline",
|
658
|
-
get: function get() {
|
659
|
-
var obj = null;
|
692
|
+
get javaScript() {
|
693
|
+
const obj = this.catDict.get("Names");
|
694
|
+
let javaScript = null;
|
660
695
|
|
661
|
-
|
662
|
-
|
663
|
-
} catch (ex) {
|
664
|
-
if (ex instanceof _util.MissingDataException) {
|
665
|
-
throw ex;
|
666
|
-
}
|
696
|
+
function appendIfJavaScriptDict(jsDict) {
|
697
|
+
const type = jsDict.get("S");
|
667
698
|
|
668
|
-
|
699
|
+
if (!(0, _primitives.isName)(type, "JavaScript")) {
|
700
|
+
return;
|
669
701
|
}
|
670
702
|
|
671
|
-
|
672
|
-
}
|
673
|
-
}, {
|
674
|
-
key: "permissions",
|
675
|
-
get: function get() {
|
676
|
-
var permissions = null;
|
703
|
+
let js = jsDict.get("JS");
|
677
704
|
|
678
|
-
|
679
|
-
|
680
|
-
}
|
681
|
-
|
682
|
-
|
683
|
-
}
|
705
|
+
if ((0, _primitives.isStream)(js)) {
|
706
|
+
js = (0, _util.bytesToString)(js.getBytes());
|
707
|
+
} else if (!(0, _util.isString)(js)) {
|
708
|
+
return;
|
709
|
+
}
|
684
710
|
|
685
|
-
|
711
|
+
if (!javaScript) {
|
712
|
+
javaScript = [];
|
686
713
|
}
|
687
714
|
|
688
|
-
|
715
|
+
javaScript.push((0, _util.stringToPDFString)(js));
|
689
716
|
}
|
690
|
-
}, {
|
691
|
-
key: "numPages",
|
692
|
-
get: function get() {
|
693
|
-
var obj = this.toplevelPagesDict.get('Count');
|
694
717
|
|
695
|
-
|
696
|
-
|
718
|
+
if (obj && obj.has("JavaScript")) {
|
719
|
+
const nameTree = new NameTree(obj.getRaw("JavaScript"), this.xref);
|
720
|
+
const names = nameTree.getAll();
|
721
|
+
|
722
|
+
for (const name in names) {
|
723
|
+
const jsDict = names[name];
|
724
|
+
|
725
|
+
if ((0, _primitives.isDict)(jsDict)) {
|
726
|
+
appendIfJavaScriptDict(jsDict);
|
727
|
+
}
|
697
728
|
}
|
729
|
+
}
|
698
730
|
|
699
|
-
|
731
|
+
const openAction = this.catDict.get("OpenAction");
|
732
|
+
|
733
|
+
if ((0, _primitives.isDict)(openAction) && (0, _primitives.isName)(openAction.get("S"), "JavaScript")) {
|
734
|
+
appendIfJavaScriptDict(openAction);
|
700
735
|
}
|
701
|
-
}, {
|
702
|
-
key: "destinations",
|
703
|
-
get: function get() {
|
704
|
-
var obj = this._readDests(),
|
705
|
-
dests = Object.create(null);
|
706
736
|
|
707
|
-
|
708
|
-
|
737
|
+
return (0, _util.shadow)(this, "javaScript", javaScript);
|
738
|
+
}
|
709
739
|
|
710
|
-
|
711
|
-
|
740
|
+
fontFallback(id, handler) {
|
741
|
+
const promises = [];
|
742
|
+
this.fontCache.forEach(function (promise) {
|
743
|
+
promises.push(promise);
|
744
|
+
});
|
745
|
+
return Promise.all(promises).then(translatedFonts => {
|
746
|
+
for (const translatedFont of translatedFonts) {
|
747
|
+
if (translatedFont.loadedName === id) {
|
748
|
+
translatedFont.fallback(handler);
|
749
|
+
return;
|
712
750
|
}
|
713
|
-
} else if (obj instanceof _primitives.Dict) {
|
714
|
-
obj.forEach(function (key, value) {
|
715
|
-
if (value) {
|
716
|
-
dests[key] = fetchDestination(value);
|
717
|
-
}
|
718
|
-
});
|
719
751
|
}
|
752
|
+
});
|
753
|
+
}
|
720
754
|
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
755
|
+
cleanup(manuallyTriggered = false) {
|
756
|
+
(0, _primitives.clearPrimitiveCaches)();
|
757
|
+
this.globalImageCache.clear(manuallyTriggered);
|
758
|
+
this.pageKidsCountCache.clear();
|
759
|
+
const promises = [];
|
760
|
+
this.fontCache.forEach(function (promise) {
|
761
|
+
promises.push(promise);
|
762
|
+
});
|
763
|
+
return Promise.all(promises).then(translatedFonts => {
|
764
|
+
for (const {
|
765
|
+
dict
|
766
|
+
} of translatedFonts) {
|
767
|
+
delete dict.translated;
|
768
|
+
}
|
769
|
+
|
770
|
+
this.fontCache.clear();
|
771
|
+
this.builtInCMapCache.clear();
|
772
|
+
});
|
773
|
+
}
|
727
774
|
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
775
|
+
getPageDict(pageIndex) {
|
776
|
+
const capability = (0, _util.createPromiseCapability)();
|
777
|
+
const nodesToVisit = [this.catDict.getRaw("Pages")];
|
778
|
+
const visitedNodes = new _primitives.RefSet();
|
779
|
+
const xref = this.xref,
|
780
|
+
pageKidsCountCache = this.pageKidsCountCache;
|
781
|
+
let count,
|
782
|
+
currentPageIndex = 0;
|
734
783
|
|
735
|
-
|
736
|
-
|
784
|
+
function next() {
|
785
|
+
while (nodesToVisit.length) {
|
786
|
+
const currentNode = nodesToVisit.pop();
|
737
787
|
|
738
|
-
|
739
|
-
|
740
|
-
}, {
|
741
|
-
key: "pageMode",
|
742
|
-
get: function get() {
|
743
|
-
var obj = this.catDict.get('PageMode');
|
744
|
-
var pageMode = 'UseNone';
|
788
|
+
if ((0, _primitives.isRef)(currentNode)) {
|
789
|
+
count = pageKidsCountCache.get(currentNode);
|
745
790
|
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
case 'UseThumbs':
|
751
|
-
case 'FullScreen':
|
752
|
-
case 'UseOC':
|
753
|
-
case 'UseAttachments':
|
754
|
-
pageMode = obj.name;
|
755
|
-
}
|
756
|
-
}
|
791
|
+
if (count > 0 && currentPageIndex + count < pageIndex) {
|
792
|
+
currentPageIndex += count;
|
793
|
+
continue;
|
794
|
+
}
|
757
795
|
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
796
|
+
if (visitedNodes.has(currentNode)) {
|
797
|
+
capability.reject(new _util.FormatError("Pages tree contains circular reference."));
|
798
|
+
return;
|
799
|
+
}
|
800
|
+
|
801
|
+
visitedNodes.put(currentNode);
|
802
|
+
xref.fetchAsync(currentNode).then(function (obj) {
|
803
|
+
if ((0, _primitives.isDict)(obj, "Page") || (0, _primitives.isDict)(obj) && !obj.has("Kids")) {
|
804
|
+
if (pageIndex === currentPageIndex) {
|
805
|
+
if (currentNode && !pageKidsCountCache.has(currentNode)) {
|
806
|
+
pageKidsCountCache.put(currentNode, 1);
|
807
|
+
}
|
808
|
+
|
809
|
+
capability.resolve([obj, currentNode]);
|
810
|
+
} else {
|
811
|
+
currentPageIndex++;
|
812
|
+
next();
|
813
|
+
}
|
814
|
+
|
815
|
+
return;
|
816
|
+
}
|
777
817
|
|
778
|
-
|
779
|
-
|
818
|
+
nodesToVisit.push(obj);
|
819
|
+
next();
|
820
|
+
}, capability.reject);
|
821
|
+
return;
|
780
822
|
}
|
781
|
-
} else if (Array.isArray(obj)) {
|
782
|
-
openActionDest = obj;
|
783
|
-
}
|
784
823
|
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
get: function get() {
|
790
|
-
var obj = this.catDict.get('Names');
|
791
|
-
var attachments = null;
|
824
|
+
if (!(0, _primitives.isDict)(currentNode)) {
|
825
|
+
capability.reject(new _util.FormatError("Page dictionary kid reference points to wrong type of object."));
|
826
|
+
return;
|
827
|
+
}
|
792
828
|
|
793
|
-
|
794
|
-
var nameTree = new NameTree(obj.getRaw('EmbeddedFiles'), this.xref);
|
795
|
-
var names = nameTree.getAll();
|
829
|
+
count = currentNode.get("Count");
|
796
830
|
|
797
|
-
|
798
|
-
|
831
|
+
if (Number.isInteger(count) && count >= 0) {
|
832
|
+
const objId = currentNode.objId;
|
799
833
|
|
800
|
-
if (!
|
801
|
-
|
834
|
+
if (objId && !pageKidsCountCache.has(objId)) {
|
835
|
+
pageKidsCountCache.put(objId, count);
|
802
836
|
}
|
803
837
|
|
804
|
-
|
838
|
+
if (currentPageIndex + count <= pageIndex) {
|
839
|
+
currentPageIndex += count;
|
840
|
+
continue;
|
841
|
+
}
|
805
842
|
}
|
806
|
-
}
|
807
843
|
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
844
|
+
const kids = currentNode.get("Kids");
|
845
|
+
|
846
|
+
if (!Array.isArray(kids)) {
|
847
|
+
if ((0, _primitives.isName)(currentNode.get("Type"), "Page") || !currentNode.has("Type") && currentNode.has("Contents")) {
|
848
|
+
if (currentPageIndex === pageIndex) {
|
849
|
+
capability.resolve([currentNode, null]);
|
850
|
+
return;
|
851
|
+
}
|
815
852
|
|
816
|
-
|
817
|
-
|
853
|
+
currentPageIndex++;
|
854
|
+
continue;
|
855
|
+
}
|
818
856
|
|
819
|
-
|
857
|
+
capability.reject(new _util.FormatError("Page dictionary kids object is not an array."));
|
820
858
|
return;
|
821
859
|
}
|
822
860
|
|
823
|
-
|
861
|
+
for (let last = kids.length - 1; last >= 0; last--) {
|
862
|
+
nodesToVisit.push(kids[last]);
|
863
|
+
}
|
864
|
+
}
|
865
|
+
|
866
|
+
capability.reject(new Error(`Page index ${pageIndex} not found.`));
|
867
|
+
}
|
824
868
|
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
|
869
|
+
next();
|
870
|
+
return capability.promise;
|
871
|
+
}
|
872
|
+
|
873
|
+
getPageIndex(pageRef) {
|
874
|
+
const xref = this.xref;
|
875
|
+
|
876
|
+
function pagesBeforeRef(kidRef) {
|
877
|
+
let total = 0,
|
878
|
+
parentRef;
|
879
|
+
return xref.fetchAsync(kidRef).then(function (node) {
|
880
|
+
if ((0, _primitives.isRefsEqual)(kidRef, pageRef) && !(0, _primitives.isDict)(node, "Page") && !((0, _primitives.isDict)(node) && !node.has("Type") && node.has("Contents"))) {
|
881
|
+
throw new _util.FormatError("The reference does not point to a /Page dictionary.");
|
829
882
|
}
|
830
883
|
|
831
|
-
if (!
|
832
|
-
|
884
|
+
if (!node) {
|
885
|
+
return null;
|
833
886
|
}
|
834
887
|
|
835
|
-
|
836
|
-
|
888
|
+
if (!(0, _primitives.isDict)(node)) {
|
889
|
+
throw new _util.FormatError("Node must be a dictionary.");
|
890
|
+
}
|
837
891
|
|
838
|
-
|
839
|
-
|
840
|
-
|
892
|
+
parentRef = node.getRaw("Parent");
|
893
|
+
return node.getAsync("Parent");
|
894
|
+
}).then(function (parent) {
|
895
|
+
if (!parent) {
|
896
|
+
return null;
|
897
|
+
}
|
841
898
|
|
842
|
-
|
843
|
-
|
899
|
+
if (!(0, _primitives.isDict)(parent)) {
|
900
|
+
throw new _util.FormatError("Parent must be a dictionary.");
|
901
|
+
}
|
844
902
|
|
845
|
-
|
846
|
-
|
847
|
-
|
903
|
+
return parent.getAsync("Kids");
|
904
|
+
}).then(function (kids) {
|
905
|
+
if (!kids) {
|
906
|
+
return null;
|
848
907
|
}
|
849
|
-
}
|
850
908
|
|
851
|
-
|
909
|
+
const kidPromises = [];
|
910
|
+
let found = false;
|
852
911
|
|
853
|
-
|
854
|
-
|
912
|
+
for (let i = 0, ii = kids.length; i < ii; i++) {
|
913
|
+
const kid = kids[i];
|
914
|
+
|
915
|
+
if (!(0, _primitives.isRef)(kid)) {
|
916
|
+
throw new _util.FormatError("Kid must be a reference.");
|
917
|
+
}
|
918
|
+
|
919
|
+
if ((0, _primitives.isRefsEqual)(kid, kidRef)) {
|
920
|
+
found = true;
|
921
|
+
break;
|
922
|
+
}
|
855
923
|
|
856
|
-
|
857
|
-
|
924
|
+
kidPromises.push(xref.fetchAsync(kid).then(function (obj) {
|
925
|
+
if (!(0, _primitives.isDict)(obj)) {
|
926
|
+
throw new _util.FormatError("Kid node must be a dictionary.");
|
927
|
+
}
|
858
928
|
|
859
|
-
|
860
|
-
|
861
|
-
|
929
|
+
if (obj.has("Count")) {
|
930
|
+
total += obj.get("Count");
|
931
|
+
} else {
|
932
|
+
total++;
|
862
933
|
}
|
934
|
+
}));
|
935
|
+
}
|
863
936
|
|
864
|
-
|
865
|
-
|
866
|
-
} else {
|
867
|
-
appendIfJavaScriptDict(openActionDict);
|
937
|
+
if (!found) {
|
938
|
+
throw new _util.FormatError("Kid reference not found in parent's kids.");
|
868
939
|
}
|
869
|
-
}
|
870
940
|
|
871
|
-
|
941
|
+
return Promise.all(kidPromises).then(function () {
|
942
|
+
return [total, parentRef];
|
943
|
+
});
|
944
|
+
});
|
872
945
|
}
|
873
|
-
}], [{
|
874
|
-
key: "parseDestDictionary",
|
875
|
-
value: function parseDestDictionary(params) {
|
876
|
-
function addDefaultProtocolToUrl(url) {
|
877
|
-
return url.startsWith('www.') ? "http://".concat(url) : url;
|
878
|
-
}
|
879
946
|
|
880
|
-
|
881
|
-
|
882
|
-
|
883
|
-
|
884
|
-
|
947
|
+
let total = 0;
|
948
|
+
|
949
|
+
function next(ref) {
|
950
|
+
return pagesBeforeRef(ref).then(function (args) {
|
951
|
+
if (!args) {
|
952
|
+
return total;
|
885
953
|
}
|
886
|
-
}
|
887
954
|
|
888
|
-
|
955
|
+
const [count, parentRef] = args;
|
956
|
+
total += count;
|
957
|
+
return next(parentRef);
|
958
|
+
});
|
959
|
+
}
|
889
960
|
|
890
|
-
|
891
|
-
|
892
|
-
return;
|
893
|
-
}
|
961
|
+
return next(pageRef);
|
962
|
+
}
|
894
963
|
|
895
|
-
|
964
|
+
static parseDestDictionary(params) {
|
965
|
+
function addDefaultProtocolToUrl(url) {
|
966
|
+
return url.startsWith("www.") ? `http://${url}` : url;
|
967
|
+
}
|
896
968
|
|
897
|
-
|
898
|
-
|
899
|
-
return;
|
969
|
+
function tryConvertUrlEncoding(url) {
|
970
|
+
try {
|
971
|
+
return (0, _util.stringToUTF8String)(url);
|
972
|
+
} catch (e) {
|
973
|
+
return url;
|
900
974
|
}
|
975
|
+
}
|
901
976
|
|
902
|
-
|
903
|
-
var action = destDict.get('A'),
|
904
|
-
url,
|
905
|
-
dest;
|
977
|
+
const destDict = params.destDict;
|
906
978
|
|
907
|
-
|
908
|
-
|
909
|
-
|
979
|
+
if (!(0, _primitives.isDict)(destDict)) {
|
980
|
+
(0, _util.warn)("parseDestDictionary: `destDict` must be a dictionary.");
|
981
|
+
return;
|
982
|
+
}
|
910
983
|
|
911
|
-
|
912
|
-
var actionType = action.get('S');
|
984
|
+
const resultObj = params.resultObj;
|
913
985
|
|
914
|
-
|
915
|
-
|
916
|
-
|
917
|
-
|
986
|
+
if (typeof resultObj !== "object") {
|
987
|
+
(0, _util.warn)("parseDestDictionary: `resultObj` must be an object.");
|
988
|
+
return;
|
989
|
+
}
|
918
990
|
|
919
|
-
|
991
|
+
const docBaseUrl = params.docBaseUrl || null;
|
992
|
+
let action = destDict.get("A"),
|
993
|
+
url,
|
994
|
+
dest;
|
920
995
|
|
921
|
-
|
922
|
-
|
923
|
-
|
996
|
+
if (!(0, _primitives.isDict)(action) && destDict.has("Dest")) {
|
997
|
+
action = destDict.get("Dest");
|
998
|
+
}
|
924
999
|
|
925
|
-
|
926
|
-
|
927
|
-
} else if ((0, _util.isString)(url)) {
|
928
|
-
url = addDefaultProtocolToUrl(url);
|
929
|
-
}
|
1000
|
+
if ((0, _primitives.isDict)(action)) {
|
1001
|
+
const actionType = action.get("S");
|
930
1002
|
|
931
|
-
|
1003
|
+
if (!(0, _primitives.isName)(actionType)) {
|
1004
|
+
(0, _util.warn)("parseDestDictionary: Invalid type in Action dictionary.");
|
1005
|
+
return;
|
1006
|
+
}
|
932
1007
|
|
933
|
-
|
934
|
-
dest = action.get('D');
|
935
|
-
break;
|
1008
|
+
const actionName = actionType.name;
|
936
1009
|
|
937
|
-
|
938
|
-
|
939
|
-
|
1010
|
+
switch (actionName) {
|
1011
|
+
case "URI":
|
1012
|
+
url = action.get("URI");
|
940
1013
|
|
941
|
-
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
1014
|
+
if ((0, _primitives.isName)(url)) {
|
1015
|
+
url = "/" + url.name;
|
1016
|
+
} else if ((0, _util.isString)(url)) {
|
1017
|
+
url = addDefaultProtocolToUrl(url);
|
1018
|
+
}
|
946
1019
|
|
947
|
-
|
1020
|
+
break;
|
948
1021
|
|
949
|
-
|
950
|
-
|
951
|
-
|
952
|
-
}
|
1022
|
+
case "GoTo":
|
1023
|
+
dest = action.get("D");
|
1024
|
+
break;
|
953
1025
|
|
954
|
-
|
955
|
-
|
1026
|
+
case "Launch":
|
1027
|
+
case "GoToR":
|
1028
|
+
const urlDict = action.get("F");
|
956
1029
|
|
957
|
-
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
|
962
|
-
|
1030
|
+
if ((0, _primitives.isDict)(urlDict)) {
|
1031
|
+
url = urlDict.get("F") || null;
|
1032
|
+
} else if ((0, _util.isString)(urlDict)) {
|
1033
|
+
url = urlDict;
|
1034
|
+
}
|
1035
|
+
|
1036
|
+
let remoteDest = action.get("D");
|
1037
|
+
|
1038
|
+
if (remoteDest) {
|
1039
|
+
if ((0, _primitives.isName)(remoteDest)) {
|
1040
|
+
remoteDest = remoteDest.name;
|
963
1041
|
}
|
964
1042
|
|
965
|
-
|
1043
|
+
if ((0, _util.isString)(url)) {
|
1044
|
+
const baseUrl = url.split("#")[0];
|
966
1045
|
|
967
|
-
|
968
|
-
|
1046
|
+
if ((0, _util.isString)(remoteDest)) {
|
1047
|
+
url = baseUrl + "#" + remoteDest;
|
1048
|
+
} else if (Array.isArray(remoteDest)) {
|
1049
|
+
url = baseUrl + "#" + JSON.stringify(remoteDest);
|
1050
|
+
}
|
969
1051
|
}
|
1052
|
+
}
|
970
1053
|
|
971
|
-
|
1054
|
+
const newWindow = action.get("NewWindow");
|
972
1055
|
|
973
|
-
|
974
|
-
|
1056
|
+
if ((0, _util.isBool)(newWindow)) {
|
1057
|
+
resultObj.newWindow = newWindow;
|
1058
|
+
}
|
975
1059
|
|
976
|
-
|
977
|
-
resultObj.action = namedAction.name;
|
978
|
-
}
|
1060
|
+
break;
|
979
1061
|
|
980
|
-
|
1062
|
+
case "Named":
|
1063
|
+
const namedAction = action.get("N");
|
981
1064
|
|
982
|
-
|
983
|
-
|
984
|
-
|
1065
|
+
if ((0, _primitives.isName)(namedAction)) {
|
1066
|
+
resultObj.action = namedAction.name;
|
1067
|
+
}
|
985
1068
|
|
986
|
-
|
987
|
-
js = (0, _util.bytesToString)(jsAction.getBytes());
|
988
|
-
} else if ((0, _util.isString)(jsAction)) {
|
989
|
-
js = jsAction;
|
990
|
-
}
|
1069
|
+
break;
|
991
1070
|
|
992
|
-
|
993
|
-
|
994
|
-
|
995
|
-
var jsUrl = regex.exec((0, _util.stringToPDFString)(js));
|
1071
|
+
case "JavaScript":
|
1072
|
+
const jsAction = action.get("JS");
|
1073
|
+
let js;
|
996
1074
|
|
997
|
-
|
998
|
-
|
1075
|
+
if ((0, _primitives.isStream)(jsAction)) {
|
1076
|
+
js = (0, _util.bytesToString)(jsAction.getBytes());
|
1077
|
+
} else if ((0, _util.isString)(jsAction)) {
|
1078
|
+
js = jsAction;
|
1079
|
+
}
|
999
1080
|
|
1000
|
-
|
1001
|
-
|
1002
|
-
|
1081
|
+
if (js) {
|
1082
|
+
const URL_OPEN_METHODS = ["app.launchURL", "window.open"];
|
1083
|
+
const regex = new RegExp("^\\s*(" + URL_OPEN_METHODS.join("|").split(".").join("\\.") + ")\\((?:'|\")([^'\"]*)(?:'|\")(?:,\\s*(\\w+)\\)|\\))", "i");
|
1084
|
+
const jsUrl = regex.exec((0, _util.stringToPDFString)(js));
|
1003
1085
|
|
1004
|
-
|
1086
|
+
if (jsUrl && jsUrl[2]) {
|
1087
|
+
url = jsUrl[2];
|
1088
|
+
|
1089
|
+
if (jsUrl[3] === "true" && jsUrl[1] === "app.launchURL") {
|
1090
|
+
resultObj.newWindow = true;
|
1005
1091
|
}
|
1092
|
+
|
1093
|
+
break;
|
1006
1094
|
}
|
1095
|
+
}
|
1007
1096
|
|
1008
|
-
|
1009
|
-
|
1010
|
-
|
1011
|
-
}
|
1012
|
-
} else if (destDict.has('Dest')) {
|
1013
|
-
dest = destDict.get('Dest');
|
1097
|
+
default:
|
1098
|
+
(0, _util.warn)(`parseDestDictionary: unsupported action type "${actionName}".`);
|
1099
|
+
break;
|
1014
1100
|
}
|
1101
|
+
} else if (destDict.has("Dest")) {
|
1102
|
+
dest = destDict.get("Dest");
|
1103
|
+
}
|
1015
1104
|
|
1016
|
-
|
1017
|
-
|
1018
|
-
|
1019
|
-
|
1020
|
-
if (absoluteUrl) {
|
1021
|
-
resultObj.url = absoluteUrl.href;
|
1022
|
-
}
|
1105
|
+
if ((0, _util.isString)(url)) {
|
1106
|
+
url = tryConvertUrlEncoding(url);
|
1107
|
+
const absoluteUrl = (0, _util.createValidAbsoluteUrl)(url, docBaseUrl);
|
1023
1108
|
|
1024
|
-
|
1109
|
+
if (absoluteUrl) {
|
1110
|
+
resultObj.url = absoluteUrl.href;
|
1025
1111
|
}
|
1026
1112
|
|
1027
|
-
|
1028
|
-
|
1029
|
-
dest = dest.name;
|
1030
|
-
}
|
1113
|
+
resultObj.unsafeUrl = url;
|
1114
|
+
}
|
1031
1115
|
|
1032
|
-
|
1033
|
-
|
1034
|
-
|
1116
|
+
if (dest) {
|
1117
|
+
if ((0, _primitives.isName)(dest)) {
|
1118
|
+
dest = dest.name;
|
1119
|
+
}
|
1120
|
+
|
1121
|
+
if ((0, _util.isString)(dest) || Array.isArray(dest)) {
|
1122
|
+
resultObj.dest = dest;
|
1035
1123
|
}
|
1036
1124
|
}
|
1037
|
-
}
|
1125
|
+
}
|
1038
1126
|
|
1039
|
-
|
1040
|
-
}();
|
1127
|
+
}
|
1041
1128
|
|
1042
1129
|
exports.Catalog = Catalog;
|
1043
1130
|
|
@@ -1047,10 +1134,10 @@ var XRef = function XRefClosure() {
|
|
1047
1134
|
this.pdfManager = pdfManager;
|
1048
1135
|
this.entries = [];
|
1049
1136
|
this.xrefstms = Object.create(null);
|
1050
|
-
this.
|
1137
|
+
this._cacheMap = new Map();
|
1051
1138
|
this.stats = {
|
1052
|
-
streamTypes:
|
1053
|
-
fontTypes:
|
1139
|
+
streamTypes: Object.create(null),
|
1140
|
+
fontTypes: Object.create(null)
|
1054
1141
|
};
|
1055
1142
|
}
|
1056
1143
|
|
@@ -1064,55 +1151,55 @@ var XRef = function XRefClosure() {
|
|
1064
1151
|
if (!recoveryMode) {
|
1065
1152
|
trailerDict = this.readXRef();
|
1066
1153
|
} else {
|
1067
|
-
(0, _util.warn)(
|
1154
|
+
(0, _util.warn)("Indexing all PDF objects");
|
1068
1155
|
trailerDict = this.indexObjects();
|
1069
1156
|
}
|
1070
1157
|
|
1071
1158
|
trailerDict.assignXref(this);
|
1072
1159
|
this.trailer = trailerDict;
|
1073
|
-
|
1160
|
+
let encrypt;
|
1074
1161
|
|
1075
1162
|
try {
|
1076
|
-
encrypt = trailerDict.get(
|
1163
|
+
encrypt = trailerDict.get("Encrypt");
|
1077
1164
|
} catch (ex) {
|
1078
|
-
if (ex instanceof
|
1165
|
+
if (ex instanceof _core_utils.MissingDataException) {
|
1079
1166
|
throw ex;
|
1080
1167
|
}
|
1081
1168
|
|
1082
|
-
(0, _util.warn)(
|
1169
|
+
(0, _util.warn)(`XRef.parse - Invalid "Encrypt" reference: "${ex}".`);
|
1083
1170
|
}
|
1084
1171
|
|
1085
1172
|
if ((0, _primitives.isDict)(encrypt)) {
|
1086
|
-
var ids = trailerDict.get(
|
1087
|
-
var fileId = ids && ids.length ? ids[0] :
|
1173
|
+
var ids = trailerDict.get("ID");
|
1174
|
+
var fileId = ids && ids.length ? ids[0] : "";
|
1088
1175
|
encrypt.suppressEncryption = true;
|
1089
1176
|
this.encrypt = new _crypto.CipherTransformFactory(encrypt, fileId, this.pdfManager.password);
|
1090
1177
|
}
|
1091
1178
|
|
1092
|
-
|
1179
|
+
let root;
|
1093
1180
|
|
1094
1181
|
try {
|
1095
|
-
root = trailerDict.get(
|
1182
|
+
root = trailerDict.get("Root");
|
1096
1183
|
} catch (ex) {
|
1097
|
-
if (ex instanceof
|
1184
|
+
if (ex instanceof _core_utils.MissingDataException) {
|
1098
1185
|
throw ex;
|
1099
1186
|
}
|
1100
1187
|
|
1101
|
-
(0, _util.warn)(
|
1188
|
+
(0, _util.warn)(`XRef.parse - Invalid "Root" reference: "${ex}".`);
|
1102
1189
|
}
|
1103
1190
|
|
1104
|
-
if ((0, _primitives.isDict)(root) && root.has(
|
1191
|
+
if ((0, _primitives.isDict)(root) && root.has("Pages")) {
|
1105
1192
|
this.root = root;
|
1106
1193
|
} else {
|
1107
1194
|
if (!recoveryMode) {
|
1108
|
-
throw new
|
1195
|
+
throw new _core_utils.XRefParseException();
|
1109
1196
|
}
|
1110
1197
|
|
1111
|
-
throw new _util.FormatError(
|
1198
|
+
throw new _util.FormatError("Invalid root reference");
|
1112
1199
|
}
|
1113
1200
|
},
|
1114
1201
|
processXRefTable: function XRef_processXRefTable(parser) {
|
1115
|
-
if (!(
|
1202
|
+
if (!("tableState" in this)) {
|
1116
1203
|
this.tableState = {
|
1117
1204
|
entryNum: 0,
|
1118
1205
|
streamPos: parser.lexer.stream.pos,
|
@@ -1123,8 +1210,8 @@ var XRef = function XRefClosure() {
|
|
1123
1210
|
|
1124
1211
|
var obj = this.readXRefTable(parser);
|
1125
1212
|
|
1126
|
-
if (!(0, _primitives.isCmd)(obj,
|
1127
|
-
throw new _util.FormatError(
|
1213
|
+
if (!(0, _primitives.isCmd)(obj, "trailer")) {
|
1214
|
+
throw new _util.FormatError("Invalid XRef table: could not find trailer dictionary");
|
1128
1215
|
}
|
1129
1216
|
|
1130
1217
|
var dict = parser.getObj();
|
@@ -1134,7 +1221,7 @@ var XRef = function XRefClosure() {
|
|
1134
1221
|
}
|
1135
1222
|
|
1136
1223
|
if (!(0, _primitives.isDict)(dict)) {
|
1137
|
-
throw new _util.FormatError(
|
1224
|
+
throw new _util.FormatError("Invalid XRef table: could not parse trailer dictionary");
|
1138
1225
|
}
|
1139
1226
|
|
1140
1227
|
delete this.tableState;
|
@@ -1149,8 +1236,8 @@ var XRef = function XRefClosure() {
|
|
1149
1236
|
var obj;
|
1150
1237
|
|
1151
1238
|
while (true) {
|
1152
|
-
if (!(
|
1153
|
-
if ((0, _primitives.isCmd)(obj = parser.getObj(),
|
1239
|
+
if (!("firstEntryNum" in tableState) || !("entryCount" in tableState)) {
|
1240
|
+
if ((0, _primitives.isCmd)(obj = parser.getObj(), "trailer")) {
|
1154
1241
|
break;
|
1155
1242
|
}
|
1156
1243
|
|
@@ -1162,7 +1249,7 @@ var XRef = function XRefClosure() {
|
|
1162
1249
|
var count = tableState.entryCount;
|
1163
1250
|
|
1164
1251
|
if (!Number.isInteger(first) || !Number.isInteger(count)) {
|
1165
|
-
throw new _util.FormatError(
|
1252
|
+
throw new _util.FormatError("Invalid XRef table: wrong types in subsection header");
|
1166
1253
|
}
|
1167
1254
|
|
1168
1255
|
for (var i = tableState.entryNum; i < count; i++) {
|
@@ -1175,14 +1262,20 @@ var XRef = function XRefClosure() {
|
|
1175
1262
|
entry.gen = parser.getObj();
|
1176
1263
|
var type = parser.getObj();
|
1177
1264
|
|
1178
|
-
if (
|
1179
|
-
|
1180
|
-
|
1181
|
-
|
1265
|
+
if (type instanceof _primitives.Cmd) {
|
1266
|
+
switch (type.cmd) {
|
1267
|
+
case "f":
|
1268
|
+
entry.free = true;
|
1269
|
+
break;
|
1270
|
+
|
1271
|
+
case "n":
|
1272
|
+
entry.uncompressed = true;
|
1273
|
+
break;
|
1274
|
+
}
|
1182
1275
|
}
|
1183
1276
|
|
1184
1277
|
if (!Number.isInteger(entry.offset) || !Number.isInteger(entry.gen) || !(entry.free || entry.uncompressed)) {
|
1185
|
-
throw new _util.FormatError(
|
1278
|
+
throw new _util.FormatError(`Invalid entry in XRef subsection: ${first}, ${count}`);
|
1186
1279
|
}
|
1187
1280
|
|
1188
1281
|
if (i === 0 && entry.free && first === 1) {
|
@@ -1203,24 +1296,24 @@ var XRef = function XRefClosure() {
|
|
1203
1296
|
}
|
1204
1297
|
|
1205
1298
|
if (this.entries[0] && !this.entries[0].free) {
|
1206
|
-
throw new _util.FormatError(
|
1299
|
+
throw new _util.FormatError("Invalid XRef table: unexpected first object");
|
1207
1300
|
}
|
1208
1301
|
|
1209
1302
|
return obj;
|
1210
1303
|
},
|
1211
1304
|
processXRefStream: function XRef_processXRefStream(stream) {
|
1212
|
-
if (!(
|
1305
|
+
if (!("streamState" in this)) {
|
1213
1306
|
var streamParameters = stream.dict;
|
1214
|
-
var byteWidths = streamParameters.get(
|
1215
|
-
var range = streamParameters.get(
|
1307
|
+
var byteWidths = streamParameters.get("W");
|
1308
|
+
var range = streamParameters.get("Index");
|
1216
1309
|
|
1217
1310
|
if (!range) {
|
1218
|
-
range = [0, streamParameters.get(
|
1311
|
+
range = [0, streamParameters.get("Size")];
|
1219
1312
|
}
|
1220
1313
|
|
1221
1314
|
this.streamState = {
|
1222
1315
|
entryRanges: range,
|
1223
|
-
byteWidths
|
1316
|
+
byteWidths,
|
1224
1317
|
entryNum: 0,
|
1225
1318
|
streamPos: stream.pos
|
1226
1319
|
};
|
@@ -1245,11 +1338,11 @@ var XRef = function XRefClosure() {
|
|
1245
1338
|
var n = entryRanges[1];
|
1246
1339
|
|
1247
1340
|
if (!Number.isInteger(first) || !Number.isInteger(n)) {
|
1248
|
-
throw new _util.FormatError(
|
1341
|
+
throw new _util.FormatError(`Invalid XRef range fields: ${first}, ${n}`);
|
1249
1342
|
}
|
1250
1343
|
|
1251
1344
|
if (!Number.isInteger(typeFieldWidth) || !Number.isInteger(offsetFieldWidth) || !Number.isInteger(generationFieldWidth)) {
|
1252
|
-
throw new _util.FormatError(
|
1345
|
+
throw new _util.FormatError(`Invalid XRef entry fields length: ${first}, ${n}`);
|
1253
1346
|
}
|
1254
1347
|
|
1255
1348
|
for (i = streamState.entryNum; i < n; ++i) {
|
@@ -1292,7 +1385,7 @@ var XRef = function XRefClosure() {
|
|
1292
1385
|
break;
|
1293
1386
|
|
1294
1387
|
default:
|
1295
|
-
throw new _util.FormatError(
|
1388
|
+
throw new _util.FormatError(`Invalid XRef entry type: ${type}`);
|
1296
1389
|
}
|
1297
1390
|
|
1298
1391
|
if (!this.entries[first + i]) {
|
@@ -1307,14 +1400,14 @@ var XRef = function XRefClosure() {
|
|
1307
1400
|
},
|
1308
1401
|
indexObjects: function XRef_indexObjects() {
|
1309
1402
|
var TAB = 0x9,
|
1310
|
-
LF =
|
1311
|
-
CR =
|
1403
|
+
LF = 0xa,
|
1404
|
+
CR = 0xd,
|
1312
1405
|
SPACE = 0x20;
|
1313
1406
|
var PERCENT = 0x25,
|
1314
|
-
LT =
|
1407
|
+
LT = 0x3c;
|
1315
1408
|
|
1316
1409
|
function readToken(data, offset) {
|
1317
|
-
var token =
|
1410
|
+
var token = "",
|
1318
1411
|
ch = data[offset];
|
1319
1412
|
|
1320
1413
|
while (ch !== LF && ch !== CR && ch !== LT) {
|
@@ -1353,12 +1446,12 @@ var XRef = function XRefClosure() {
|
|
1353
1446
|
}
|
1354
1447
|
|
1355
1448
|
var objRegExp = /^(\d+)\s+(\d+)\s+obj\b/;
|
1356
|
-
|
1357
|
-
|
1358
|
-
|
1449
|
+
const endobjRegExp = /\bendobj[\b\s]$/;
|
1450
|
+
const nestedObjRegExp = /\s+(\d+\s+\d+\s+obj[\b\s<])$/;
|
1451
|
+
const CHECK_CONTENT_LENGTH = 25;
|
1359
1452
|
var trailerBytes = new Uint8Array([116, 114, 97, 105, 108, 101, 114]);
|
1360
1453
|
var startxrefBytes = new Uint8Array([115, 116, 97, 114, 116, 120, 114, 101, 102]);
|
1361
|
-
|
1454
|
+
const objBytes = new Uint8Array([111, 98, 106]);
|
1362
1455
|
var xrefBytes = new Uint8Array([47, 88, 82, 101, 102]);
|
1363
1456
|
this.entries.length = 0;
|
1364
1457
|
var stream = this.stream;
|
@@ -1394,35 +1487,35 @@ var XRef = function XRefClosure() {
|
|
1394
1487
|
var token = readToken(buffer, position);
|
1395
1488
|
var m;
|
1396
1489
|
|
1397
|
-
if (token.startsWith(
|
1490
|
+
if (token.startsWith("xref") && (token.length === 4 || /\s/.test(token[4]))) {
|
1398
1491
|
position += skipUntil(buffer, position, trailerBytes);
|
1399
1492
|
trailers.push(position);
|
1400
1493
|
position += skipUntil(buffer, position, startxrefBytes);
|
1401
1494
|
} else if (m = objRegExp.exec(token)) {
|
1402
|
-
|
1403
|
-
|
1495
|
+
const num = m[1] | 0,
|
1496
|
+
gen = m[2] | 0;
|
1404
1497
|
|
1405
|
-
if (
|
1498
|
+
if (!this.entries[num] || this.entries[num].gen === gen) {
|
1406
1499
|
this.entries[num] = {
|
1407
1500
|
offset: position - stream.start,
|
1408
|
-
gen
|
1501
|
+
gen,
|
1409
1502
|
uncompressed: true
|
1410
1503
|
};
|
1411
1504
|
}
|
1412
1505
|
|
1413
|
-
|
1506
|
+
let contentLength,
|
1414
1507
|
startPos = position + token.length;
|
1415
1508
|
|
1416
1509
|
while (startPos < buffer.length) {
|
1417
|
-
|
1510
|
+
const endPos = startPos + skipUntil(buffer, startPos, objBytes) + 4;
|
1418
1511
|
contentLength = endPos - position;
|
1419
|
-
|
1420
|
-
|
1512
|
+
const checkPos = Math.max(endPos - CHECK_CONTENT_LENGTH, startPos);
|
1513
|
+
const tokenStr = (0, _util.bytesToString)(buffer.subarray(checkPos, endPos));
|
1421
1514
|
|
1422
1515
|
if (endobjRegExp.test(tokenStr)) {
|
1423
1516
|
break;
|
1424
1517
|
} else {
|
1425
|
-
|
1518
|
+
const objToken = nestedObjRegExp.exec(tokenStr);
|
1426
1519
|
|
1427
1520
|
if (objToken && objToken[1]) {
|
1428
1521
|
(0, _util.warn)('indexObjects: Found new "obj" inside of another "obj", ' + 'caused by missing "endobj" -- trying to recover.');
|
@@ -1434,7 +1527,7 @@ var XRef = function XRefClosure() {
|
|
1434
1527
|
startPos = endPos;
|
1435
1528
|
}
|
1436
1529
|
|
1437
|
-
|
1530
|
+
const content = buffer.subarray(position, position + contentLength);
|
1438
1531
|
var xrefTagOffset = skipUntil(content, 0, xrefBytes);
|
1439
1532
|
|
1440
1533
|
if (xrefTagOffset < contentLength && content[xrefTagOffset + 5] < 64) {
|
@@ -1443,7 +1536,7 @@ var XRef = function XRefClosure() {
|
|
1443
1536
|
}
|
1444
1537
|
|
1445
1538
|
position += contentLength;
|
1446
|
-
} else if (token.startsWith(
|
1539
|
+
} else if (token.startsWith("trailer") && (token.length === 7 || /\s/.test(token[7]))) {
|
1447
1540
|
trailers.push(position);
|
1448
1541
|
position += skipUntil(buffer, position, startxrefBytes);
|
1449
1542
|
} else {
|
@@ -1458,40 +1551,45 @@ var XRef = function XRefClosure() {
|
|
1458
1551
|
this.readXRef(true);
|
1459
1552
|
}
|
1460
1553
|
|
1461
|
-
|
1554
|
+
let trailerDict;
|
1462
1555
|
|
1463
1556
|
for (i = 0, ii = trailers.length; i < ii; ++i) {
|
1464
1557
|
stream.pos = trailers[i];
|
1465
|
-
|
1558
|
+
const parser = new _parser.Parser({
|
1559
|
+
lexer: new _parser.Lexer(stream),
|
1560
|
+
xref: this,
|
1561
|
+
allowStreams: true,
|
1562
|
+
recoveryMode: true
|
1563
|
+
});
|
1466
1564
|
var obj = parser.getObj();
|
1467
1565
|
|
1468
|
-
if (!(0, _primitives.isCmd)(obj,
|
1566
|
+
if (!(0, _primitives.isCmd)(obj, "trailer")) {
|
1469
1567
|
continue;
|
1470
1568
|
}
|
1471
1569
|
|
1472
|
-
|
1570
|
+
const dict = parser.getObj();
|
1473
1571
|
|
1474
1572
|
if (!(0, _primitives.isDict)(dict)) {
|
1475
1573
|
continue;
|
1476
1574
|
}
|
1477
1575
|
|
1478
|
-
|
1576
|
+
let rootDict;
|
1479
1577
|
|
1480
1578
|
try {
|
1481
|
-
rootDict = dict.get(
|
1579
|
+
rootDict = dict.get("Root");
|
1482
1580
|
} catch (ex) {
|
1483
|
-
if (ex instanceof
|
1581
|
+
if (ex instanceof _core_utils.MissingDataException) {
|
1484
1582
|
throw ex;
|
1485
1583
|
}
|
1486
1584
|
|
1487
1585
|
continue;
|
1488
1586
|
}
|
1489
1587
|
|
1490
|
-
if (!(0, _primitives.isDict)(rootDict) || !rootDict.has(
|
1588
|
+
if (!(0, _primitives.isDict)(rootDict) || !rootDict.has("Pages")) {
|
1491
1589
|
continue;
|
1492
1590
|
}
|
1493
1591
|
|
1494
|
-
if (dict.has(
|
1592
|
+
if (dict.has("ID")) {
|
1495
1593
|
return dict;
|
1496
1594
|
}
|
1497
1595
|
|
@@ -1502,36 +1600,40 @@ var XRef = function XRefClosure() {
|
|
1502
1600
|
return trailerDict;
|
1503
1601
|
}
|
1504
1602
|
|
1505
|
-
throw new _util.InvalidPDFException(
|
1603
|
+
throw new _util.InvalidPDFException("Invalid PDF structure.");
|
1506
1604
|
},
|
1507
1605
|
readXRef: function XRef_readXRef(recoveryMode) {
|
1508
1606
|
var stream = this.stream;
|
1509
|
-
|
1607
|
+
const startXRefParsedCache = Object.create(null);
|
1510
1608
|
|
1511
1609
|
try {
|
1512
1610
|
while (this.startXRefQueue.length) {
|
1513
1611
|
var startXRef = this.startXRefQueue[0];
|
1514
1612
|
|
1515
1613
|
if (startXRefParsedCache[startXRef]) {
|
1516
|
-
(0, _util.warn)(
|
1614
|
+
(0, _util.warn)("readXRef - skipping XRef table since it was already parsed.");
|
1517
1615
|
this.startXRefQueue.shift();
|
1518
1616
|
continue;
|
1519
1617
|
}
|
1520
1618
|
|
1521
1619
|
startXRefParsedCache[startXRef] = true;
|
1522
1620
|
stream.pos = startXRef + stream.start;
|
1523
|
-
|
1621
|
+
const parser = new _parser.Parser({
|
1622
|
+
lexer: new _parser.Lexer(stream),
|
1623
|
+
xref: this,
|
1624
|
+
allowStreams: true
|
1625
|
+
});
|
1524
1626
|
var obj = parser.getObj();
|
1525
1627
|
var dict;
|
1526
1628
|
|
1527
|
-
if ((0, _primitives.isCmd)(obj,
|
1629
|
+
if ((0, _primitives.isCmd)(obj, "xref")) {
|
1528
1630
|
dict = this.processXRefTable(parser);
|
1529
1631
|
|
1530
1632
|
if (!this.topDict) {
|
1531
1633
|
this.topDict = dict;
|
1532
1634
|
}
|
1533
1635
|
|
1534
|
-
obj = dict.get(
|
1636
|
+
obj = dict.get("XRefStm");
|
1535
1637
|
|
1536
1638
|
if (Number.isInteger(obj)) {
|
1537
1639
|
var pos = obj;
|
@@ -1542,8 +1644,8 @@ var XRef = function XRefClosure() {
|
|
1542
1644
|
}
|
1543
1645
|
}
|
1544
1646
|
} else if (Number.isInteger(obj)) {
|
1545
|
-
if (!Number.isInteger(parser.getObj()) || !(0, _primitives.isCmd)(parser.getObj(),
|
1546
|
-
throw new _util.FormatError(
|
1647
|
+
if (!Number.isInteger(parser.getObj()) || !(0, _primitives.isCmd)(parser.getObj(), "obj") || !(0, _primitives.isStream)(obj = parser.getObj())) {
|
1648
|
+
throw new _util.FormatError("Invalid XRef stream");
|
1547
1649
|
}
|
1548
1650
|
|
1549
1651
|
dict = this.processXRefStream(obj);
|
@@ -1553,13 +1655,13 @@ var XRef = function XRefClosure() {
|
|
1553
1655
|
}
|
1554
1656
|
|
1555
1657
|
if (!dict) {
|
1556
|
-
throw new _util.FormatError(
|
1658
|
+
throw new _util.FormatError("Failed to read XRef stream");
|
1557
1659
|
}
|
1558
1660
|
} else {
|
1559
|
-
throw new _util.FormatError(
|
1661
|
+
throw new _util.FormatError("Invalid XRef stream header");
|
1560
1662
|
}
|
1561
1663
|
|
1562
|
-
obj = dict.get(
|
1664
|
+
obj = dict.get("Prev");
|
1563
1665
|
|
1564
1666
|
if (Number.isInteger(obj)) {
|
1565
1667
|
this.startXRefQueue.push(obj);
|
@@ -1572,18 +1674,18 @@ var XRef = function XRefClosure() {
|
|
1572
1674
|
|
1573
1675
|
return this.topDict;
|
1574
1676
|
} catch (e) {
|
1575
|
-
if (e instanceof
|
1677
|
+
if (e instanceof _core_utils.MissingDataException) {
|
1576
1678
|
throw e;
|
1577
1679
|
}
|
1578
1680
|
|
1579
|
-
(0, _util.info)(
|
1681
|
+
(0, _util.info)("(while reading XRef): " + e);
|
1580
1682
|
}
|
1581
1683
|
|
1582
1684
|
if (recoveryMode) {
|
1583
|
-
return;
|
1685
|
+
return undefined;
|
1584
1686
|
}
|
1585
1687
|
|
1586
|
-
throw new
|
1688
|
+
throw new _core_utils.XRefParseException();
|
1587
1689
|
},
|
1588
1690
|
getEntry: function XRef_getEntry(i) {
|
1589
1691
|
var xrefEntry = this.entries[i];
|
@@ -1595,22 +1697,22 @@ var XRef = function XRefClosure() {
|
|
1595
1697
|
return null;
|
1596
1698
|
},
|
1597
1699
|
fetchIfRef: function XRef_fetchIfRef(obj, suppressEncryption) {
|
1598
|
-
if (
|
1599
|
-
return obj;
|
1700
|
+
if (obj instanceof _primitives.Ref) {
|
1701
|
+
return this.fetch(obj, suppressEncryption);
|
1600
1702
|
}
|
1601
1703
|
|
1602
|
-
return
|
1704
|
+
return obj;
|
1603
1705
|
},
|
1604
1706
|
fetch: function XRef_fetch(ref, suppressEncryption) {
|
1605
|
-
if (!(
|
1606
|
-
throw new Error(
|
1707
|
+
if (!(ref instanceof _primitives.Ref)) {
|
1708
|
+
throw new Error("ref object is not a reference");
|
1607
1709
|
}
|
1608
1710
|
|
1609
|
-
|
1711
|
+
const num = ref.num;
|
1610
1712
|
|
1611
|
-
|
1612
|
-
var cacheEntry = this.cache[num];
|
1713
|
+
const cacheEntry = this._cacheMap.get(num);
|
1613
1714
|
|
1715
|
+
if (cacheEntry !== undefined) {
|
1614
1716
|
if (cacheEntry instanceof _primitives.Dict && !cacheEntry.objId) {
|
1615
1717
|
cacheEntry.objId = ref.toString();
|
1616
1718
|
}
|
@@ -1618,10 +1720,12 @@ var XRef = function XRefClosure() {
|
|
1618
1720
|
return cacheEntry;
|
1619
1721
|
}
|
1620
1722
|
|
1621
|
-
|
1723
|
+
let xrefEntry = this.getEntry(num);
|
1622
1724
|
|
1623
1725
|
if (xrefEntry === null) {
|
1624
|
-
|
1726
|
+
this._cacheMap.set(num, xrefEntry);
|
1727
|
+
|
1728
|
+
return xrefEntry;
|
1625
1729
|
}
|
1626
1730
|
|
1627
1731
|
if (xrefEntry.uncompressed) {
|
@@ -1638,35 +1742,31 @@ var XRef = function XRefClosure() {
|
|
1638
1742
|
|
1639
1743
|
return xrefEntry;
|
1640
1744
|
},
|
1641
|
-
|
1642
|
-
|
1745
|
+
|
1746
|
+
fetchUncompressed(ref, xrefEntry, suppressEncryption = false) {
|
1643
1747
|
var gen = ref.gen;
|
1644
1748
|
var num = ref.num;
|
1645
1749
|
|
1646
1750
|
if (xrefEntry.gen !== gen) {
|
1647
|
-
throw new
|
1751
|
+
throw new _core_utils.XRefEntryException(`Inconsistent generation in XRef: ${ref}`);
|
1648
1752
|
}
|
1649
1753
|
|
1650
1754
|
var stream = this.stream.makeSubStream(xrefEntry.offset + this.stream.start);
|
1651
|
-
|
1755
|
+
const parser = new _parser.Parser({
|
1756
|
+
lexer: new _parser.Lexer(stream),
|
1757
|
+
xref: this,
|
1758
|
+
allowStreams: true
|
1759
|
+
});
|
1652
1760
|
var obj1 = parser.getObj();
|
1653
1761
|
var obj2 = parser.getObj();
|
1654
1762
|
var obj3 = parser.getObj();
|
1655
1763
|
|
1656
|
-
if (!
|
1657
|
-
|
1764
|
+
if (obj1 !== num || obj2 !== gen || !(obj3 instanceof _primitives.Cmd)) {
|
1765
|
+
throw new _core_utils.XRefEntryException(`Bad (uncompressed) XRef entry: ${ref}`);
|
1658
1766
|
}
|
1659
1767
|
|
1660
|
-
if (
|
1661
|
-
|
1662
|
-
}
|
1663
|
-
|
1664
|
-
if (obj1 !== num || obj2 !== gen || !(0, _primitives.isCmd)(obj3)) {
|
1665
|
-
throw new _util.XRefEntryException("Bad (uncompressed) XRef entry: ".concat(ref));
|
1666
|
-
}
|
1667
|
-
|
1668
|
-
if (obj3.cmd !== 'obj') {
|
1669
|
-
if (obj3.cmd.startsWith('obj')) {
|
1768
|
+
if (obj3.cmd !== "obj") {
|
1769
|
+
if (obj3.cmd.startsWith("obj")) {
|
1670
1770
|
num = parseInt(obj3.cmd.substring(3), 10);
|
1671
1771
|
|
1672
1772
|
if (!Number.isNaN(num)) {
|
@@ -1674,7 +1774,7 @@ var XRef = function XRefClosure() {
|
|
1674
1774
|
}
|
1675
1775
|
}
|
1676
1776
|
|
1677
|
-
throw new
|
1777
|
+
throw new _core_utils.XRefEntryException(`Bad (uncompressed) XRef entry: ${ref}`);
|
1678
1778
|
}
|
1679
1779
|
|
1680
1780
|
if (this.encrypt && !suppressEncryption) {
|
@@ -1684,147 +1784,102 @@ var XRef = function XRefClosure() {
|
|
1684
1784
|
}
|
1685
1785
|
|
1686
1786
|
if (!(0, _primitives.isStream)(xrefEntry)) {
|
1687
|
-
this.
|
1787
|
+
this._cacheMap.set(num, xrefEntry);
|
1688
1788
|
}
|
1689
1789
|
|
1690
1790
|
return xrefEntry;
|
1691
1791
|
},
|
1692
|
-
|
1693
|
-
|
1694
|
-
|
1695
|
-
|
1792
|
+
|
1793
|
+
fetchCompressed(ref, xrefEntry, suppressEncryption = false) {
|
1794
|
+
const tableOffset = xrefEntry.offset;
|
1795
|
+
const stream = this.fetch(_primitives.Ref.get(tableOffset, 0));
|
1696
1796
|
|
1697
1797
|
if (!(0, _primitives.isStream)(stream)) {
|
1698
|
-
throw new _util.FormatError(
|
1798
|
+
throw new _util.FormatError("bad ObjStm stream");
|
1699
1799
|
}
|
1700
1800
|
|
1701
|
-
|
1702
|
-
|
1801
|
+
const first = stream.dict.get("First");
|
1802
|
+
const n = stream.dict.get("N");
|
1703
1803
|
|
1704
1804
|
if (!Number.isInteger(first) || !Number.isInteger(n)) {
|
1705
|
-
throw new _util.FormatError(
|
1805
|
+
throw new _util.FormatError("invalid first and n parameters for ObjStm stream");
|
1706
1806
|
}
|
1707
1807
|
|
1708
|
-
|
1709
|
-
|
1710
|
-
|
1711
|
-
|
1712
|
-
|
1713
|
-
|
1808
|
+
const parser = new _parser.Parser({
|
1809
|
+
lexer: new _parser.Lexer(stream),
|
1810
|
+
xref: this,
|
1811
|
+
allowStreams: true
|
1812
|
+
});
|
1813
|
+
const nums = new Array(n);
|
1714
1814
|
|
1715
|
-
for (i = 0; i < n; ++i) {
|
1716
|
-
num = parser.getObj();
|
1815
|
+
for (let i = 0; i < n; ++i) {
|
1816
|
+
const num = parser.getObj();
|
1717
1817
|
|
1718
1818
|
if (!Number.isInteger(num)) {
|
1719
|
-
throw new _util.FormatError(
|
1819
|
+
throw new _util.FormatError(`invalid object number in the ObjStm stream: ${num}`);
|
1720
1820
|
}
|
1721
1821
|
|
1722
|
-
|
1723
|
-
var offset = parser.getObj();
|
1822
|
+
const offset = parser.getObj();
|
1724
1823
|
|
1725
1824
|
if (!Number.isInteger(offset)) {
|
1726
|
-
throw new _util.FormatError(
|
1825
|
+
throw new _util.FormatError(`invalid object offset in the ObjStm stream: ${offset}`);
|
1727
1826
|
}
|
1827
|
+
|
1828
|
+
nums[i] = num;
|
1728
1829
|
}
|
1729
1830
|
|
1730
|
-
|
1731
|
-
|
1831
|
+
const entries = new Array(n);
|
1832
|
+
|
1833
|
+
for (let i = 0; i < n; ++i) {
|
1834
|
+
const obj = parser.getObj();
|
1835
|
+
entries[i] = obj;
|
1732
1836
|
|
1733
|
-
if (
|
1837
|
+
if (parser.buf1 instanceof _primitives.Cmd && parser.buf1.cmd === "endobj") {
|
1734
1838
|
parser.shift();
|
1735
1839
|
}
|
1736
1840
|
|
1737
|
-
|
1738
|
-
|
1841
|
+
if ((0, _primitives.isStream)(obj)) {
|
1842
|
+
continue;
|
1843
|
+
}
|
1844
|
+
|
1845
|
+
const num = nums[i],
|
1846
|
+
entry = this.entries[num];
|
1739
1847
|
|
1740
1848
|
if (entry && entry.offset === tableOffset && entry.gen === i) {
|
1741
|
-
this.
|
1849
|
+
this._cacheMap.set(num, obj);
|
1742
1850
|
}
|
1743
1851
|
}
|
1744
1852
|
|
1745
1853
|
xrefEntry = entries[xrefEntry.gen];
|
1746
1854
|
|
1747
1855
|
if (xrefEntry === undefined) {
|
1748
|
-
throw new
|
1856
|
+
throw new _core_utils.XRefEntryException(`Bad (compressed) XRef entry: ${ref}`);
|
1749
1857
|
}
|
1750
1858
|
|
1751
1859
|
return xrefEntry;
|
1752
1860
|
},
|
1753
|
-
fetchIfRefAsync: function () {
|
1754
|
-
var _fetchIfRefAsync = _asyncToGenerator(
|
1755
|
-
/*#__PURE__*/
|
1756
|
-
_regenerator.default.mark(function _callee(obj, suppressEncryption) {
|
1757
|
-
return _regenerator.default.wrap(function _callee$(_context) {
|
1758
|
-
while (1) {
|
1759
|
-
switch (_context.prev = _context.next) {
|
1760
|
-
case 0:
|
1761
|
-
if ((0, _primitives.isRef)(obj)) {
|
1762
|
-
_context.next = 2;
|
1763
|
-
break;
|
1764
|
-
}
|
1765
|
-
|
1766
|
-
return _context.abrupt("return", obj);
|
1767
|
-
|
1768
|
-
case 2:
|
1769
|
-
return _context.abrupt("return", this.fetchAsync(obj, suppressEncryption));
|
1770
|
-
|
1771
|
-
case 3:
|
1772
|
-
case "end":
|
1773
|
-
return _context.stop();
|
1774
|
-
}
|
1775
|
-
}
|
1776
|
-
}, _callee, this);
|
1777
|
-
}));
|
1778
|
-
|
1779
|
-
function fetchIfRefAsync(_x, _x2) {
|
1780
|
-
return _fetchIfRefAsync.apply(this, arguments);
|
1781
|
-
}
|
1782
|
-
|
1783
|
-
return fetchIfRefAsync;
|
1784
|
-
}(),
|
1785
|
-
fetchAsync: function () {
|
1786
|
-
var _fetchAsync = _asyncToGenerator(
|
1787
|
-
/*#__PURE__*/
|
1788
|
-
_regenerator.default.mark(function _callee2(ref, suppressEncryption) {
|
1789
|
-
return _regenerator.default.wrap(function _callee2$(_context2) {
|
1790
|
-
while (1) {
|
1791
|
-
switch (_context2.prev = _context2.next) {
|
1792
|
-
case 0:
|
1793
|
-
_context2.prev = 0;
|
1794
|
-
return _context2.abrupt("return", this.fetch(ref, suppressEncryption));
|
1795
|
-
|
1796
|
-
case 4:
|
1797
|
-
_context2.prev = 4;
|
1798
|
-
_context2.t0 = _context2["catch"](0);
|
1799
|
-
|
1800
|
-
if (_context2.t0 instanceof _util.MissingDataException) {
|
1801
|
-
_context2.next = 8;
|
1802
|
-
break;
|
1803
|
-
}
|
1804
1861
|
|
1805
|
-
|
1806
|
-
|
1807
|
-
|
1808
|
-
|
1809
|
-
return this.pdfManager.requestRange(_context2.t0.begin, _context2.t0.end);
|
1862
|
+
async fetchIfRefAsync(obj, suppressEncryption) {
|
1863
|
+
if (obj instanceof _primitives.Ref) {
|
1864
|
+
return this.fetchAsync(obj, suppressEncryption);
|
1865
|
+
}
|
1810
1866
|
|
1811
|
-
|
1812
|
-
|
1867
|
+
return obj;
|
1868
|
+
},
|
1813
1869
|
|
1814
|
-
|
1815
|
-
|
1816
|
-
|
1817
|
-
|
1818
|
-
|
1819
|
-
|
1820
|
-
|
1870
|
+
async fetchAsync(ref, suppressEncryption) {
|
1871
|
+
try {
|
1872
|
+
return this.fetch(ref, suppressEncryption);
|
1873
|
+
} catch (ex) {
|
1874
|
+
if (!(ex instanceof _core_utils.MissingDataException)) {
|
1875
|
+
throw ex;
|
1876
|
+
}
|
1821
1877
|
|
1822
|
-
|
1823
|
-
return
|
1878
|
+
await this.pdfManager.requestRange(ex.begin, ex.end);
|
1879
|
+
return this.fetchAsync(ref, suppressEncryption);
|
1824
1880
|
}
|
1881
|
+
},
|
1825
1882
|
|
1826
|
-
return fetchAsync;
|
1827
|
-
}(),
|
1828
1883
|
getCatalogObj: function XRef_getCatalogObj() {
|
1829
1884
|
return this.root;
|
1830
1885
|
}
|
@@ -1834,14 +1889,10 @@ var XRef = function XRefClosure() {
|
|
1834
1889
|
|
1835
1890
|
exports.XRef = XRef;
|
1836
1891
|
|
1837
|
-
|
1838
|
-
|
1839
|
-
function () {
|
1840
|
-
function NameOrNumberTree(root, xref, type) {
|
1841
|
-
_classCallCheck(this, NameOrNumberTree);
|
1842
|
-
|
1892
|
+
class NameOrNumberTree {
|
1893
|
+
constructor(root, xref, type) {
|
1843
1894
|
if (this.constructor === NameOrNumberTree) {
|
1844
|
-
(0, _util.unreachable)(
|
1895
|
+
(0, _util.unreachable)("Cannot initialize NameOrNumberTree.");
|
1845
1896
|
}
|
1846
1897
|
|
1847
1898
|
this.root = root;
|
@@ -1849,169 +1900,149 @@ function () {
|
|
1849
1900
|
this._type = type;
|
1850
1901
|
}
|
1851
1902
|
|
1852
|
-
|
1853
|
-
|
1854
|
-
value: function getAll() {
|
1855
|
-
var dict = Object.create(null);
|
1856
|
-
|
1857
|
-
if (!this.root) {
|
1858
|
-
return dict;
|
1859
|
-
}
|
1903
|
+
getAll() {
|
1904
|
+
const dict = Object.create(null);
|
1860
1905
|
|
1861
|
-
|
1862
|
-
|
1863
|
-
|
1864
|
-
var queue = [this.root];
|
1906
|
+
if (!this.root) {
|
1907
|
+
return dict;
|
1908
|
+
}
|
1865
1909
|
|
1866
|
-
|
1867
|
-
|
1910
|
+
const xref = this.xref;
|
1911
|
+
const processed = new _primitives.RefSet();
|
1912
|
+
processed.put(this.root);
|
1913
|
+
const queue = [this.root];
|
1868
1914
|
|
1869
|
-
|
1870
|
-
|
1871
|
-
}
|
1915
|
+
while (queue.length > 0) {
|
1916
|
+
const obj = xref.fetchIfRef(queue.shift());
|
1872
1917
|
|
1873
|
-
|
1874
|
-
|
1918
|
+
if (!(0, _primitives.isDict)(obj)) {
|
1919
|
+
continue;
|
1920
|
+
}
|
1875
1921
|
|
1876
|
-
|
1877
|
-
|
1922
|
+
if (obj.has("Kids")) {
|
1923
|
+
const kids = obj.get("Kids");
|
1878
1924
|
|
1879
|
-
|
1880
|
-
|
1881
|
-
}
|
1925
|
+
for (let i = 0, ii = kids.length; i < ii; i++) {
|
1926
|
+
const kid = kids[i];
|
1882
1927
|
|
1883
|
-
|
1884
|
-
|
1928
|
+
if (processed.has(kid)) {
|
1929
|
+
throw new _util.FormatError(`Duplicate entry in "${this._type}" tree.`);
|
1885
1930
|
}
|
1886
1931
|
|
1887
|
-
|
1932
|
+
queue.push(kid);
|
1933
|
+
processed.put(kid);
|
1888
1934
|
}
|
1889
1935
|
|
1890
|
-
|
1936
|
+
continue;
|
1937
|
+
}
|
1891
1938
|
|
1892
|
-
|
1893
|
-
|
1894
|
-
|
1895
|
-
|
1939
|
+
const entries = obj.get(this._type);
|
1940
|
+
|
1941
|
+
if (Array.isArray(entries)) {
|
1942
|
+
for (let i = 0, ii = entries.length; i < ii; i += 2) {
|
1943
|
+
dict[xref.fetchIfRef(entries[i])] = xref.fetchIfRef(entries[i + 1]);
|
1896
1944
|
}
|
1897
1945
|
}
|
1898
|
-
|
1899
|
-
return dict;
|
1900
1946
|
}
|
1901
|
-
}, {
|
1902
|
-
key: "get",
|
1903
|
-
value: function get(key) {
|
1904
|
-
if (!this.root) {
|
1905
|
-
return null;
|
1906
|
-
}
|
1907
1947
|
|
1908
|
-
|
1909
|
-
|
1910
|
-
var loopCount = 0;
|
1911
|
-
var MAX_LEVELS = 10;
|
1948
|
+
return dict;
|
1949
|
+
}
|
1912
1950
|
|
1913
|
-
|
1914
|
-
|
1915
|
-
|
1916
|
-
|
1917
|
-
}
|
1951
|
+
get(key) {
|
1952
|
+
if (!this.root) {
|
1953
|
+
return null;
|
1954
|
+
}
|
1918
1955
|
|
1919
|
-
|
1956
|
+
const xref = this.xref;
|
1957
|
+
let kidsOrEntries = xref.fetchIfRef(this.root);
|
1958
|
+
let loopCount = 0;
|
1959
|
+
const MAX_LEVELS = 10;
|
1920
1960
|
|
1921
|
-
|
1922
|
-
|
1923
|
-
}
|
1961
|
+
while (kidsOrEntries.has("Kids")) {
|
1962
|
+
if (++loopCount > MAX_LEVELS) {
|
1963
|
+
(0, _util.warn)(`Search depth limit reached for "${this._type}" tree.`);
|
1964
|
+
return null;
|
1965
|
+
}
|
1924
1966
|
|
1925
|
-
|
1926
|
-
r = kids.length - 1;
|
1967
|
+
const kids = kidsOrEntries.get("Kids");
|
1927
1968
|
|
1928
|
-
|
1929
|
-
|
1930
|
-
|
1931
|
-
var limits = kid.get('Limits');
|
1969
|
+
if (!Array.isArray(kids)) {
|
1970
|
+
return null;
|
1971
|
+
}
|
1932
1972
|
|
1933
|
-
|
1934
|
-
|
1935
|
-
} else if (key > xref.fetchIfRef(limits[1])) {
|
1936
|
-
l = m + 1;
|
1937
|
-
} else {
|
1938
|
-
kidsOrEntries = xref.fetchIfRef(kids[m]);
|
1939
|
-
break;
|
1940
|
-
}
|
1941
|
-
}
|
1973
|
+
let l = 0,
|
1974
|
+
r = kids.length - 1;
|
1942
1975
|
|
1943
|
-
|
1944
|
-
|
1976
|
+
while (l <= r) {
|
1977
|
+
const m = l + r >> 1;
|
1978
|
+
const kid = xref.fetchIfRef(kids[m]);
|
1979
|
+
const limits = kid.get("Limits");
|
1980
|
+
|
1981
|
+
if (key < xref.fetchIfRef(limits[0])) {
|
1982
|
+
r = m - 1;
|
1983
|
+
} else if (key > xref.fetchIfRef(limits[1])) {
|
1984
|
+
l = m + 1;
|
1985
|
+
} else {
|
1986
|
+
kidsOrEntries = xref.fetchIfRef(kids[m]);
|
1987
|
+
break;
|
1945
1988
|
}
|
1946
1989
|
}
|
1947
1990
|
|
1948
|
-
|
1991
|
+
if (l > r) {
|
1992
|
+
return null;
|
1993
|
+
}
|
1994
|
+
}
|
1949
1995
|
|
1950
|
-
|
1951
|
-
var _l = 0,
|
1952
|
-
_r = entries.length - 2;
|
1996
|
+
const entries = kidsOrEntries.get(this._type);
|
1953
1997
|
|
1954
|
-
|
1955
|
-
|
1956
|
-
|
1998
|
+
if (Array.isArray(entries)) {
|
1999
|
+
let l = 0,
|
2000
|
+
r = entries.length - 2;
|
1957
2001
|
|
1958
|
-
|
2002
|
+
while (l <= r) {
|
2003
|
+
const tmp = l + r >> 1,
|
2004
|
+
m = tmp + (tmp & 1);
|
2005
|
+
const currentKey = xref.fetchIfRef(entries[m]);
|
1959
2006
|
|
1960
|
-
|
1961
|
-
|
1962
|
-
|
1963
|
-
|
1964
|
-
|
1965
|
-
|
1966
|
-
}
|
2007
|
+
if (key < currentKey) {
|
2008
|
+
r = m - 2;
|
2009
|
+
} else if (key > currentKey) {
|
2010
|
+
l = m + 2;
|
2011
|
+
} else {
|
2012
|
+
return xref.fetchIfRef(entries[m + 1]);
|
1967
2013
|
}
|
2014
|
+
}
|
1968
2015
|
|
1969
|
-
|
2016
|
+
(0, _util.info)(`Falling back to an exhaustive search, for key "${key}", ` + `in "${this._type}" tree.`);
|
1970
2017
|
|
1971
|
-
|
1972
|
-
|
2018
|
+
for (let m = 0, mm = entries.length; m < mm; m += 2) {
|
2019
|
+
const currentKey = xref.fetchIfRef(entries[m]);
|
1973
2020
|
|
1974
|
-
|
1975
|
-
|
1976
|
-
|
1977
|
-
}
|
2021
|
+
if (currentKey === key) {
|
2022
|
+
(0, _util.warn)(`The "${key}" key was found at an incorrect, ` + `i.e. out-of-order, position in "${this._type}" tree.`);
|
2023
|
+
return xref.fetchIfRef(entries[m + 1]);
|
1978
2024
|
}
|
1979
2025
|
}
|
1980
|
-
|
1981
|
-
return null;
|
1982
2026
|
}
|
1983
|
-
}]);
|
1984
|
-
|
1985
|
-
return NameOrNumberTree;
|
1986
|
-
}();
|
1987
2027
|
|
1988
|
-
|
1989
|
-
/*#__PURE__*/
|
1990
|
-
function (_NameOrNumberTree) {
|
1991
|
-
_inherits(NameTree, _NameOrNumberTree);
|
1992
|
-
|
1993
|
-
function NameTree(root, xref) {
|
1994
|
-
_classCallCheck(this, NameTree);
|
1995
|
-
|
1996
|
-
return _possibleConstructorReturn(this, _getPrototypeOf(NameTree).call(this, root, xref, 'Names'));
|
2028
|
+
return null;
|
1997
2029
|
}
|
1998
2030
|
|
1999
|
-
|
2000
|
-
}(NameOrNumberTree);
|
2031
|
+
}
|
2001
2032
|
|
2002
|
-
|
2003
|
-
|
2004
|
-
|
2005
|
-
|
2033
|
+
class NameTree extends NameOrNumberTree {
|
2034
|
+
constructor(root, xref) {
|
2035
|
+
super(root, xref, "Names");
|
2036
|
+
}
|
2006
2037
|
|
2007
|
-
|
2008
|
-
_classCallCheck(this, NumberTree);
|
2038
|
+
}
|
2009
2039
|
|
2010
|
-
|
2040
|
+
class NumberTree extends NameOrNumberTree {
|
2041
|
+
constructor(root, xref) {
|
2042
|
+
super(root, xref, "Nums");
|
2011
2043
|
}
|
2012
2044
|
|
2013
|
-
|
2014
|
-
}(NameOrNumberTree);
|
2045
|
+
}
|
2015
2046
|
|
2016
2047
|
var FileSpec = function FileSpecClosure() {
|
2017
2048
|
function FileSpec(root, xref) {
|
@@ -2022,35 +2053,35 @@ var FileSpec = function FileSpecClosure() {
|
|
2022
2053
|
this.xref = xref;
|
2023
2054
|
this.root = root;
|
2024
2055
|
|
2025
|
-
if (root.has(
|
2026
|
-
this.fs = root.get(
|
2056
|
+
if (root.has("FS")) {
|
2057
|
+
this.fs = root.get("FS");
|
2027
2058
|
}
|
2028
2059
|
|
2029
|
-
this.description = root.has(
|
2060
|
+
this.description = root.has("Desc") ? (0, _util.stringToPDFString)(root.get("Desc")) : "";
|
2030
2061
|
|
2031
|
-
if (root.has(
|
2032
|
-
(0, _util.warn)(
|
2062
|
+
if (root.has("RF")) {
|
2063
|
+
(0, _util.warn)("Related file specifications are not supported");
|
2033
2064
|
}
|
2034
2065
|
|
2035
2066
|
this.contentAvailable = true;
|
2036
2067
|
|
2037
|
-
if (!root.has(
|
2068
|
+
if (!root.has("EF")) {
|
2038
2069
|
this.contentAvailable = false;
|
2039
|
-
(0, _util.warn)(
|
2070
|
+
(0, _util.warn)("Non-embedded file specifications are not supported");
|
2040
2071
|
}
|
2041
2072
|
}
|
2042
2073
|
|
2043
2074
|
function pickPlatformItem(dict) {
|
2044
|
-
if (dict.has(
|
2045
|
-
return dict.get(
|
2046
|
-
} else if (dict.has(
|
2047
|
-
return dict.get(
|
2048
|
-
} else if (dict.has(
|
2049
|
-
return dict.get(
|
2050
|
-
} else if (dict.has(
|
2051
|
-
return dict.get(
|
2052
|
-
} else if (dict.has(
|
2053
|
-
return dict.get(
|
2075
|
+
if (dict.has("UF")) {
|
2076
|
+
return dict.get("UF");
|
2077
|
+
} else if (dict.has("F")) {
|
2078
|
+
return dict.get("F");
|
2079
|
+
} else if (dict.has("Unix")) {
|
2080
|
+
return dict.get("Unix");
|
2081
|
+
} else if (dict.has("Mac")) {
|
2082
|
+
return dict.get("Mac");
|
2083
|
+
} else if (dict.has("DOS")) {
|
2084
|
+
return dict.get("DOS");
|
2054
2085
|
}
|
2055
2086
|
|
2056
2087
|
return null;
|
@@ -2059,8 +2090,8 @@ var FileSpec = function FileSpecClosure() {
|
|
2059
2090
|
FileSpec.prototype = {
|
2060
2091
|
get filename() {
|
2061
2092
|
if (!this._filename && this.root) {
|
2062
|
-
var filename = pickPlatformItem(this.root) ||
|
2063
|
-
this._filename = (0, _util.stringToPDFString)(filename).replace(/\\\\/g,
|
2093
|
+
var filename = pickPlatformItem(this.root) || "unnamed";
|
2094
|
+
this._filename = (0, _util.stringToPDFString)(filename).replace(/\\\\/g, "\\").replace(/\\\//g, "/").replace(/\\/g, "/");
|
2064
2095
|
}
|
2065
2096
|
|
2066
2097
|
return this._filename;
|
@@ -2072,7 +2103,7 @@ var FileSpec = function FileSpecClosure() {
|
|
2072
2103
|
}
|
2073
2104
|
|
2074
2105
|
if (!this.contentRef && this.root) {
|
2075
|
-
this.contentRef = pickPlatformItem(this.root.get(
|
2106
|
+
this.contentRef = pickPlatformItem(this.root.get("EF"));
|
2076
2107
|
}
|
2077
2108
|
|
2078
2109
|
var content = null;
|
@@ -2084,10 +2115,10 @@ var FileSpec = function FileSpecClosure() {
|
|
2084
2115
|
if (fileObj && (0, _primitives.isStream)(fileObj)) {
|
2085
2116
|
content = fileObj.getBytes();
|
2086
2117
|
} else {
|
2087
|
-
(0, _util.warn)(
|
2118
|
+
(0, _util.warn)("Embedded file specification points to non-existing/invalid " + "content");
|
2088
2119
|
}
|
2089
2120
|
} else {
|
2090
|
-
(0, _util.warn)(
|
2121
|
+
(0, _util.warn)("Embedded file specification does not have a content");
|
2091
2122
|
}
|
2092
2123
|
|
2093
2124
|
return content;
|
@@ -2106,26 +2137,26 @@ var FileSpec = function FileSpecClosure() {
|
|
2106
2137
|
|
2107
2138
|
exports.FileSpec = FileSpec;
|
2108
2139
|
|
2109
|
-
|
2140
|
+
const ObjectLoader = function () {
|
2110
2141
|
function mayHaveChildren(value) {
|
2111
|
-
return
|
2142
|
+
return value instanceof _primitives.Ref || value instanceof _primitives.Dict || Array.isArray(value) || (0, _primitives.isStream)(value);
|
2112
2143
|
}
|
2113
2144
|
|
2114
2145
|
function addChildren(node, nodesToVisit) {
|
2115
|
-
if (
|
2116
|
-
|
2117
|
-
|
2146
|
+
if (node instanceof _primitives.Dict || (0, _primitives.isStream)(node)) {
|
2147
|
+
const dict = node instanceof _primitives.Dict ? node : node.dict;
|
2148
|
+
const dictKeys = dict.getKeys();
|
2118
2149
|
|
2119
|
-
for (
|
2120
|
-
|
2150
|
+
for (let i = 0, ii = dictKeys.length; i < ii; i++) {
|
2151
|
+
const rawValue = dict.getRaw(dictKeys[i]);
|
2121
2152
|
|
2122
2153
|
if (mayHaveChildren(rawValue)) {
|
2123
2154
|
nodesToVisit.push(rawValue);
|
2124
2155
|
}
|
2125
2156
|
}
|
2126
2157
|
} else if (Array.isArray(node)) {
|
2127
|
-
for (
|
2128
|
-
|
2158
|
+
for (let i = 0, ii = node.length; i < ii; i++) {
|
2159
|
+
const value = node[i];
|
2129
2160
|
|
2130
2161
|
if (mayHaveChildren(value)) {
|
2131
2162
|
nodesToVisit.push(value);
|
@@ -2139,45 +2170,40 @@ var ObjectLoader = function () {
|
|
2139
2170
|
this.keys = keys;
|
2140
2171
|
this.xref = xref;
|
2141
2172
|
this.refSet = null;
|
2142
|
-
this.capability = null;
|
2143
2173
|
}
|
2144
2174
|
|
2145
2175
|
ObjectLoader.prototype = {
|
2146
|
-
|
2147
|
-
this.
|
2148
|
-
|
2149
|
-
if (!(this.xref.stream instanceof _chunked_stream.ChunkedStream) || this.xref.stream.getMissingChunks().length === 0) {
|
2150
|
-
this.capability.resolve();
|
2151
|
-
return this.capability.promise;
|
2176
|
+
async load() {
|
2177
|
+
if (!this.xref.stream.allChunksLoaded || this.xref.stream.allChunksLoaded()) {
|
2178
|
+
return undefined;
|
2152
2179
|
}
|
2153
2180
|
|
2154
|
-
|
2155
|
-
|
2181
|
+
const {
|
2182
|
+
keys,
|
2183
|
+
dict
|
2184
|
+
} = this;
|
2156
2185
|
this.refSet = new _primitives.RefSet();
|
2157
|
-
|
2186
|
+
const nodesToVisit = [];
|
2158
2187
|
|
2159
|
-
for (
|
2160
|
-
|
2188
|
+
for (let i = 0, ii = keys.length; i < ii; i++) {
|
2189
|
+
const rawValue = dict.getRaw(keys[i]);
|
2161
2190
|
|
2162
2191
|
if (rawValue !== undefined) {
|
2163
2192
|
nodesToVisit.push(rawValue);
|
2164
2193
|
}
|
2165
2194
|
}
|
2166
2195
|
|
2167
|
-
this._walk(nodesToVisit);
|
2168
|
-
|
2169
|
-
return this.capability.promise;
|
2196
|
+
return this._walk(nodesToVisit);
|
2170
2197
|
},
|
2171
|
-
_walk: function _walk(nodesToVisit) {
|
2172
|
-
var _this2 = this;
|
2173
2198
|
|
2174
|
-
|
2175
|
-
|
2199
|
+
async _walk(nodesToVisit) {
|
2200
|
+
const nodesToRevisit = [];
|
2201
|
+
const pendingRequests = [];
|
2176
2202
|
|
2177
2203
|
while (nodesToVisit.length) {
|
2178
|
-
|
2204
|
+
let currentNode = nodesToVisit.pop();
|
2179
2205
|
|
2180
|
-
if (
|
2206
|
+
if (currentNode instanceof _primitives.Ref) {
|
2181
2207
|
if (this.refSet.has(currentNode)) {
|
2182
2208
|
continue;
|
2183
2209
|
}
|
@@ -2186,7 +2212,7 @@ var ObjectLoader = function () {
|
|
2186
2212
|
this.refSet.put(currentNode);
|
2187
2213
|
currentNode = this.xref.fetch(currentNode);
|
2188
2214
|
} catch (ex) {
|
2189
|
-
if (!(ex instanceof
|
2215
|
+
if (!(ex instanceof _core_utils.MissingDataException)) {
|
2190
2216
|
throw ex;
|
2191
2217
|
}
|
2192
2218
|
|
@@ -2199,13 +2225,13 @@ var ObjectLoader = function () {
|
|
2199
2225
|
}
|
2200
2226
|
|
2201
2227
|
if (currentNode && currentNode.getBaseStreams) {
|
2202
|
-
|
2203
|
-
|
2228
|
+
const baseStreams = currentNode.getBaseStreams();
|
2229
|
+
let foundMissingData = false;
|
2204
2230
|
|
2205
|
-
for (
|
2206
|
-
|
2231
|
+
for (let i = 0, ii = baseStreams.length; i < ii; i++) {
|
2232
|
+
const stream = baseStreams[i];
|
2207
2233
|
|
2208
|
-
if (stream.
|
2234
|
+
if (stream.allChunksLoaded && !stream.allChunksLoaded()) {
|
2209
2235
|
foundMissingData = true;
|
2210
2236
|
pendingRequests.push({
|
2211
2237
|
begin: stream.start,
|
@@ -2223,23 +2249,23 @@ var ObjectLoader = function () {
|
|
2223
2249
|
}
|
2224
2250
|
|
2225
2251
|
if (pendingRequests.length) {
|
2226
|
-
this.xref.stream.manager.requestRanges(pendingRequests)
|
2227
|
-
for (var _i4 = 0, _ii3 = nodesToRevisit.length; _i4 < _ii3; _i4++) {
|
2228
|
-
var node = nodesToRevisit[_i4];
|
2252
|
+
await this.xref.stream.manager.requestRanges(pendingRequests);
|
2229
2253
|
|
2230
|
-
|
2231
|
-
|
2232
|
-
|
2254
|
+
for (let i = 0, ii = nodesToRevisit.length; i < ii; i++) {
|
2255
|
+
const node = nodesToRevisit[i];
|
2256
|
+
|
2257
|
+
if (node instanceof _primitives.Ref) {
|
2258
|
+
this.refSet.remove(node);
|
2233
2259
|
}
|
2260
|
+
}
|
2234
2261
|
|
2235
|
-
|
2236
|
-
}, this.capability.reject);
|
2237
|
-
return;
|
2262
|
+
return this._walk(nodesToRevisit);
|
2238
2263
|
}
|
2239
2264
|
|
2240
2265
|
this.refSet = null;
|
2241
|
-
|
2266
|
+
return undefined;
|
2242
2267
|
}
|
2268
|
+
|
2243
2269
|
};
|
2244
2270
|
return ObjectLoader;
|
2245
2271
|
}();
|