pdf-codec 5.5.1 → 5.6.1
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 +3 -1
- package/dist/codec.d.cts +1 -0
- package/dist/codec.d.ts +1 -0
- package/dist/filters.cjs +39 -14
- package/dist/filters.js +39 -14
- package/dist/images-read.cjs +107 -48
- package/dist/images-read.d.cts +30 -1
- package/dist/images-read.d.ts +30 -1
- package/dist/images-read.js +106 -49
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/{interpret-BDVrFWhd.cjs → interpret-2_N_lh0h.cjs} +2 -3
- package/dist/{interpret---0lZPlv.js → interpret-BeMKZGBm.js} +2 -3
- package/dist/interpret-colors.cjs +1 -1
- package/dist/interpret-colors.js +1 -1
- package/dist/interpret.cjs +1 -1
- package/dist/interpret.js +1 -1
- package/dist/layout.cjs +3 -2
- package/dist/layout.d.cts +3 -1
- package/dist/layout.d.ts +3 -1
- package/dist/layout.js +3 -2
- package/dist/{raster-HUE5bw5s.cjs → raster-B8i3Tgjj.cjs} +1 -1
- package/dist/{raster-DUmwfi3F.js → raster-CIc6ot36.js} +1 -1
- package/dist/raster-text.cjs +1 -1
- package/dist/raster-text.js +1 -1
- package/dist/raster.cjs +1 -1
- package/dist/raster.js +1 -1
- package/dist/read-convert.cjs +14 -3
- package/dist/read-convert.d.cts +19 -2
- package/dist/read-convert.d.ts +19 -2
- package/dist/read-convert.js +14 -3
- package/dist/read.cjs +8 -5
- package/dist/read.d.cts +2 -1
- package/dist/read.d.ts +2 -1
- package/dist/read.js +8 -5
- package/package.json +1 -1
package/dist/read.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ interface ReadPdfOptions {
|
|
|
18
18
|
/**
|
|
19
19
|
* Which document-level surfaces to read. Each is read unless its entry is `false`, so omitting the setting, or an entry, reads it as before. Independent of `pages`: it applies to a full read and a page-selected read alike.
|
|
20
20
|
*
|
|
21
|
-
* A surface turned off is never parsed (its part of the catalog is not walked, so a malformed outline, form, layer list or structure tree reports no diagnostic) and its field is absent from the result whatever the file holds; the result lists it in `skippedSurfaces`, which is how a caller tells "not read" from "none". What each one covers, and what page items lose without it:
|
|
21
|
+
* A surface turned off is never parsed (its part of the catalog is not walked, so a malformed outline, form, layer list or structure tree reports no diagnostic, and no image a page draws is decoded or diagnosed) and its field is absent from the result whatever the file holds (`images` is left empty instead); the result lists it in `skippedSurfaces`, which is how a caller tells "not read" from "none". What each one covers, and what page items lose without it:
|
|
22
22
|
*
|
|
23
23
|
* - `outline`: the `/Outlines` bookmark tree (`outline`). Page items do not depend on it, except through minted names: a destination stated as a direct array is named with the first unused `destN` in the order the reader meets it, and the outline is read before any page, so an outline entry's direct destination takes a lower number than any link's. Without the outline, the names minted for page links' direct destinations are renumbered, and `destinations` loses the entries only the outline minted; each link still resolves to the same target.
|
|
24
24
|
* - `destinations`: the named destinations of the catalog `/Dests` dictionary and the `/Names /Dests` name tree, and the registry links and outline entries name their targets through (`destinations`). Without it nothing can name an internal target, so a link whose target is internal (a `/Dest`, or a `/GoTo` action, named or direct) is left out of its page's items, and a read outline entry carries no `destination`; a link to a URI is kept as usual.
|
|
@@ -26,6 +26,7 @@ interface ReadPdfOptions {
|
|
|
26
26
|
* - `layers`: optional content, the `/OCProperties` groups and their default visibility (`layers`). Without it no item carries a `layer`, since an `/OC` membership resolves to no name; the items themselves are all still read, so content the default view hides is indistinguishable from visible content.
|
|
27
27
|
* - `structure`: the `/StructTreeRoot` element tree and its `/ParentTree` ownership map (`structure`). Without it no item carries a `structure` owner, and the parent-tree diagnostics are not reported.
|
|
28
28
|
* - `residue`: the package-level residue rows (`source`), including the per-page `page-boxes` row. Page items do not depend on it; `metadata` still reads the XMP packet it falls back to.
|
|
29
|
+
* - `images`: the image registry (`images`), which holds every image XObject and inline image a read page draws, decoded to PNG or passed through as JPEG. Without it no image's stream is decoded, `images` is an empty record (every `LayoutDocument` carries one), and each page's `image` items are left out, since they would name assets that were never read. Decoding an image costs memory in proportion to its pixels, so a read that wants only a page's text leaves this out.
|
|
29
30
|
*
|
|
30
31
|
* Apart from those stated losses and the renumbering a skipped outline causes, every page item is exactly what a read with the surface on produces.
|
|
31
32
|
*/
|
package/dist/read.js
CHANGED
|
@@ -16,7 +16,7 @@ import { NOOP_DIAGNOSTIC_SINK, PdfPageSelectionError, PdfParseError } from "./di
|
|
|
16
16
|
import { openPdfDocument } from "./document.js";
|
|
17
17
|
import { throwIfAborted } from "./util/abort.js";
|
|
18
18
|
import { createFontResolver } from "./font-read.js";
|
|
19
|
-
import { t as interpretContentStream } from "./interpret
|
|
19
|
+
import { t as interpretContentStream } from "./interpret-BeMKZGBm.js";
|
|
20
20
|
import { createDestinationRegistry, readOutline } from "./navigation.js";
|
|
21
21
|
//#region src/read.ts
|
|
22
22
|
function skippedSurfacesOf(surfaces) {
|
|
@@ -58,11 +58,14 @@ function readPdf(bytes, options) {
|
|
|
58
58
|
sink
|
|
59
59
|
});
|
|
60
60
|
const images = {};
|
|
61
|
-
const imageIdCache = /* @__PURE__ */ new Map();
|
|
62
61
|
const pageDicts = doc.pages();
|
|
63
62
|
const selection = options?.pages === void 0 ? void 0 : resolvePageSelection(options.pages, pageDicts.length);
|
|
64
63
|
const skippedSurfaces = skippedSurfacesOf(options?.surfaces);
|
|
65
64
|
const reads = (surface) => !skippedSurfaces.includes(surface);
|
|
65
|
+
const imageRegistry = reads("images") ? {
|
|
66
|
+
images,
|
|
67
|
+
imageIdCache: /* @__PURE__ */ new Map()
|
|
68
|
+
} : void 0;
|
|
66
69
|
const destinationRegistry = reads("destinations") ? createDestinationRegistry(doc.catalog, doc, (obj) => doc.pageIndex(obj), sink) : UNREAD_DESTINATION_REGISTRY;
|
|
67
70
|
const outline = reads("outline") ? readOutline(doc.catalog, destinationRegistry, doc, sink) : void 0;
|
|
68
71
|
const attachments = selection === void 0 ? readAttachments(doc.catalog, pageDicts, doc, sink) : [];
|
|
@@ -74,7 +77,7 @@ function readPdf(bytes, options) {
|
|
|
74
77
|
const pages = pageDicts.flatMap((pageDict, index) => {
|
|
75
78
|
if (selection !== void 0 && !selection.has(index)) return [];
|
|
76
79
|
throwIfAborted(signal);
|
|
77
|
-
const read = readPage(index, pageDict, doc, fontResolver,
|
|
80
|
+
const read = readPage(index, pageDict, doc, fontResolver, imageRegistry, destinationRegistry, optionalContent?.layerNameOf ?? noLayerName, structure?.ownerOf ?? noStructureOwner, sink);
|
|
78
81
|
if (read.boxRow !== void 0) pageBoxRows.push(read.boxRow);
|
|
79
82
|
return [selection === void 0 ? read.page : {
|
|
80
83
|
...read.page,
|
|
@@ -308,7 +311,7 @@ function pageBoxResidueEntry(pageIndex, page, mediaBox, cropBox) {
|
|
|
308
311
|
for (const [key, value] of declaredBoxes) if (value !== void 0) entries[key] = value;
|
|
309
312
|
return pdfDict(entries);
|
|
310
313
|
}
|
|
311
|
-
function readPage(pageIndex, page, resolver, fontResolver,
|
|
314
|
+
function readPage(pageIndex, page, resolver, fontResolver, imageRegistry, destinationRegistry, layerNameOf, structureOwnerOf, sink) {
|
|
312
315
|
const resources = resolver.resolveDict(dictGet(page, "Resources"));
|
|
313
316
|
const mediaBox = readMediaBox(page);
|
|
314
317
|
let cropBox = readDeclaredPageBox(page, "CropBox") ?? mediaBox;
|
|
@@ -337,7 +340,7 @@ function readPage(pageIndex, page, resolver, fontResolver, images, imageIdCache,
|
|
|
337
340
|
layerNameOf
|
|
338
341
|
});
|
|
339
342
|
for (const item of extracted) {
|
|
340
|
-
const converted = convertExtractedItem(item, pageMatrix, fontResolver,
|
|
343
|
+
const converted = convertExtractedItem(item, pageMatrix, fontResolver, imageRegistry, resolver, sink);
|
|
341
344
|
if (converted === void 0 || !itemIntersectsVisibleRegion(converted, widthPt, heightPt)) continue;
|
|
342
345
|
const owner = item.mcid === void 0 ? void 0 : structureOwnerOf(pageIndex, item.mcid);
|
|
343
346
|
items.push(owner === void 0 ? converted : withStructure(converted, owner));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pdf-codec",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.6.1",
|
|
4
4
|
"description": "Hand-written, dependency-minimal PDF codec: parses arbitrary real-world PDFs and generates new ones, built on its own codec-owned LayoutDocument item model and Zod 4 codecs.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|