pdf-codec 3.1.3 → 3.2.0
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.
- package/README.md +2 -2
- package/dist/annotations.cjs +104 -0
- package/dist/annotations.d.cts +9 -0
- package/dist/annotations.d.ts +9 -0
- package/dist/annotations.js +103 -0
- package/dist/attachments.cjs +65 -0
- package/dist/attachments.d.cts +8 -0
- package/dist/attachments.d.ts +8 -0
- package/dist/attachments.js +64 -0
- package/dist/bytes/flate.cjs +1 -1
- package/dist/bytes/flate.js +1 -1
- package/dist/codec.d.cts +109 -0
- package/dist/codec.d.ts +109 -0
- package/dist/content-read.cjs +1 -1
- package/dist/content-read.js +1 -1
- package/dist/content-write.cjs +2 -2
- package/dist/content-write.js +2 -2
- package/dist/document.cjs +12 -3
- package/dist/document.d.cts +2 -0
- package/dist/document.d.ts +2 -0
- package/dist/document.js +12 -3
- package/dist/embedded-font-write.cjs +1 -1
- package/dist/embedded-font-write.js +1 -1
- package/dist/encrypt.cjs +1 -1
- package/dist/encrypt.js +1 -1
- package/dist/filters.cjs +1 -1
- package/dist/filters.js +1 -1
- package/dist/font-read.cjs +1 -1
- package/dist/font-read.js +1 -1
- package/dist/font-registry.cjs +1 -1
- package/dist/font-registry.js +1 -1
- package/dist/form.cjs +138 -0
- package/dist/form.d.cts +9 -0
- package/dist/form.d.ts +9 -0
- package/dist/form.js +137 -0
- package/dist/image/png-decode.cjs +1 -1
- package/dist/image/png-decode.js +1 -1
- package/dist/image/png-encode.cjs +1 -1
- package/dist/image/png-encode.js +1 -1
- package/dist/index.cjs +12 -2
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/dist/interpret.cjs +70 -10
- package/dist/interpret.d.cts +9 -1
- package/dist/interpret.d.ts +9 -1
- package/dist/interpret.js +70 -10
- package/dist/layout.cjs +132 -2
- package/dist/layout.d.cts +335 -1
- package/dist/layout.d.ts +335 -1
- package/dist/layout.js +124 -4
- package/dist/math-content-write.cjs +1 -1
- package/dist/math-content-write.js +1 -1
- package/dist/math-font.cjs +1 -1
- package/dist/math-font.js +1 -1
- package/dist/names.cjs +41 -0
- package/dist/names.d.cts +11 -0
- package/dist/names.d.ts +11 -0
- package/dist/names.js +40 -0
- package/dist/navigation.cjs +210 -0
- package/dist/navigation.d.cts +18 -0
- package/dist/navigation.d.ts +18 -0
- package/dist/navigation.js +207 -0
- package/dist/optional-content.cjs +63 -0
- package/dist/optional-content.d.cts +12 -0
- package/dist/optional-content.d.ts +12 -0
- package/dist/optional-content.js +62 -0
- package/dist/parse.cjs +1 -1
- package/dist/parse.d.cts +1 -1
- package/dist/parse.d.ts +1 -1
- package/dist/parse.js +1 -1
- package/dist/pdf-text.cjs +21 -0
- package/dist/pdf-text.d.cts +5 -0
- package/dist/pdf-text.d.ts +5 -0
- package/dist/pdf-text.js +19 -0
- package/dist/read.cjs +128 -58
- package/dist/read.d.cts +2 -4
- package/dist/read.d.ts +2 -4
- package/dist/read.js +125 -53
- package/dist/serialize.cjs +5 -1
- package/dist/serialize.d.cts +3 -2
- package/dist/serialize.d.ts +3 -2
- package/dist/serialize.js +5 -2
- package/dist/write.cjs +51 -5
- package/dist/write.js +51 -5
- package/dist/xmp.cjs +46 -0
- package/dist/xmp.d.cts +14 -0
- package/dist/xmp.d.ts +14 -0
- package/dist/xmp.js +45 -0
- package/dist/xref.cjs +2 -2
- package/dist/xref.js +2 -2
- package/package.json +2 -2
package/dist/read.cjs
CHANGED
|
@@ -1,18 +1,26 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
require("./notes-annotation-author.cjs");
|
|
3
|
+
const require_objects = require("./objects.cjs");
|
|
4
|
+
const require_pdf_text = require("./pdf-text.cjs");
|
|
5
|
+
const require_bytes_writer = require("./bytes/writer.cjs");
|
|
6
|
+
const require_serialize = require("./serialize.cjs");
|
|
7
|
+
const require_matrix = require("./matrix.cjs");
|
|
8
|
+
const require_annotations = require("./annotations.cjs");
|
|
9
|
+
const require_filters = require("./filters.cjs");
|
|
2
10
|
const require_util_base64 = require("./util/base64.cjs");
|
|
11
|
+
const require_attachments = require("./attachments.cjs");
|
|
3
12
|
const require_bytes_crc32 = require("./bytes/crc32.cjs");
|
|
4
|
-
const
|
|
13
|
+
const require_form = require("./form.cjs");
|
|
14
|
+
const require_xmp = require("./xmp.cjs");
|
|
15
|
+
const require_optional_content = require("./optional-content.cjs");
|
|
5
16
|
require("./layout.cjs");
|
|
6
17
|
const require_diagnostics = require("./diagnostics.cjs");
|
|
7
|
-
const require_objects = require("./objects.cjs");
|
|
8
|
-
const require_filters = require("./filters.cjs");
|
|
9
18
|
const require_document = require("./document.cjs");
|
|
10
19
|
const require_util_abort = require("./util/abort.cjs");
|
|
11
20
|
const require_font_read = require("./font-read.cjs");
|
|
12
21
|
const require_images_read = require("./images-read.cjs");
|
|
13
|
-
const require_matrix = require("./matrix.cjs");
|
|
14
22
|
const require_interpret = require("./interpret.cjs");
|
|
15
|
-
require("./
|
|
23
|
+
const require_navigation = require("./navigation.cjs");
|
|
16
24
|
//#region src/read.ts
|
|
17
25
|
const PDF_HEADER_BYTES = new TextEncoder().encode("%PDF-");
|
|
18
26
|
const HEADER_SEARCH_WINDOW = 1024;
|
|
@@ -38,15 +46,28 @@ function readPdf(bytes, options) {
|
|
|
38
46
|
});
|
|
39
47
|
const images = {};
|
|
40
48
|
const imageIdCache = /* @__PURE__ */ new Map();
|
|
41
|
-
const
|
|
49
|
+
const pageDicts = doc.pages();
|
|
50
|
+
const destinationRegistry = require_navigation.createDestinationRegistry(doc.catalog, doc, (obj) => doc.pageIndex(obj), sink);
|
|
51
|
+
const outline = require_navigation.readOutline(doc.catalog, destinationRegistry, doc, sink);
|
|
52
|
+
const attachments = require_attachments.readAttachments(doc.catalog, pageDicts, doc, sink);
|
|
53
|
+
const optionalContent = require_optional_content.readOptionalContent(doc.catalog, doc, sink);
|
|
54
|
+
const form = require_form.readAcroForm(doc.catalog, doc, (obj) => doc.pageIndex(obj), sink);
|
|
55
|
+
const source = readDocumentResidue(doc, sink);
|
|
56
|
+
const pages = pageDicts.map((pageDict) => {
|
|
42
57
|
require_util_abort.throwIfAborted(signal);
|
|
43
|
-
return readPage(pageDict, doc, fontResolver, images, imageIdCache, sink);
|
|
58
|
+
return readPage(pageDict, doc, fontResolver, images, imageIdCache, destinationRegistry, optionalContent.layerNameOf, sink);
|
|
44
59
|
});
|
|
45
60
|
return {
|
|
46
61
|
formatVersion: 1,
|
|
47
|
-
metadata: readMetadata(doc.trailer, doc),
|
|
62
|
+
metadata: readMetadata(doc.trailer, doc, doc.catalog, sink),
|
|
48
63
|
pages,
|
|
49
|
-
images
|
|
64
|
+
images,
|
|
65
|
+
...destinationRegistry.entries.length > 0 ? { destinations: [...destinationRegistry.entries] } : {},
|
|
66
|
+
...outline.length > 0 ? { outline } : {},
|
|
67
|
+
...attachments.length > 0 ? { attachments } : {},
|
|
68
|
+
...optionalContent.layers.length > 0 ? { layers: [...optionalContent.layers] } : {},
|
|
69
|
+
...form.length > 0 ? { form } : {},
|
|
70
|
+
...Object.keys(source).length > 0 ? { source } : {}
|
|
50
71
|
};
|
|
51
72
|
}
|
|
52
73
|
function readMediaBox(page) {
|
|
@@ -136,7 +157,7 @@ function readPageContentBytes(page, resolver, sink) {
|
|
|
136
157
|
}
|
|
137
158
|
return /* @__PURE__ */ new Uint8Array(0);
|
|
138
159
|
}
|
|
139
|
-
function readPage(page, resolver, fontResolver, images, imageIdCache, sink) {
|
|
160
|
+
function readPage(page, resolver, fontResolver, images, imageIdCache, destinationRegistry, layerNameOf, sink) {
|
|
140
161
|
const resources = resolver.resolveDict(require_objects.dictGet(page, "Resources"));
|
|
141
162
|
const mediaBox = readMediaBox(page);
|
|
142
163
|
const rotationResult = pageRotationTransform(normalizeRotation(require_objects.asNumber(require_objects.dictGet(page, "Rotate"))), mediaBox.urx - mediaBox.llx, mediaBox.ury - mediaBox.lly);
|
|
@@ -147,7 +168,8 @@ function readPage(page, resolver, fontResolver, images, imageIdCache, sink) {
|
|
|
147
168
|
const extracted = require_interpret.interpretContentStream(contentBytes, resources, {
|
|
148
169
|
fontMetrics: fontResolver.metrics,
|
|
149
170
|
resolver,
|
|
150
|
-
sink
|
|
171
|
+
sink,
|
|
172
|
+
layerNameOf
|
|
151
173
|
});
|
|
152
174
|
for (const item of extracted) {
|
|
153
175
|
const converted = convertExtractedItem(item, pageMatrix, fontResolver, images, imageIdCache, resolver, sink);
|
|
@@ -158,13 +180,15 @@ function readPage(page, resolver, fontResolver, images, imageIdCache, sink) {
|
|
|
158
180
|
severity: "warning",
|
|
159
181
|
message: "page has no /Resources dict; its content stream cannot be interpreted"
|
|
160
182
|
});
|
|
161
|
-
items.push(...readLinkAnnotations(page, pageMatrix, resolver));
|
|
183
|
+
items.push(...readLinkAnnotations(page, pageMatrix, resolver, destinationRegistry));
|
|
162
184
|
const notes = readPageNotes(page, resolver);
|
|
185
|
+
const annotations = require_annotations.readPageAnnotations(page, pageMatrix, resolver, sink);
|
|
163
186
|
return {
|
|
164
187
|
widthPt: rotationResult.widthPt,
|
|
165
188
|
heightPt: rotationResult.heightPt,
|
|
166
189
|
items,
|
|
167
|
-
...notes !== void 0 ? { notes } : {}
|
|
190
|
+
...notes !== void 0 ? { notes } : {},
|
|
191
|
+
...annotations.length > 0 ? { annotations } : {}
|
|
168
192
|
};
|
|
169
193
|
}
|
|
170
194
|
function convertExtractedItem(item, pageMatrix, fontResolver, images, imageIdCache, resolver, sink) {
|
|
@@ -199,7 +223,10 @@ function convertText(item, pageMatrix, fontResolver) {
|
|
|
199
223
|
sizePt: sizePt > 0 ? sizePt : item.sizePt,
|
|
200
224
|
color: item.color,
|
|
201
225
|
widthPt,
|
|
202
|
-
rotationDeg: rotationDeg !== 0 ? rotationDeg : void 0
|
|
226
|
+
rotationDeg: rotationDeg !== 0 ? rotationDeg : void 0,
|
|
227
|
+
...item.layerName !== void 0 ? { layer: item.layerName } : {},
|
|
228
|
+
...item.actualText !== void 0 ? { actualText: item.actualText } : {},
|
|
229
|
+
...item.alt !== void 0 ? { alt: item.alt } : {}
|
|
203
230
|
};
|
|
204
231
|
}
|
|
205
232
|
function paintFields(paint) {
|
|
@@ -228,14 +255,16 @@ function convertRect(item, pageMatrix) {
|
|
|
228
255
|
return {
|
|
229
256
|
kind: "rect",
|
|
230
257
|
...transformBox(item, pageMatrix),
|
|
231
|
-
...paintFields(item)
|
|
258
|
+
...paintFields(item),
|
|
259
|
+
...item.layerName !== void 0 ? { layer: item.layerName } : {}
|
|
232
260
|
};
|
|
233
261
|
}
|
|
234
262
|
function convertEllipse(item, pageMatrix) {
|
|
235
263
|
return {
|
|
236
264
|
kind: "ellipse",
|
|
237
265
|
...transformBox(item, pageMatrix),
|
|
238
|
-
...paintFields(item)
|
|
266
|
+
...paintFields(item),
|
|
267
|
+
...item.layerName !== void 0 ? { layer: item.layerName } : {}
|
|
239
268
|
};
|
|
240
269
|
}
|
|
241
270
|
function convertLine(item, pageMatrix) {
|
|
@@ -254,7 +283,8 @@ function convertLine(item, pageMatrix) {
|
|
|
254
283
|
x2Pt: p2.x,
|
|
255
284
|
y2Pt: p2.y,
|
|
256
285
|
color: item.color,
|
|
257
|
-
widthPt: item.widthPt
|
|
286
|
+
widthPt: item.widthPt,
|
|
287
|
+
...item.layerName !== void 0 ? { layer: item.layerName } : {}
|
|
258
288
|
};
|
|
259
289
|
}
|
|
260
290
|
function transformSubpath(subpath, pageMatrix) {
|
|
@@ -309,7 +339,8 @@ function convertPath(item, pageMatrix) {
|
|
|
309
339
|
subpaths: item.subpaths.map((subpath) => transformSubpath(subpath, pageMatrix)),
|
|
310
340
|
...item.fill !== void 0 ? { fill: item.fill } : {},
|
|
311
341
|
...item.fill !== void 0 && item.fillRule === "evenodd" ? { fillRule: "evenodd" } : {},
|
|
312
|
-
...item.stroke !== void 0 ? { stroke: item.stroke } : {}
|
|
342
|
+
...item.stroke !== void 0 ? { stroke: item.stroke } : {},
|
|
343
|
+
...item.layerName !== void 0 ? { layer: item.layerName } : {}
|
|
313
344
|
};
|
|
314
345
|
}
|
|
315
346
|
function imagePlacementFrom(matrix) {
|
|
@@ -352,7 +383,8 @@ function convertImage(item, pageMatrix, images, cache, resolver, sink) {
|
|
|
352
383
|
return {
|
|
353
384
|
kind: "image",
|
|
354
385
|
imageId,
|
|
355
|
-
...imagePlacementFrom(require_matrix.multiplyMatrices(item.matrix, pageMatrix))
|
|
386
|
+
...imagePlacementFrom(require_matrix.multiplyMatrices(item.matrix, pageMatrix)),
|
|
387
|
+
...item.layerName !== void 0 ? { layer: item.layerName } : {}
|
|
356
388
|
};
|
|
357
389
|
}
|
|
358
390
|
function convertInlineImage(item, pageMatrix, images, resolver, sink) {
|
|
@@ -361,19 +393,22 @@ function convertInlineImage(item, pageMatrix, images, resolver, sink) {
|
|
|
361
393
|
return {
|
|
362
394
|
kind: "image",
|
|
363
395
|
imageId: registerExtractedImage(decoded.format, decoded.bytes, decoded.widthPx, decoded.heightPx, images),
|
|
364
|
-
...imagePlacementFrom(require_matrix.multiplyMatrices(item.matrix, pageMatrix))
|
|
396
|
+
...imagePlacementFrom(require_matrix.multiplyMatrices(item.matrix, pageMatrix)),
|
|
397
|
+
...item.layerName !== void 0 ? { layer: item.layerName } : {}
|
|
365
398
|
};
|
|
366
399
|
}
|
|
367
|
-
function readLinkAnnotations(page, pageMatrix, resolver) {
|
|
400
|
+
function readLinkAnnotations(page, pageMatrix, resolver, destinationRegistry) {
|
|
368
401
|
const annotsArr = require_objects.asArray(require_objects.dictGet(page, "Annots"));
|
|
369
402
|
if (annotsArr === void 0) return [];
|
|
370
403
|
const links = [];
|
|
371
404
|
for (const annotRef of annotsArr) {
|
|
372
405
|
const annot = resolver.resolveDict(annotRef);
|
|
373
406
|
if (annot === void 0 || require_objects.asName(require_objects.dictGet(annot, "Subtype")) !== "Link") continue;
|
|
374
|
-
const uri = readLinkUri(annot, resolver);
|
|
375
407
|
const rectArr = require_objects.asArray(require_objects.dictGet(annot, "Rect"));
|
|
376
|
-
if (
|
|
408
|
+
if (rectArr === void 0) continue;
|
|
409
|
+
const uri = readLinkUri(annot, resolver);
|
|
410
|
+
const destination = uri === void 0 ? readInternalDestination(annot, resolver, destinationRegistry) : void 0;
|
|
411
|
+
if (uri === void 0 && destination === void 0) continue;
|
|
377
412
|
const x1 = require_objects.asNumber(rectArr[0]) ?? 0;
|
|
378
413
|
const y1 = require_objects.asNumber(rectArr[1]) ?? 0;
|
|
379
414
|
const x2 = require_objects.asNumber(rectArr[2]) ?? 0;
|
|
@@ -386,13 +421,24 @@ function readLinkAnnotations(page, pageMatrix, resolver) {
|
|
|
386
421
|
x: Math.max(x1, x2),
|
|
387
422
|
y: Math.max(y1, y2)
|
|
388
423
|
});
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
424
|
+
const contentsObj = require_objects.dictGet(annot, "Contents");
|
|
425
|
+
const title = contentsObj?.kind === "string" ? require_pdf_text.decodePdfString(contentsObj.bytes) : void 0;
|
|
426
|
+
const box = {
|
|
392
427
|
xPt: Math.min(p1.x, p2.x),
|
|
393
428
|
yPt: Math.min(p1.y, p2.y),
|
|
394
429
|
widthPt: Math.abs(p2.x - p1.x),
|
|
395
|
-
heightPt: Math.abs(p2.y - p1.y)
|
|
430
|
+
heightPt: Math.abs(p2.y - p1.y),
|
|
431
|
+
...title !== void 0 ? { title } : {}
|
|
432
|
+
};
|
|
433
|
+
if (uri !== void 0) links.push({
|
|
434
|
+
kind: "link",
|
|
435
|
+
uri,
|
|
436
|
+
...box
|
|
437
|
+
});
|
|
438
|
+
else if (destination !== void 0) links.push({
|
|
439
|
+
kind: "internalLink",
|
|
440
|
+
destination,
|
|
441
|
+
...box
|
|
396
442
|
});
|
|
397
443
|
}
|
|
398
444
|
return links;
|
|
@@ -401,7 +447,13 @@ function readLinkUri(annot, resolver) {
|
|
|
401
447
|
const action = resolver.resolveDict(require_objects.dictGet(annot, "A"));
|
|
402
448
|
if (action === void 0 || require_objects.asName(require_objects.dictGet(action, "S")) !== "URI") return;
|
|
403
449
|
const uriObj = require_objects.dictGet(action, "URI");
|
|
404
|
-
return uriObj?.kind === "string" ? decodePdfString(uriObj.bytes) : void 0;
|
|
450
|
+
return uriObj?.kind === "string" ? require_pdf_text.decodePdfString(uriObj.bytes) : void 0;
|
|
451
|
+
}
|
|
452
|
+
function readInternalDestination(annot, resolver, destinationRegistry) {
|
|
453
|
+
const dest = require_objects.dictGet(annot, "Dest");
|
|
454
|
+
if (dest !== void 0) return destinationRegistry.intern(dest);
|
|
455
|
+
const action = resolver.resolveDict(require_objects.dictGet(annot, "A"));
|
|
456
|
+
if (action !== void 0 && require_objects.asName(require_objects.dictGet(action, "S")) === "GoTo") return destinationRegistry.intern(require_objects.dictGet(action, "D"));
|
|
405
457
|
}
|
|
406
458
|
function readPageNotes(page, resolver) {
|
|
407
459
|
const annotsArr = require_objects.asArray(require_objects.dictGet(page, "Annots"));
|
|
@@ -410,49 +462,67 @@ function readPageNotes(page, resolver) {
|
|
|
410
462
|
const annot = resolver.resolveDict(annotRef);
|
|
411
463
|
if (annot === void 0 || require_objects.asName(require_objects.dictGet(annot, "Subtype")) !== "Text") continue;
|
|
412
464
|
const titleObj = require_objects.dictGet(annot, "T");
|
|
413
|
-
if ((titleObj?.kind === "string" ? decodePdfString(titleObj.bytes) : void 0) !== "documents.js:notes") continue;
|
|
465
|
+
if ((titleObj?.kind === "string" ? require_pdf_text.decodePdfString(titleObj.bytes) : void 0) !== "documents.js:notes") continue;
|
|
414
466
|
const contentsObj = require_objects.dictGet(annot, "Contents");
|
|
415
|
-
if (contentsObj?.kind === "string") return decodePdfString(contentsObj.bytes);
|
|
467
|
+
if (contentsObj?.kind === "string") return require_pdf_text.decodePdfString(contentsObj.bytes);
|
|
416
468
|
}
|
|
417
469
|
}
|
|
418
|
-
function
|
|
419
|
-
if (bytes.length >= 2 && bytes[0] === 254 && bytes[1] === 255) {
|
|
420
|
-
let out = "";
|
|
421
|
-
for (let i = 2; i + 1 < bytes.length; i += 2) out += String.fromCharCode((bytes[i] ?? 0) << 8 | (bytes[i + 1] ?? 0));
|
|
422
|
-
return out;
|
|
423
|
-
}
|
|
424
|
-
return Array.from(bytes, (b) => String.fromCharCode(b)).join("");
|
|
425
|
-
}
|
|
426
|
-
const PDF_DATE_PATTERN = /^D:(\d{4})(\d{2})?(\d{2})?(\d{2})?(\d{2})?(\d{2})?([+\-Z])?(\d{2})?'?(\d{2})?'?$/;
|
|
427
|
-
function parsePdfDate(raw) {
|
|
428
|
-
if (raw === void 0) return;
|
|
429
|
-
const match = PDF_DATE_PATTERN.exec(raw);
|
|
430
|
-
if (match === null) return;
|
|
431
|
-
const [, year, month = "01", day = "01", hour = "00", minute = "00", second = "00", tzSign, tzHour = "00", tzMinute = "00"] = match;
|
|
432
|
-
return `${year}-${month}-${day}T${hour}:${minute}:${second}${tzSign === void 0 || tzSign === "Z" ? "Z" : `${tzSign}${tzHour}:${tzMinute}`}`;
|
|
433
|
-
}
|
|
434
|
-
function readMetadata(trailer, resolver) {
|
|
470
|
+
function readMetadata(trailer, resolver, catalog, sink) {
|
|
435
471
|
const info = resolver.resolveDict(require_objects.dictGet(trailer, "Info"));
|
|
436
472
|
if (info === void 0) return {};
|
|
437
473
|
const stringField = (key) => {
|
|
438
474
|
const obj = require_objects.dictGet(info, key);
|
|
439
|
-
return obj?.kind === "string" ? decodePdfString(obj.bytes) : void 0;
|
|
475
|
+
return obj?.kind === "string" ? require_pdf_text.decodePdfString(obj.bytes) : void 0;
|
|
440
476
|
};
|
|
441
477
|
const keywords = stringField("Keywords")?.split(",").map((k) => k.trim()).filter((k) => k.length > 0);
|
|
478
|
+
const langObj = require_objects.dictGet(catalog, "Lang");
|
|
479
|
+
const xmp = xmpPacket(catalog, resolver, sink);
|
|
480
|
+
const mirrored = require_xmp.readXmpMetadata(xmp ?? "");
|
|
442
481
|
return {
|
|
443
|
-
title: stringField("Title"),
|
|
444
|
-
author: stringField("Author"),
|
|
445
|
-
subject: stringField("Subject"),
|
|
446
|
-
keywords: keywords !== void 0 && keywords.length > 0 ? keywords : void 0,
|
|
447
|
-
creator: stringField("Creator"),
|
|
448
|
-
producer: stringField("Producer"),
|
|
449
|
-
createdIso: parsePdfDate(stringField("CreationDate")),
|
|
450
|
-
modifiedIso: parsePdfDate(stringField("ModDate"))
|
|
482
|
+
title: stringField("Title") ?? mirrored.title,
|
|
483
|
+
author: stringField("Author") ?? mirrored.author,
|
|
484
|
+
subject: stringField("Subject") ?? mirrored.subject,
|
|
485
|
+
keywords: (keywords !== void 0 && keywords.length > 0 ? keywords : void 0) ?? mirrored.keywords,
|
|
486
|
+
creator: stringField("Creator") ?? mirrored.creator,
|
|
487
|
+
producer: stringField("Producer") ?? mirrored.producer,
|
|
488
|
+
createdIso: require_pdf_text.parsePdfDate(stringField("CreationDate")) ?? mirrored.createdIso,
|
|
489
|
+
modifiedIso: require_pdf_text.parsePdfDate(stringField("ModDate")) ?? mirrored.modifiedIso,
|
|
490
|
+
...langObj?.kind === "string" ? { language: require_pdf_text.decodePdfString(langObj.bytes) } : {}
|
|
491
|
+
};
|
|
492
|
+
}
|
|
493
|
+
function xmpPacket(catalog, resolver, sink) {
|
|
494
|
+
const metadataObj = resolver.resolve(require_objects.dictGet(catalog, "Metadata"));
|
|
495
|
+
if (metadataObj?.kind !== "stream") return;
|
|
496
|
+
const decoded = require_filters.decodeStream(metadataObj.raw, metadataObj.dict, sink);
|
|
497
|
+
return new TextDecoder().decode(decoded.bytes);
|
|
498
|
+
}
|
|
499
|
+
function readDocumentResidue(doc, sink) {
|
|
500
|
+
const source = {};
|
|
501
|
+
const residue = (key, obj) => {
|
|
502
|
+
if (obj !== void 0) source[key] = {
|
|
503
|
+
format: "pdf",
|
|
504
|
+
xml: require_serialize.serializeObjectToText(obj)
|
|
505
|
+
};
|
|
506
|
+
};
|
|
507
|
+
const catalog = doc.catalog;
|
|
508
|
+
const packet = xmpPacket(catalog, doc, sink);
|
|
509
|
+
if (packet !== void 0) source.xmp = {
|
|
510
|
+
format: "pdf",
|
|
511
|
+
xml: packet
|
|
451
512
|
};
|
|
513
|
+
residue("viewer-preferences", require_objects.dictGet(catalog, "ViewerPreferences"));
|
|
514
|
+
residue("page-mode", require_objects.dictGet(catalog, "PageMode"));
|
|
515
|
+
residue("page-layout", require_objects.dictGet(catalog, "PageLayout"));
|
|
516
|
+
residue("open-action", require_objects.dictGet(catalog, "OpenAction"));
|
|
517
|
+
const outputIntents = require_objects.asArray(require_objects.dictGet(catalog, "OutputIntents"));
|
|
518
|
+
if (outputIntents !== void 0) residue("output-intents", require_objects.pdfArray(outputIntents.map((intent) => doc.resolve(intent) ?? require_objects.pdfNull())));
|
|
519
|
+
residue("piece-info", require_objects.dictGet(catalog, "PieceInfo"));
|
|
520
|
+
residue("legal", require_objects.dictGet(catalog, "Legal"));
|
|
521
|
+
residue("collection", require_objects.dictGet(catalog, "Collection"));
|
|
522
|
+
residue("trailer-id", require_objects.dictGet(doc.trailer, "ID"));
|
|
523
|
+
return source;
|
|
452
524
|
}
|
|
453
525
|
//#endregion
|
|
454
|
-
exports.decodePdfString = decodePdfString;
|
|
455
526
|
exports.normalizeRotation = normalizeRotation;
|
|
456
527
|
exports.pageRotationTransform = pageRotationTransform;
|
|
457
|
-
exports.parsePdfDate = parsePdfDate;
|
|
458
528
|
exports.readPdf = readPdf;
|
package/dist/read.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PdfDiagnosticSink } from "./diagnostics.cjs";
|
|
2
|
-
import { LayoutDocument } from "./layout.cjs";
|
|
3
2
|
import { r as Matrix } from "./matrix-B7_SBKQ5.cjs";
|
|
3
|
+
import { LayoutDocument } from "./layout.cjs";
|
|
4
4
|
//#region src/read.d.ts
|
|
5
5
|
interface ReadPdfOptions {
|
|
6
6
|
readonly sink?: PdfDiagnosticSink;
|
|
@@ -15,7 +15,5 @@ interface PageRotationResult {
|
|
|
15
15
|
readonly heightPt: number;
|
|
16
16
|
}
|
|
17
17
|
declare function pageRotationTransform(rotation: PageRotation, w: number, h: number): PageRotationResult;
|
|
18
|
-
declare function decodePdfString(bytes: Uint8Array<ArrayBuffer>): string;
|
|
19
|
-
declare function parsePdfDate(raw: string | undefined): string | undefined;
|
|
20
18
|
//#endregion
|
|
21
|
-
export { ReadPdfOptions,
|
|
19
|
+
export { ReadPdfOptions, normalizeRotation, pageRotationTransform, readPdf };
|
package/dist/read.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PdfDiagnosticSink } from "./diagnostics.js";
|
|
2
|
-
import { LayoutDocument } from "./layout.js";
|
|
3
2
|
import { r as Matrix } from "./matrix-B7_SBKQ5.js";
|
|
3
|
+
import { LayoutDocument } from "./layout.js";
|
|
4
4
|
//#region src/read.d.ts
|
|
5
5
|
interface ReadPdfOptions {
|
|
6
6
|
readonly sink?: PdfDiagnosticSink;
|
|
@@ -15,7 +15,5 @@ interface PageRotationResult {
|
|
|
15
15
|
readonly heightPt: number;
|
|
16
16
|
}
|
|
17
17
|
declare function pageRotationTransform(rotation: PageRotation, w: number, h: number): PageRotationResult;
|
|
18
|
-
declare function decodePdfString(bytes: Uint8Array<ArrayBuffer>): string;
|
|
19
|
-
declare function parsePdfDate(raw: string | undefined): string | undefined;
|
|
20
18
|
//#endregion
|
|
21
|
-
export { ReadPdfOptions,
|
|
19
|
+
export { ReadPdfOptions, normalizeRotation, pageRotationTransform, readPdf };
|