pdf-parser.js 5.2.30 → 5.3.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/dist/{afm-widths-BHD2HZIL.cjs → afm-widths-C6U0SQj9.cjs} +5 -1448
- package/dist/{afm-widths-B_IGbGky.js → afm-widths-p3UfaXme.js} +3 -1398
- package/dist/afm-widths.cjs +1 -1
- package/dist/afm-widths.js +1 -1
- package/dist/annotations.d.cts +3 -3
- package/dist/annotations.d.ts +3 -3
- package/dist/attachments.d.cts +2 -2
- package/dist/attachments.d.ts +2 -2
- package/dist/builtin-encoding.cjs +4 -3
- package/dist/builtin-encoding.js +2 -1
- package/dist/cmap.d.cts +1 -1
- package/dist/cmap.d.ts +1 -1
- package/dist/content-read.d.cts +1 -1
- package/dist/content-read.d.ts +1 -1
- package/dist/content-write.cjs +1 -1
- package/dist/content-write.d.cts +1 -1
- package/dist/content-write.d.ts +1 -1
- package/dist/content-write.js +1 -1
- package/dist/diagnostics-C9FxfZ6H.d.cts +22 -0
- package/dist/diagnostics-C9FxfZ6H.d.ts +22 -0
- package/dist/diagnostics.d.cts +1 -21
- package/dist/diagnostics.d.ts +1 -21
- package/dist/document.d.cts +1 -1
- package/dist/document.d.ts +1 -1
- package/dist/{embedded-font-ByD7ZiQS.d.ts → embedded-font-CQZbTTDM.d.ts} +1 -1
- package/dist/{embedded-font-DgVBedw6.d.cts → embedded-font-CqePfvrl.d.cts} +1 -1
- package/dist/embedded-font-write.d.cts +1 -1
- package/dist/embedded-font-write.d.ts +1 -1
- package/dist/embedded-font.cjs +2 -2
- package/dist/embedded-font.d.cts +1 -1
- package/dist/embedded-font.d.ts +1 -1
- package/dist/embedded-font.js +2 -2
- package/dist/encoding-glyph-unicode.cjs +353 -0
- package/dist/encoding-glyph-unicode.d.cts +4 -0
- package/dist/encoding-glyph-unicode.d.ts +4 -0
- package/dist/encoding-glyph-unicode.js +352 -0
- package/dist/encoding-standard-tables.cjs +531 -0
- package/dist/encoding-standard-tables.d.cts +7 -0
- package/dist/encoding-standard-tables.d.ts +7 -0
- package/dist/encoding-standard-tables.js +527 -0
- package/dist/encoding-symbol-tables.cjs +533 -0
- package/dist/encoding-symbol-tables.d.cts +7 -0
- package/dist/encoding-symbol-tables.d.ts +7 -0
- package/dist/encoding-symbol-tables.js +529 -0
- package/dist/encoding.cjs +1 -9
- package/dist/encoding.d.cts +1 -9
- package/dist/encoding.d.ts +1 -9
- package/dist/encoding.js +2 -2
- package/dist/encrypt.d.cts +1 -1
- package/dist/encrypt.d.ts +1 -1
- package/dist/filters.d.cts +1 -1
- package/dist/filters.d.ts +1 -1
- package/dist/font-read.cjs +4 -3
- package/dist/font-read.d.cts +2 -2
- package/dist/font-read.d.ts +2 -2
- package/dist/font-read.js +2 -1
- package/dist/font-registry.d.cts +1 -1
- package/dist/font-registry.d.ts +1 -1
- package/dist/form.d.cts +2 -2
- package/dist/form.d.ts +2 -2
- package/dist/gdef-table-D0Hzn4KD.d.cts +15 -0
- package/dist/gdef-table-DL0V8wEZ.d.ts +15 -0
- package/dist/gdef-table.d.cts +1 -14
- package/dist/gdef-table.d.ts +1 -14
- package/dist/glyf-contours.d.cts +12 -1
- package/dist/glyf-contours.d.ts +12 -1
- package/dist/gsub-context.cjs +13 -0
- package/dist/gsub-context.d.cts +34 -0
- package/dist/gsub-context.d.ts +34 -0
- package/dist/gsub-context.js +2 -0
- package/dist/gsub-table-BDpJWqpf.d.ts +52 -0
- package/dist/gsub-table-D6niKeLi.js +556 -0
- package/dist/gsub-table-DW7Wmi9V.d.cts +52 -0
- package/dist/gsub-table-hFfYmf1W.cjs +741 -0
- package/dist/gsub-table.cjs +21 -556
- package/dist/gsub-table.d.cts +2 -2
- package/dist/gsub-table.d.ts +2 -2
- package/dist/gsub-table.js +2 -554
- package/dist/images-read.d.cts +2 -2
- package/dist/images-read.d.ts +2 -2
- package/dist/index.cjs +6 -6
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +6 -6
- package/dist/interpret-CqXdXgkY.cjs +712 -0
- package/dist/interpret-aWWhdIzr.js +677 -0
- package/dist/interpret-colors.cjs +6 -0
- package/dist/interpret-colors.d.cts +9 -0
- package/dist/interpret-colors.d.ts +9 -0
- package/dist/interpret-colors.js +2 -0
- package/dist/interpret-marked.cjs +25 -0
- package/dist/interpret-marked.d.cts +11 -0
- package/dist/interpret-marked.d.ts +11 -0
- package/dist/interpret-marked.js +23 -0
- package/dist/interpret-shapes.cjs +212 -0
- package/dist/interpret-shapes.d.cts +32 -0
- package/dist/interpret-shapes.d.ts +32 -0
- package/dist/interpret-shapes.js +199 -0
- package/dist/interpret-types.cjs +0 -0
- package/dist/interpret-types.d.cts +123 -0
- package/dist/interpret-types.d.ts +123 -0
- package/dist/interpret-types.js +0 -0
- package/dist/interpret.cjs +3 -887
- package/dist/interpret.d.cts +5 -116
- package/dist/interpret.d.ts +5 -116
- package/dist/interpret.js +2 -887
- package/dist/math-font.cjs +1 -1
- package/dist/math-font.js +1 -1
- package/dist/measure.cjs +1 -1
- package/dist/measure.js +1 -1
- package/dist/names.d.cts +2 -2
- package/dist/names.d.ts +2 -2
- package/dist/navigation.d.cts +2 -2
- package/dist/navigation.d.ts +2 -2
- package/dist/optional-content.d.cts +2 -2
- package/dist/optional-content.d.ts +2 -2
- package/dist/ot-layout-common-BcsGRFBS.d.cts +10 -0
- package/dist/ot-layout-common-BcsGRFBS.d.ts +10 -0
- package/dist/ot-layout-common.d.cts +1 -9
- package/dist/ot-layout-common.d.ts +1 -9
- package/dist/parse.d.cts +1 -1
- package/dist/parse.d.ts +1 -1
- package/dist/predictors.d.cts +1 -1
- package/dist/predictors.d.ts +1 -1
- package/dist/raster-Cdm3idP_.js +794 -0
- package/dist/raster-EG2KYRZ0.cjs +829 -0
- package/dist/raster-text.cjs +5 -0
- package/dist/raster-text.d.cts +20 -0
- package/dist/raster-text.d.ts +20 -0
- package/dist/raster-text.js +2 -0
- package/dist/raster.cjs +4 -795
- package/dist/raster.d.cts +17 -6
- package/dist/raster.d.ts +17 -6
- package/dist/raster.js +2 -792
- package/dist/read-convert.cjs +310 -0
- package/dist/read-convert.d.cts +58 -0
- package/dist/read-convert.d.ts +58 -0
- package/dist/read-convert.js +295 -0
- package/dist/read.cjs +5 -293
- package/dist/read.d.cts +1 -1
- package/dist/read.d.ts +1 -1
- package/dist/read.js +4 -292
- package/dist/structure.d.cts +2 -2
- package/dist/structure.d.ts +2 -2
- package/dist/winansi.cjs +1 -1
- package/dist/winansi.js +1 -1
- package/dist/write-annotations.cjs +132 -0
- package/dist/write-annotations.d.cts +29 -0
- package/dist/write-annotations.d.ts +29 -0
- package/dist/write-annotations.js +121 -0
- package/dist/write-font-objects.cjs +76 -0
- package/dist/write-font-objects.d.cts +35 -0
- package/dist/write-font-objects.d.ts +35 -0
- package/dist/write-font-objects.js +75 -0
- package/dist/write-form.cjs +91 -0
- package/dist/write-form.d.cts +19 -0
- package/dist/write-form.d.ts +19 -0
- package/dist/write-form.js +89 -0
- package/dist/write-images.cjs +148 -0
- package/dist/write-images.d.cts +25 -0
- package/dist/write-images.d.ts +25 -0
- package/dist/write-images.js +140 -0
- package/dist/write-outline.cjs +46 -0
- package/dist/write-outline.d.cts +18 -0
- package/dist/write-outline.d.ts +18 -0
- package/dist/write-outline.js +45 -0
- package/dist/write-page-emit.cjs +97 -0
- package/dist/write-page-emit.d.cts +63 -0
- package/dist/write-page-emit.d.ts +63 -0
- package/dist/write-page-emit.js +96 -0
- package/dist/write-pages.cjs +37 -0
- package/dist/write-pages.d.cts +21 -0
- package/dist/write-pages.d.ts +21 -0
- package/dist/write-pages.js +36 -0
- package/dist/write-strings.cjs +41 -0
- package/dist/write-strings.d.cts +9 -0
- package/dist/write-strings.d.ts +9 -0
- package/dist/write-strings.js +37 -0
- package/dist/write.cjs +53 -553
- package/dist/write.d.cts +1 -1
- package/dist/write.d.ts +1 -1
- package/dist/write.js +49 -549
- package/dist/xref.d.cts +1 -1
- package/dist/xref.d.ts +1 -1
- package/package.json +1 -1
- package/dist/glyf-contours-B1PsI9oA.d.ts +0 -13
- package/dist/glyf-contours-NHBpgks-.d.cts +0 -13
- package/dist/gsub-table-Bm9kSMzk.d.cts +0 -16
- package/dist/gsub-table-CdfESH2-.d.ts +0 -16
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { pdfArray, pdfBool, pdfDict, pdfName, pdfNum } from "./objects.js";
|
|
2
|
+
import { deflate } from "./bytes/flate.js";
|
|
3
|
+
import { encodeCcittFax } from "./image/ccitt-encode.js";
|
|
4
|
+
import { decodePng } from "./image/png-decode.js";
|
|
5
|
+
import { readJpegInfo as readJpegInfo$1 } from "./image/jpeg-info.js";
|
|
6
|
+
import { base64ToBytes } from "byte-codec";
|
|
7
|
+
//#region src/write-images.ts
|
|
8
|
+
const BITS_PER_BYTE = 8;
|
|
9
|
+
const BYTE_SHIFT = Math.log2(8);
|
|
10
|
+
const BYTE_MASK = 255;
|
|
11
|
+
const PACKED_BIT_MSB_MASK = 128;
|
|
12
|
+
const BIT_INDEX_MASK = 7;
|
|
13
|
+
const JPEG_COMPONENTS_CMYK = 4;
|
|
14
|
+
function prepareJpegImage(bytes) {
|
|
15
|
+
const info = readJpegInfo$1(bytes);
|
|
16
|
+
const colorSpace = info.components === 1 ? "DeviceGray" : info.components === JPEG_COMPONENTS_CMYK ? "DeviceCMYK" : "DeviceRGB";
|
|
17
|
+
const entries = /* @__PURE__ */ new Map([
|
|
18
|
+
["Type", pdfName("XObject")],
|
|
19
|
+
["Subtype", pdfName("Image")],
|
|
20
|
+
["Width", pdfNum(info.width)],
|
|
21
|
+
["Height", pdfNum(info.height)],
|
|
22
|
+
["ColorSpace", pdfName(colorSpace)],
|
|
23
|
+
["BitsPerComponent", pdfNum(info.precision)],
|
|
24
|
+
["Filter", pdfName("DCTDecode")]
|
|
25
|
+
]);
|
|
26
|
+
if (info.components === JPEG_COMPONENTS_CMYK && (info.adobeTransform === 2 || info.adobeTransform === void 0)) entries.set("Decode", pdfArray([
|
|
27
|
+
1,
|
|
28
|
+
0,
|
|
29
|
+
1,
|
|
30
|
+
0,
|
|
31
|
+
1,
|
|
32
|
+
0,
|
|
33
|
+
1,
|
|
34
|
+
0
|
|
35
|
+
].map((n) => pdfNum(n))));
|
|
36
|
+
return {
|
|
37
|
+
dict: pdfDict(entries),
|
|
38
|
+
raw: bytes
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function pngImageDict(width, height, colorSpace, compress) {
|
|
42
|
+
const entries = /* @__PURE__ */ new Map([
|
|
43
|
+
["Type", pdfName("XObject")],
|
|
44
|
+
["Subtype", pdfName("Image")],
|
|
45
|
+
["Width", pdfNum(width)],
|
|
46
|
+
["Height", pdfNum(height)],
|
|
47
|
+
["ColorSpace", pdfName(colorSpace)],
|
|
48
|
+
["BitsPerComponent", pdfNum(8)]
|
|
49
|
+
]);
|
|
50
|
+
if (compress) entries.set("Filter", pdfName("FlateDecode"));
|
|
51
|
+
return pdfDict(entries);
|
|
52
|
+
}
|
|
53
|
+
function packBilevel(raw) {
|
|
54
|
+
const rowBytes = raw.width + BIT_INDEX_MASK >> BYTE_SHIFT;
|
|
55
|
+
const packed = new Uint8Array(rowBytes * raw.height);
|
|
56
|
+
const view = new DataView(packed.buffer);
|
|
57
|
+
for (let index = 0; index < raw.data.length; index++) {
|
|
58
|
+
const sample = raw.data[index];
|
|
59
|
+
if (sample !== 0 && sample !== 255) return;
|
|
60
|
+
if (sample === 255) {
|
|
61
|
+
const x = index % raw.width;
|
|
62
|
+
const byteIndex = Math.floor(index / raw.width) * rowBytes + (x >> BYTE_SHIFT);
|
|
63
|
+
view.setUint8(byteIndex, view.getUint8(byteIndex) | PACKED_BIT_MSB_MASK >> (x & BIT_INDEX_MASK));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return packed;
|
|
67
|
+
}
|
|
68
|
+
function preparePngImage(bytes, compress) {
|
|
69
|
+
const raw = decodePng(bytes);
|
|
70
|
+
const colorSpace = raw.channels === 1 ? "DeviceGray" : "DeviceRGB";
|
|
71
|
+
if (compress && raw.channels === 1 && raw.alpha === void 0) {
|
|
72
|
+
const bilevel = packBilevel(raw);
|
|
73
|
+
if (bilevel !== void 0) {
|
|
74
|
+
const flate = deflate(raw.data);
|
|
75
|
+
const g4 = encodeCcittFax(bilevel, {
|
|
76
|
+
columns: raw.width,
|
|
77
|
+
rows: raw.height,
|
|
78
|
+
maxBytes: flate.length
|
|
79
|
+
});
|
|
80
|
+
if (g4 !== void 0) return {
|
|
81
|
+
dict: pdfDict(/* @__PURE__ */ new Map([
|
|
82
|
+
["Type", pdfName("XObject")],
|
|
83
|
+
["Subtype", pdfName("Image")],
|
|
84
|
+
["Width", pdfNum(raw.width)],
|
|
85
|
+
["Height", pdfNum(raw.height)],
|
|
86
|
+
["ColorSpace", pdfName("DeviceGray")],
|
|
87
|
+
["BitsPerComponent", pdfNum(1)],
|
|
88
|
+
["Filter", pdfName("CCITTFaxDecode")],
|
|
89
|
+
["DecodeParms", pdfDict(/* @__PURE__ */ new Map([
|
|
90
|
+
["K", pdfNum(-1)],
|
|
91
|
+
["Columns", pdfNum(raw.width)],
|
|
92
|
+
["Rows", pdfNum(raw.height)],
|
|
93
|
+
["BlackIs1", pdfBool(false)]
|
|
94
|
+
]))]
|
|
95
|
+
])),
|
|
96
|
+
raw: g4,
|
|
97
|
+
alpha: void 0
|
|
98
|
+
};
|
|
99
|
+
return {
|
|
100
|
+
dict: pngImageDict(raw.width, raw.height, colorSpace, true),
|
|
101
|
+
raw: flate,
|
|
102
|
+
alpha: void 0
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
dict: pngImageDict(raw.width, raw.height, colorSpace, compress),
|
|
108
|
+
raw: compress ? deflate(raw.data) : raw.data,
|
|
109
|
+
alpha: raw.alpha === void 0 ? void 0 : {
|
|
110
|
+
dict: pngImageDict(raw.width, raw.height, "DeviceGray", compress),
|
|
111
|
+
raw: compress ? deflate(raw.alpha) : raw.alpha
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
function preparePassthroughImage(asset, original, compress) {
|
|
116
|
+
const png = preparePngImage(base64ToBytes(asset.base64), compress);
|
|
117
|
+
const entries = /* @__PURE__ */ new Map([
|
|
118
|
+
["Type", pdfName("XObject")],
|
|
119
|
+
["Subtype", pdfName("Image")],
|
|
120
|
+
["Width", pdfNum(asset.widthPx)],
|
|
121
|
+
["Height", pdfNum(asset.heightPx)],
|
|
122
|
+
["Filter", pdfName(original.filter === "jbig2" ? "JBIG2Decode" : "JPXDecode")]
|
|
123
|
+
]);
|
|
124
|
+
if (original.filter === "jbig2") {
|
|
125
|
+
entries.set("ColorSpace", pdfName("DeviceGray"));
|
|
126
|
+
entries.set("BitsPerComponent", pdfNum(1));
|
|
127
|
+
}
|
|
128
|
+
return {
|
|
129
|
+
dict: pdfDict(entries),
|
|
130
|
+
raw: base64ToBytes(original.base64),
|
|
131
|
+
alpha: png.alpha
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
function prepareImage(asset, compress) {
|
|
135
|
+
if (asset.original !== void 0) return preparePassthroughImage(asset, asset.original, compress);
|
|
136
|
+
const bytes = base64ToBytes(asset.base64);
|
|
137
|
+
return asset.format === "jpeg" ? prepareJpegImage(bytes) : preparePngImage(bytes, compress);
|
|
138
|
+
}
|
|
139
|
+
//#endregion
|
|
140
|
+
export { BITS_PER_BYTE, BYTE_MASK, packBilevel, pngImageDict, prepareImage, prepareJpegImage, preparePassthroughImage, preparePngImage };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_objects = require("./objects.cjs");
|
|
3
|
+
const require_write_annotations = require("./write-annotations.cjs");
|
|
4
|
+
//#region src/write-outline.ts
|
|
5
|
+
function emitOutlineObjects(state) {
|
|
6
|
+
const { objects, outlineItemNums, outlineRootNum, doc, pageAllocs } = state;
|
|
7
|
+
if (outlineRootNum !== void 0) {
|
|
8
|
+
let itemCursor = 0;
|
|
9
|
+
const emitItems = (items, parentNum) => {
|
|
10
|
+
const siblingNums = [];
|
|
11
|
+
let prevNum;
|
|
12
|
+
for (const item of items) {
|
|
13
|
+
const ownNum = outlineItemNums[itemCursor];
|
|
14
|
+
itemCursor += 1;
|
|
15
|
+
siblingNums.push(ownNum);
|
|
16
|
+
const childNums = emitItems(item.children, ownNum);
|
|
17
|
+
const entries = [["Title", require_objects.pdfLiteralString(new TextEncoder().encode(item.title))], ["Parent", require_objects.pdfRef(parentNum, 0)]];
|
|
18
|
+
if (item.destination !== void 0) entries.push(["Dest", require_objects.pdfArray(require_write_annotations.resolveDestinationArray(doc, pageAllocs, item.destination, `outline item "${item.title}"`))]);
|
|
19
|
+
if (prevNum !== void 0) entries.push(["Prev", require_objects.pdfRef(prevNum, 0)]);
|
|
20
|
+
if (siblingNums.length < items.length) entries.push(["Next", require_objects.pdfRef(outlineItemNums[itemCursor], 0)]);
|
|
21
|
+
if (childNums.length > 0) {
|
|
22
|
+
entries.push(["First", require_objects.pdfRef(childNums[0], 0)]);
|
|
23
|
+
entries.push(["Last", require_objects.pdfRef(childNums[childNums.length - 1], 0)]);
|
|
24
|
+
entries.push(["Count", require_objects.pdfNum(childNums.length)]);
|
|
25
|
+
}
|
|
26
|
+
objects.push({
|
|
27
|
+
num: ownNum,
|
|
28
|
+
value: require_objects.pdfDict(Object.fromEntries(entries))
|
|
29
|
+
});
|
|
30
|
+
prevNum = ownNum;
|
|
31
|
+
}
|
|
32
|
+
return siblingNums;
|
|
33
|
+
};
|
|
34
|
+
const topLevelNums = emitItems(doc.outline ?? [], outlineRootNum);
|
|
35
|
+
objects.push({
|
|
36
|
+
num: outlineRootNum,
|
|
37
|
+
value: require_objects.pdfDict({
|
|
38
|
+
Type: require_objects.pdfName("Outlines"),
|
|
39
|
+
First: require_objects.pdfRef(topLevelNums[0], 0),
|
|
40
|
+
Last: require_objects.pdfRef(topLevelNums[topLevelNums.length - 1], 0)
|
|
41
|
+
})
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
//#endregion
|
|
46
|
+
exports.emitOutlineObjects = emitOutlineObjects;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { r as PdfObject } from "./objects-e2RS3-yT.cjs";
|
|
2
|
+
import { LayoutDocument } from "./layout.cjs";
|
|
3
|
+
//#region src/write-outline.d.ts
|
|
4
|
+
interface OutlineEmitState {
|
|
5
|
+
readonly objects: {
|
|
6
|
+
num: number;
|
|
7
|
+
value: PdfObject;
|
|
8
|
+
}[];
|
|
9
|
+
readonly outlineItemNums: readonly number[];
|
|
10
|
+
readonly outlineRootNum: number | undefined;
|
|
11
|
+
readonly doc: LayoutDocument;
|
|
12
|
+
readonly pageAllocs: readonly {
|
|
13
|
+
pageNum: number;
|
|
14
|
+
}[];
|
|
15
|
+
}
|
|
16
|
+
declare function emitOutlineObjects(state: OutlineEmitState): void;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { OutlineEmitState, emitOutlineObjects };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { r as PdfObject } from "./objects-e2RS3-yT.js";
|
|
2
|
+
import { LayoutDocument } from "./layout.js";
|
|
3
|
+
//#region src/write-outline.d.ts
|
|
4
|
+
interface OutlineEmitState {
|
|
5
|
+
readonly objects: {
|
|
6
|
+
num: number;
|
|
7
|
+
value: PdfObject;
|
|
8
|
+
}[];
|
|
9
|
+
readonly outlineItemNums: readonly number[];
|
|
10
|
+
readonly outlineRootNum: number | undefined;
|
|
11
|
+
readonly doc: LayoutDocument;
|
|
12
|
+
readonly pageAllocs: readonly {
|
|
13
|
+
pageNum: number;
|
|
14
|
+
}[];
|
|
15
|
+
}
|
|
16
|
+
declare function emitOutlineObjects(state: OutlineEmitState): void;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { OutlineEmitState, emitOutlineObjects };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { pdfArray, pdfDict, pdfLiteralString, pdfName, pdfNum, pdfRef } from "./objects.js";
|
|
2
|
+
import { resolveDestinationArray } from "./write-annotations.js";
|
|
3
|
+
//#region src/write-outline.ts
|
|
4
|
+
function emitOutlineObjects(state) {
|
|
5
|
+
const { objects, outlineItemNums, outlineRootNum, doc, pageAllocs } = state;
|
|
6
|
+
if (outlineRootNum !== void 0) {
|
|
7
|
+
let itemCursor = 0;
|
|
8
|
+
const emitItems = (items, parentNum) => {
|
|
9
|
+
const siblingNums = [];
|
|
10
|
+
let prevNum;
|
|
11
|
+
for (const item of items) {
|
|
12
|
+
const ownNum = outlineItemNums[itemCursor];
|
|
13
|
+
itemCursor += 1;
|
|
14
|
+
siblingNums.push(ownNum);
|
|
15
|
+
const childNums = emitItems(item.children, ownNum);
|
|
16
|
+
const entries = [["Title", pdfLiteralString(new TextEncoder().encode(item.title))], ["Parent", pdfRef(parentNum, 0)]];
|
|
17
|
+
if (item.destination !== void 0) entries.push(["Dest", pdfArray(resolveDestinationArray(doc, pageAllocs, item.destination, `outline item "${item.title}"`))]);
|
|
18
|
+
if (prevNum !== void 0) entries.push(["Prev", pdfRef(prevNum, 0)]);
|
|
19
|
+
if (siblingNums.length < items.length) entries.push(["Next", pdfRef(outlineItemNums[itemCursor], 0)]);
|
|
20
|
+
if (childNums.length > 0) {
|
|
21
|
+
entries.push(["First", pdfRef(childNums[0], 0)]);
|
|
22
|
+
entries.push(["Last", pdfRef(childNums[childNums.length - 1], 0)]);
|
|
23
|
+
entries.push(["Count", pdfNum(childNums.length)]);
|
|
24
|
+
}
|
|
25
|
+
objects.push({
|
|
26
|
+
num: ownNum,
|
|
27
|
+
value: pdfDict(Object.fromEntries(entries))
|
|
28
|
+
});
|
|
29
|
+
prevNum = ownNum;
|
|
30
|
+
}
|
|
31
|
+
return siblingNums;
|
|
32
|
+
};
|
|
33
|
+
const topLevelNums = emitItems(doc.outline ?? [], outlineRootNum);
|
|
34
|
+
objects.push({
|
|
35
|
+
num: outlineRootNum,
|
|
36
|
+
value: pdfDict({
|
|
37
|
+
Type: pdfName("Outlines"),
|
|
38
|
+
First: pdfRef(topLevelNums[0], 0),
|
|
39
|
+
Last: pdfRef(topLevelNums[topLevelNums.length - 1], 0)
|
|
40
|
+
})
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
//#endregion
|
|
45
|
+
export { emitOutlineObjects };
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_objects = require("./objects.cjs");
|
|
3
|
+
const require_bytes_writer = require("./bytes/writer.cjs");
|
|
4
|
+
const require_bytes_flate = require("./bytes/flate.cjs");
|
|
5
|
+
const require_util_abort = require("./util/abort.cjs");
|
|
6
|
+
const require_write_annotations = require("./write-annotations.cjs");
|
|
7
|
+
const require_math_content_write = require("./math-content-write.cjs");
|
|
8
|
+
const require_content_write = require("./content-write.cjs");
|
|
9
|
+
const require_font_registry = require("./font-registry.cjs");
|
|
10
|
+
//#region src/write-page-emit.ts
|
|
11
|
+
function emitPageObjects(s) {
|
|
12
|
+
const { doc, options, objects, compress, measurer, registry, fontAllocs, embeddedAllocs, imageAllocs, layerNumByName, formulas, mathFontAlloc, mathFont, pageAllocs, pagesNum, resourcesDict, widgetAnnotsByPage } = s;
|
|
13
|
+
const markedStructureByPage = /* @__PURE__ */ new Map();
|
|
14
|
+
const formulasByPage = /* @__PURE__ */ new Map();
|
|
15
|
+
for (const formula of formulas) {
|
|
16
|
+
const forPage = formulasByPage.get(formula.pageIndex);
|
|
17
|
+
if (forPage === void 0) formulasByPage.set(formula.pageIndex, [formula]);
|
|
18
|
+
else forPage.push(formula);
|
|
19
|
+
}
|
|
20
|
+
const context = {
|
|
21
|
+
measurer,
|
|
22
|
+
resolveFont: (font) => {
|
|
23
|
+
const resolved = require_font_registry.resolveFaceWithRegistry(registry, font);
|
|
24
|
+
if (resolved.kind === "embedded") {
|
|
25
|
+
const alloc = embeddedAllocs.get(resolved.face);
|
|
26
|
+
if (alloc === void 0) throw new Error(`embedded font "${resolved.face.postScriptName}" was not pre-allocated — this is a writePdf internal invariant violation`);
|
|
27
|
+
return {
|
|
28
|
+
kind: "embedded",
|
|
29
|
+
resourceName: alloc.resourceName,
|
|
30
|
+
face: resolved.face
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
const alloc = fontAllocs.get(resolved.standardName);
|
|
34
|
+
if (alloc === void 0) throw new Error(`font "${resolved.standardName}" was not pre-allocated — this is a writePdf internal invariant violation`);
|
|
35
|
+
return {
|
|
36
|
+
kind: "standard",
|
|
37
|
+
resourceName: alloc.resourceName,
|
|
38
|
+
standardName: resolved.standardName
|
|
39
|
+
};
|
|
40
|
+
},
|
|
41
|
+
resolveImage: (imageId) => {
|
|
42
|
+
const alloc = imageAllocs.get(imageId);
|
|
43
|
+
if (alloc === void 0) throw new Error(`image "${imageId}" was not pre-allocated — this is a writePdf internal invariant violation`);
|
|
44
|
+
return { resourceName: alloc.resourceName };
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
doc.pages.forEach((page, pageIndex) => {
|
|
48
|
+
require_util_abort.throwIfAborted(options.signal);
|
|
49
|
+
const { pageNum, contentsNum } = pageAllocs[pageIndex];
|
|
50
|
+
let pageMcid = 0;
|
|
51
|
+
const pageContext = {
|
|
52
|
+
...context,
|
|
53
|
+
nextMcid: () => pageMcid++,
|
|
54
|
+
layerObjectNumberOf: (name) => layerNumByName.get(name)
|
|
55
|
+
};
|
|
56
|
+
const { bytes: contentBytes, substitutions, missingGlyphs, markedStructure } = require_content_write.writeContentStream(page.items, pageContext);
|
|
57
|
+
if (markedStructure.length > 0) markedStructureByPage.set(pageIndex, [...markedStructure]);
|
|
58
|
+
for (const substitution of substitutions) options.onSubstitution?.(substitution, { pageIndex });
|
|
59
|
+
for (const missing of missingGlyphs) options.onMissingGlyph?.(missing, { pageIndex });
|
|
60
|
+
const pageFormulas = formulasByPage.get(pageIndex);
|
|
61
|
+
const formulaBytes = pageFormulas === void 0 || mathFontAlloc === void 0 || mathFont === void 0 ? void 0 : require_math_content_write.writeFormulaContentStream(pageFormulas, {
|
|
62
|
+
font: mathFont.font,
|
|
63
|
+
resourceName: mathFontAlloc.resourceName
|
|
64
|
+
});
|
|
65
|
+
const combinedContentBytes = formulaBytes === void 0 ? contentBytes : require_bytes_writer.concatBytes([contentBytes, formulaBytes]);
|
|
66
|
+
const finalContentBytes = compress ? require_bytes_flate.deflate(combinedContentBytes) : combinedContentBytes;
|
|
67
|
+
const contentsDict = require_objects.pdfDict(compress ? { Filter: require_objects.pdfName("FlateDecode") } : {});
|
|
68
|
+
objects.push({
|
|
69
|
+
num: contentsNum,
|
|
70
|
+
value: require_objects.pdfStream(contentsDict, finalContentBytes)
|
|
71
|
+
});
|
|
72
|
+
const annots = [...page.items.filter(require_write_annotations.isLinkItem).map((link) => require_write_annotations.buildLinkAnnotDict(link)), ...page.items.filter(require_write_annotations.isInternalLinkItem).map((link) => require_write_annotations.buildInternalLinkAnnotDict(link, doc, pageAllocs))];
|
|
73
|
+
if (page.notes !== void 0 && page.notes.length > 0) annots.push(require_write_annotations.buildNotesAnnotDict(page.notes));
|
|
74
|
+
annots.push(...widgetAnnotsByPage.get(pageIndex) ?? []);
|
|
75
|
+
const pageEntries = /* @__PURE__ */ new Map([
|
|
76
|
+
["Type", require_objects.pdfName("Page")],
|
|
77
|
+
["Parent", require_objects.pdfRef(pagesNum, 0)],
|
|
78
|
+
["MediaBox", require_objects.pdfArray([
|
|
79
|
+
0,
|
|
80
|
+
0,
|
|
81
|
+
page.widthPt,
|
|
82
|
+
page.heightPt
|
|
83
|
+
].map((n) => require_objects.pdfNum(n)))],
|
|
84
|
+
["Resources", resourcesDict],
|
|
85
|
+
["Contents", require_objects.pdfRef(contentsNum, 0)]
|
|
86
|
+
]);
|
|
87
|
+
if (annots.length > 0) pageEntries.set("Annots", require_objects.pdfArray(annots));
|
|
88
|
+
if (markedStructureByPage.has(pageIndex)) pageEntries.set("StructParents", require_objects.pdfNum(pageIndex));
|
|
89
|
+
objects.push({
|
|
90
|
+
num: pageNum,
|
|
91
|
+
value: require_objects.pdfDict(pageEntries)
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
return markedStructureByPage;
|
|
95
|
+
}
|
|
96
|
+
//#endregion
|
|
97
|
+
exports.emitPageObjects = emitPageObjects;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { r as PdfObject } from "./objects-e2RS3-yT.cjs";
|
|
2
|
+
import { LayoutDocument } from "./layout.cjs";
|
|
3
|
+
import { r as EmbeddedFaceSubstitution, t as EmbeddedFace } from "./embedded-font-CqePfvrl.cjs";
|
|
4
|
+
import { WinAnsiSubstitution } from "./winansi.cjs";
|
|
5
|
+
import { FontRegistry } from "./font-registry.cjs";
|
|
6
|
+
import { LoadedMathFont } from "./math-font.cjs";
|
|
7
|
+
import { createFontMeasurer } from "./measure.cjs";
|
|
8
|
+
import { PositionedFormula } from "document-schema.js";
|
|
9
|
+
//#region src/write-page-emit.d.ts
|
|
10
|
+
interface PdfObjectSink {
|
|
11
|
+
num: number;
|
|
12
|
+
value: PdfObject;
|
|
13
|
+
}
|
|
14
|
+
interface WritePdfPageOptions {
|
|
15
|
+
readonly signal?: AbortSignal;
|
|
16
|
+
readonly onSubstitution?: (substitution: WinAnsiSubstitution, context: {
|
|
17
|
+
readonly pageIndex: number;
|
|
18
|
+
}) => void;
|
|
19
|
+
readonly onMissingGlyph?: (missing: EmbeddedFaceSubstitution, context: {
|
|
20
|
+
readonly pageIndex: number;
|
|
21
|
+
}) => void;
|
|
22
|
+
}
|
|
23
|
+
interface PageEmitState {
|
|
24
|
+
readonly doc: LayoutDocument;
|
|
25
|
+
readonly options: WritePdfPageOptions;
|
|
26
|
+
readonly objects: PdfObjectSink[];
|
|
27
|
+
readonly compress: boolean;
|
|
28
|
+
readonly measurer: ReturnType<typeof createFontMeasurer>;
|
|
29
|
+
readonly registry: FontRegistry | undefined;
|
|
30
|
+
readonly fontAllocs: ReadonlyMap<string, {
|
|
31
|
+
resourceName: string;
|
|
32
|
+
fontNum: number;
|
|
33
|
+
descNum: number;
|
|
34
|
+
objNum?: number;
|
|
35
|
+
objNums?: readonly number[];
|
|
36
|
+
}>;
|
|
37
|
+
readonly embeddedAllocs: ReadonlyMap<EmbeddedFace, {
|
|
38
|
+
resourceName: string;
|
|
39
|
+
}>;
|
|
40
|
+
readonly imageAllocs: ReadonlyMap<string, {
|
|
41
|
+
resourceName: string;
|
|
42
|
+
[extra: string]: unknown;
|
|
43
|
+
}>;
|
|
44
|
+
readonly layerNumByName: ReadonlyMap<string, number>;
|
|
45
|
+
readonly formulas: readonly PositionedFormula[];
|
|
46
|
+
readonly mathFontAlloc: {
|
|
47
|
+
resourceName: string;
|
|
48
|
+
} | undefined;
|
|
49
|
+
readonly mathFont: LoadedMathFont | undefined;
|
|
50
|
+
readonly pageAllocs: readonly {
|
|
51
|
+
pageNum: number;
|
|
52
|
+
contentsNum: number;
|
|
53
|
+
}[];
|
|
54
|
+
readonly pagesNum: number;
|
|
55
|
+
readonly resourcesDict: PdfObject;
|
|
56
|
+
readonly widgetAnnotsByPage: ReadonlyMap<number, PdfObject[]>;
|
|
57
|
+
}
|
|
58
|
+
declare function emitPageObjects(s: PageEmitState): Map<number, {
|
|
59
|
+
mcid: number;
|
|
60
|
+
structureId: string;
|
|
61
|
+
}[]>;
|
|
62
|
+
//#endregion
|
|
63
|
+
export { PageEmitState, PdfObjectSink, WritePdfPageOptions, emitPageObjects };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { r as PdfObject } from "./objects-e2RS3-yT.js";
|
|
2
|
+
import { LayoutDocument } from "./layout.js";
|
|
3
|
+
import { r as EmbeddedFaceSubstitution, t as EmbeddedFace } from "./embedded-font-CQZbTTDM.js";
|
|
4
|
+
import { WinAnsiSubstitution } from "./winansi.js";
|
|
5
|
+
import { FontRegistry } from "./font-registry.js";
|
|
6
|
+
import { LoadedMathFont } from "./math-font.js";
|
|
7
|
+
import { createFontMeasurer } from "./measure.js";
|
|
8
|
+
import { PositionedFormula } from "document-schema.js";
|
|
9
|
+
//#region src/write-page-emit.d.ts
|
|
10
|
+
interface PdfObjectSink {
|
|
11
|
+
num: number;
|
|
12
|
+
value: PdfObject;
|
|
13
|
+
}
|
|
14
|
+
interface WritePdfPageOptions {
|
|
15
|
+
readonly signal?: AbortSignal;
|
|
16
|
+
readonly onSubstitution?: (substitution: WinAnsiSubstitution, context: {
|
|
17
|
+
readonly pageIndex: number;
|
|
18
|
+
}) => void;
|
|
19
|
+
readonly onMissingGlyph?: (missing: EmbeddedFaceSubstitution, context: {
|
|
20
|
+
readonly pageIndex: number;
|
|
21
|
+
}) => void;
|
|
22
|
+
}
|
|
23
|
+
interface PageEmitState {
|
|
24
|
+
readonly doc: LayoutDocument;
|
|
25
|
+
readonly options: WritePdfPageOptions;
|
|
26
|
+
readonly objects: PdfObjectSink[];
|
|
27
|
+
readonly compress: boolean;
|
|
28
|
+
readonly measurer: ReturnType<typeof createFontMeasurer>;
|
|
29
|
+
readonly registry: FontRegistry | undefined;
|
|
30
|
+
readonly fontAllocs: ReadonlyMap<string, {
|
|
31
|
+
resourceName: string;
|
|
32
|
+
fontNum: number;
|
|
33
|
+
descNum: number;
|
|
34
|
+
objNum?: number;
|
|
35
|
+
objNums?: readonly number[];
|
|
36
|
+
}>;
|
|
37
|
+
readonly embeddedAllocs: ReadonlyMap<EmbeddedFace, {
|
|
38
|
+
resourceName: string;
|
|
39
|
+
}>;
|
|
40
|
+
readonly imageAllocs: ReadonlyMap<string, {
|
|
41
|
+
resourceName: string;
|
|
42
|
+
[extra: string]: unknown;
|
|
43
|
+
}>;
|
|
44
|
+
readonly layerNumByName: ReadonlyMap<string, number>;
|
|
45
|
+
readonly formulas: readonly PositionedFormula[];
|
|
46
|
+
readonly mathFontAlloc: {
|
|
47
|
+
resourceName: string;
|
|
48
|
+
} | undefined;
|
|
49
|
+
readonly mathFont: LoadedMathFont | undefined;
|
|
50
|
+
readonly pageAllocs: readonly {
|
|
51
|
+
pageNum: number;
|
|
52
|
+
contentsNum: number;
|
|
53
|
+
}[];
|
|
54
|
+
readonly pagesNum: number;
|
|
55
|
+
readonly resourcesDict: PdfObject;
|
|
56
|
+
readonly widgetAnnotsByPage: ReadonlyMap<number, PdfObject[]>;
|
|
57
|
+
}
|
|
58
|
+
declare function emitPageObjects(s: PageEmitState): Map<number, {
|
|
59
|
+
mcid: number;
|
|
60
|
+
structureId: string;
|
|
61
|
+
}[]>;
|
|
62
|
+
//#endregion
|
|
63
|
+
export { PageEmitState, PdfObjectSink, WritePdfPageOptions, emitPageObjects };
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { pdfArray, pdfDict, pdfName, pdfNum, pdfRef, pdfStream } from "./objects.js";
|
|
2
|
+
import { concatBytes } from "./bytes/writer.js";
|
|
3
|
+
import { deflate } from "./bytes/flate.js";
|
|
4
|
+
import { throwIfAborted } from "./util/abort.js";
|
|
5
|
+
import { buildInternalLinkAnnotDict, buildLinkAnnotDict, buildNotesAnnotDict, isInternalLinkItem, isLinkItem } from "./write-annotations.js";
|
|
6
|
+
import { writeFormulaContentStream } from "./math-content-write.js";
|
|
7
|
+
import { writeContentStream } from "./content-write.js";
|
|
8
|
+
import { resolveFaceWithRegistry } from "./font-registry.js";
|
|
9
|
+
//#region src/write-page-emit.ts
|
|
10
|
+
function emitPageObjects(s) {
|
|
11
|
+
const { doc, options, objects, compress, measurer, registry, fontAllocs, embeddedAllocs, imageAllocs, layerNumByName, formulas, mathFontAlloc, mathFont, pageAllocs, pagesNum, resourcesDict, widgetAnnotsByPage } = s;
|
|
12
|
+
const markedStructureByPage = /* @__PURE__ */ new Map();
|
|
13
|
+
const formulasByPage = /* @__PURE__ */ new Map();
|
|
14
|
+
for (const formula of formulas) {
|
|
15
|
+
const forPage = formulasByPage.get(formula.pageIndex);
|
|
16
|
+
if (forPage === void 0) formulasByPage.set(formula.pageIndex, [formula]);
|
|
17
|
+
else forPage.push(formula);
|
|
18
|
+
}
|
|
19
|
+
const context = {
|
|
20
|
+
measurer,
|
|
21
|
+
resolveFont: (font) => {
|
|
22
|
+
const resolved = resolveFaceWithRegistry(registry, font);
|
|
23
|
+
if (resolved.kind === "embedded") {
|
|
24
|
+
const alloc = embeddedAllocs.get(resolved.face);
|
|
25
|
+
if (alloc === void 0) throw new Error(`embedded font "${resolved.face.postScriptName}" was not pre-allocated — this is a writePdf internal invariant violation`);
|
|
26
|
+
return {
|
|
27
|
+
kind: "embedded",
|
|
28
|
+
resourceName: alloc.resourceName,
|
|
29
|
+
face: resolved.face
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
const alloc = fontAllocs.get(resolved.standardName);
|
|
33
|
+
if (alloc === void 0) throw new Error(`font "${resolved.standardName}" was not pre-allocated — this is a writePdf internal invariant violation`);
|
|
34
|
+
return {
|
|
35
|
+
kind: "standard",
|
|
36
|
+
resourceName: alloc.resourceName,
|
|
37
|
+
standardName: resolved.standardName
|
|
38
|
+
};
|
|
39
|
+
},
|
|
40
|
+
resolveImage: (imageId) => {
|
|
41
|
+
const alloc = imageAllocs.get(imageId);
|
|
42
|
+
if (alloc === void 0) throw new Error(`image "${imageId}" was not pre-allocated — this is a writePdf internal invariant violation`);
|
|
43
|
+
return { resourceName: alloc.resourceName };
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
doc.pages.forEach((page, pageIndex) => {
|
|
47
|
+
throwIfAborted(options.signal);
|
|
48
|
+
const { pageNum, contentsNum } = pageAllocs[pageIndex];
|
|
49
|
+
let pageMcid = 0;
|
|
50
|
+
const pageContext = {
|
|
51
|
+
...context,
|
|
52
|
+
nextMcid: () => pageMcid++,
|
|
53
|
+
layerObjectNumberOf: (name) => layerNumByName.get(name)
|
|
54
|
+
};
|
|
55
|
+
const { bytes: contentBytes, substitutions, missingGlyphs, markedStructure } = writeContentStream(page.items, pageContext);
|
|
56
|
+
if (markedStructure.length > 0) markedStructureByPage.set(pageIndex, [...markedStructure]);
|
|
57
|
+
for (const substitution of substitutions) options.onSubstitution?.(substitution, { pageIndex });
|
|
58
|
+
for (const missing of missingGlyphs) options.onMissingGlyph?.(missing, { pageIndex });
|
|
59
|
+
const pageFormulas = formulasByPage.get(pageIndex);
|
|
60
|
+
const formulaBytes = pageFormulas === void 0 || mathFontAlloc === void 0 || mathFont === void 0 ? void 0 : writeFormulaContentStream(pageFormulas, {
|
|
61
|
+
font: mathFont.font,
|
|
62
|
+
resourceName: mathFontAlloc.resourceName
|
|
63
|
+
});
|
|
64
|
+
const combinedContentBytes = formulaBytes === void 0 ? contentBytes : concatBytes([contentBytes, formulaBytes]);
|
|
65
|
+
const finalContentBytes = compress ? deflate(combinedContentBytes) : combinedContentBytes;
|
|
66
|
+
const contentsDict = pdfDict(compress ? { Filter: pdfName("FlateDecode") } : {});
|
|
67
|
+
objects.push({
|
|
68
|
+
num: contentsNum,
|
|
69
|
+
value: pdfStream(contentsDict, finalContentBytes)
|
|
70
|
+
});
|
|
71
|
+
const annots = [...page.items.filter(isLinkItem).map((link) => buildLinkAnnotDict(link)), ...page.items.filter(isInternalLinkItem).map((link) => buildInternalLinkAnnotDict(link, doc, pageAllocs))];
|
|
72
|
+
if (page.notes !== void 0 && page.notes.length > 0) annots.push(buildNotesAnnotDict(page.notes));
|
|
73
|
+
annots.push(...widgetAnnotsByPage.get(pageIndex) ?? []);
|
|
74
|
+
const pageEntries = /* @__PURE__ */ new Map([
|
|
75
|
+
["Type", pdfName("Page")],
|
|
76
|
+
["Parent", pdfRef(pagesNum, 0)],
|
|
77
|
+
["MediaBox", pdfArray([
|
|
78
|
+
0,
|
|
79
|
+
0,
|
|
80
|
+
page.widthPt,
|
|
81
|
+
page.heightPt
|
|
82
|
+
].map((n) => pdfNum(n)))],
|
|
83
|
+
["Resources", resourcesDict],
|
|
84
|
+
["Contents", pdfRef(contentsNum, 0)]
|
|
85
|
+
]);
|
|
86
|
+
if (annots.length > 0) pageEntries.set("Annots", pdfArray(annots));
|
|
87
|
+
if (markedStructureByPage.has(pageIndex)) pageEntries.set("StructParents", pdfNum(pageIndex));
|
|
88
|
+
objects.push({
|
|
89
|
+
num: pageNum,
|
|
90
|
+
value: pdfDict(pageEntries)
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
return markedStructureByPage;
|
|
94
|
+
}
|
|
95
|
+
//#endregion
|
|
96
|
+
export { emitPageObjects };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_objects = require("./objects.cjs");
|
|
3
|
+
//#region src/write-pages.ts
|
|
4
|
+
function emitStructParentTree(state) {
|
|
5
|
+
const { objects, structElementNumById, markedStructureByPage, structureRoots, structRootNum, structParentTreeNum } = state;
|
|
6
|
+
if (structRootNum !== void 0 && structParentTreeNum !== void 0) {
|
|
7
|
+
const nums = [];
|
|
8
|
+
for (const [pageIndex, marks] of markedStructureByPage) {
|
|
9
|
+
const maxMcid = Math.max(...marks.map((mark) => mark.mcid));
|
|
10
|
+
const byMcid = Array.from({ length: maxMcid + 1 }, (_, mcid) => {
|
|
11
|
+
const mark = marks.find((candidate) => candidate.mcid === mcid);
|
|
12
|
+
const elementNum = mark === void 0 ? void 0 : structElementNumById.get(mark.structureId);
|
|
13
|
+
return elementNum === void 0 ? require_objects.pdfNull() : require_objects.pdfRef(elementNum, 0);
|
|
14
|
+
});
|
|
15
|
+
nums.push(require_objects.pdfNum(pageIndex), require_objects.pdfArray(byMcid));
|
|
16
|
+
}
|
|
17
|
+
objects.push({
|
|
18
|
+
num: structParentTreeNum,
|
|
19
|
+
value: require_objects.pdfDict({ Nums: require_objects.pdfArray(nums) })
|
|
20
|
+
});
|
|
21
|
+
const rootEntries = [
|
|
22
|
+
["Type", require_objects.pdfName("StructTreeRoot")],
|
|
23
|
+
["K", require_objects.pdfArray(structureRoots.map((element) => {
|
|
24
|
+
const num = structElementNumById.get(element.id);
|
|
25
|
+
if (num === void 0) throw new Error(`structure element "${element.id}" was not allocated — this is a writePdf internal invariant violation`);
|
|
26
|
+
return require_objects.pdfRef(num, 0);
|
|
27
|
+
}))],
|
|
28
|
+
["ParentTree", require_objects.pdfRef(structParentTreeNum, 0)]
|
|
29
|
+
];
|
|
30
|
+
objects.push({
|
|
31
|
+
num: structRootNum,
|
|
32
|
+
value: require_objects.pdfDict(Object.fromEntries(rootEntries))
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
//#endregion
|
|
37
|
+
exports.emitStructParentTree = emitStructParentTree;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { r as PdfObject } from "./objects-e2RS3-yT.cjs";
|
|
2
|
+
//#region src/write-pages.d.ts
|
|
3
|
+
interface StructParentTreeState {
|
|
4
|
+
readonly objects: {
|
|
5
|
+
num: number;
|
|
6
|
+
value: PdfObject;
|
|
7
|
+
}[];
|
|
8
|
+
readonly structElementNumById: ReadonlyMap<string, number>;
|
|
9
|
+
readonly markedStructureByPage: ReadonlyMap<number, readonly {
|
|
10
|
+
mcid: number;
|
|
11
|
+
structureId: string;
|
|
12
|
+
}[]>;
|
|
13
|
+
readonly structureRoots: readonly {
|
|
14
|
+
id: string;
|
|
15
|
+
}[];
|
|
16
|
+
readonly structRootNum: number | undefined;
|
|
17
|
+
readonly structParentTreeNum: number | undefined;
|
|
18
|
+
}
|
|
19
|
+
declare function emitStructParentTree(state: StructParentTreeState): void;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { StructParentTreeState, emitStructParentTree };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { r as PdfObject } from "./objects-e2RS3-yT.js";
|
|
2
|
+
//#region src/write-pages.d.ts
|
|
3
|
+
interface StructParentTreeState {
|
|
4
|
+
readonly objects: {
|
|
5
|
+
num: number;
|
|
6
|
+
value: PdfObject;
|
|
7
|
+
}[];
|
|
8
|
+
readonly structElementNumById: ReadonlyMap<string, number>;
|
|
9
|
+
readonly markedStructureByPage: ReadonlyMap<number, readonly {
|
|
10
|
+
mcid: number;
|
|
11
|
+
structureId: string;
|
|
12
|
+
}[]>;
|
|
13
|
+
readonly structureRoots: readonly {
|
|
14
|
+
id: string;
|
|
15
|
+
}[];
|
|
16
|
+
readonly structRootNum: number | undefined;
|
|
17
|
+
readonly structParentTreeNum: number | undefined;
|
|
18
|
+
}
|
|
19
|
+
declare function emitStructParentTree(state: StructParentTreeState): void;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { StructParentTreeState, emitStructParentTree };
|