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