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