pdf-parser.js 5.2.30 → 5.3.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/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 +531 -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 +527 -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
package/dist/write.cjs
CHANGED
|
@@ -1,27 +1,20 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_afm_widths = require("./afm-widths-
|
|
3
|
-
const require_notes_annotation_author = require("./notes-annotation-author.cjs");
|
|
2
|
+
const require_afm_widths = require("./afm-widths-C6U0SQj9.cjs");
|
|
4
3
|
const require_objects = require("./objects.cjs");
|
|
5
4
|
const require_bytes_writer = require("./bytes/writer.cjs");
|
|
6
5
|
const require_serialize = require("./serialize.cjs");
|
|
7
|
-
const require_bytes_reader = require("./bytes/reader.cjs");
|
|
8
6
|
const require_bytes_flate = require("./bytes/flate.cjs");
|
|
9
|
-
const require_parse = require("./parse.cjs");
|
|
10
|
-
const require_util_abort = require("./util/abort.cjs");
|
|
11
7
|
const require_crypto_random = require("./crypto/random.cjs");
|
|
12
8
|
const require_encrypt_write = require("./encrypt-write.cjs");
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const require_embedded_font_write = require("./embedded-font-write.cjs");
|
|
9
|
+
const require_write_images = require("./write-images.cjs");
|
|
10
|
+
const require_write_strings = require("./write-strings.cjs");
|
|
11
|
+
const require_write_annotations = require("./write-annotations.cjs");
|
|
12
|
+
const require_write_form = require("./write-form.cjs");
|
|
13
|
+
const require_write_font_objects = require("./write-font-objects.cjs");
|
|
19
14
|
const require_font_registry = require("./font-registry.cjs");
|
|
20
|
-
const require_math_content_write = require("./math-content-write.cjs");
|
|
21
|
-
const require_math_font = require("./math-font.cjs");
|
|
22
|
-
const require_math_font_write = require("./math-font-write.cjs");
|
|
23
15
|
const require_measure = require("./measure.cjs");
|
|
24
|
-
const
|
|
16
|
+
const require_write_page_emit = require("./write-page-emit.cjs");
|
|
17
|
+
const require_write_outline = require("./write-outline.cjs");
|
|
25
18
|
let byte_codec = require("byte-codec");
|
|
26
19
|
//#region src/write.ts
|
|
27
20
|
const MATH_FONT_RESOURCE_NAME = "MF";
|
|
@@ -36,43 +29,6 @@ const FLAG_NONSYMBOLIC = 32;
|
|
|
36
29
|
const FLAG_ITALIC = 64;
|
|
37
30
|
const FLAG_FORCE_BOLD = 262144;
|
|
38
31
|
const FILE_ID_BYTES = 16;
|
|
39
|
-
const BITS_PER_BYTE = 8;
|
|
40
|
-
const BYTE_SHIFT = Math.log2(BITS_PER_BYTE);
|
|
41
|
-
const BYTE_MASK = 255;
|
|
42
|
-
const PACKED_BIT_MSB_MASK = 128;
|
|
43
|
-
const BIT_INDEX_MASK = 7;
|
|
44
|
-
function textToPdfString(text) {
|
|
45
|
-
const bytes = new Uint8Array(2 + text.length * 2);
|
|
46
|
-
bytes[0] = 254;
|
|
47
|
-
bytes[1] = 255;
|
|
48
|
-
let offset = 2;
|
|
49
|
-
for (const unit of text.split("")) {
|
|
50
|
-
const code = unit.charCodeAt(0);
|
|
51
|
-
bytes[offset] = code >> BITS_PER_BYTE & BYTE_MASK;
|
|
52
|
-
bytes[offset + 1] = code & BYTE_MASK;
|
|
53
|
-
offset += 2;
|
|
54
|
-
}
|
|
55
|
-
return require_objects.pdfHexString(bytes);
|
|
56
|
-
}
|
|
57
|
-
function pad2(n) {
|
|
58
|
-
return n.toString().padStart(2, "0");
|
|
59
|
-
}
|
|
60
|
-
function formatPdfDate(iso) {
|
|
61
|
-
const date = new Date(iso);
|
|
62
|
-
return `D:${date.getUTCFullYear()}${pad2(date.getUTCMonth() + 1)}${pad2(date.getUTCDate())}${pad2(date.getUTCHours())}${pad2(date.getUTCMinutes())}${pad2(date.getUTCSeconds())}Z`;
|
|
63
|
-
}
|
|
64
|
-
function buildInfoDict(doc) {
|
|
65
|
-
const entries = /* @__PURE__ */ new Map();
|
|
66
|
-
entries.set("Producer", textToPdfString("documents.js"));
|
|
67
|
-
if (doc.metadata.title !== void 0) entries.set("Title", textToPdfString(doc.metadata.title));
|
|
68
|
-
if (doc.metadata.author !== void 0) entries.set("Author", textToPdfString(doc.metadata.author));
|
|
69
|
-
if (doc.metadata.subject !== void 0) entries.set("Subject", textToPdfString(doc.metadata.subject));
|
|
70
|
-
if (doc.metadata.keywords !== void 0) entries.set("Keywords", textToPdfString(doc.metadata.keywords.join(", ")));
|
|
71
|
-
if (doc.metadata.creator !== void 0) entries.set("Creator", textToPdfString(doc.metadata.creator));
|
|
72
|
-
if (doc.metadata.createdIso !== void 0) entries.set("CreationDate", textToPdfString(formatPdfDate(doc.metadata.createdIso)));
|
|
73
|
-
if (doc.metadata.modifiedIso !== void 0) entries.set("ModDate", textToPdfString(formatPdfDate(doc.metadata.modifiedIso)));
|
|
74
|
-
return require_objects.pdfDict(entries);
|
|
75
|
-
}
|
|
76
32
|
function computeFontFlags(standardName, metrics) {
|
|
77
33
|
let flags = FLAG_NONSYMBOLIC;
|
|
78
34
|
if (standardName.startsWith("Courier")) flags |= FLAG_FIXED_PITCH;
|
|
@@ -113,245 +69,6 @@ function buildFontObjects(standardName, descriptorRef) {
|
|
|
113
69
|
function codePointsOf(texts) {
|
|
114
70
|
return new Set(texts.flatMap((text) => [...text].map((character) => character.codePointAt(0))));
|
|
115
71
|
}
|
|
116
|
-
const JPEG_COMPONENTS_CMYK = 4;
|
|
117
|
-
function prepareJpegImage(bytes) {
|
|
118
|
-
const info = require_image_jpeg_info.readJpegInfo(bytes);
|
|
119
|
-
const colorSpace = info.components === 1 ? "DeviceGray" : info.components === JPEG_COMPONENTS_CMYK ? "DeviceCMYK" : "DeviceRGB";
|
|
120
|
-
const entries = /* @__PURE__ */ new Map([
|
|
121
|
-
["Type", require_objects.pdfName("XObject")],
|
|
122
|
-
["Subtype", require_objects.pdfName("Image")],
|
|
123
|
-
["Width", require_objects.pdfNum(info.width)],
|
|
124
|
-
["Height", require_objects.pdfNum(info.height)],
|
|
125
|
-
["ColorSpace", require_objects.pdfName(colorSpace)],
|
|
126
|
-
["BitsPerComponent", require_objects.pdfNum(info.precision)],
|
|
127
|
-
["Filter", require_objects.pdfName("DCTDecode")]
|
|
128
|
-
]);
|
|
129
|
-
if (info.components === JPEG_COMPONENTS_CMYK && (info.adobeTransform === 2 || info.adobeTransform === void 0)) entries.set("Decode", require_objects.pdfArray([
|
|
130
|
-
1,
|
|
131
|
-
0,
|
|
132
|
-
1,
|
|
133
|
-
0,
|
|
134
|
-
1,
|
|
135
|
-
0,
|
|
136
|
-
1,
|
|
137
|
-
0
|
|
138
|
-
].map((n) => require_objects.pdfNum(n))));
|
|
139
|
-
return {
|
|
140
|
-
dict: require_objects.pdfDict(entries),
|
|
141
|
-
raw: bytes
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
function pngImageDict(width, height, colorSpace, compress) {
|
|
145
|
-
const entries = /* @__PURE__ */ new Map([
|
|
146
|
-
["Type", require_objects.pdfName("XObject")],
|
|
147
|
-
["Subtype", require_objects.pdfName("Image")],
|
|
148
|
-
["Width", require_objects.pdfNum(width)],
|
|
149
|
-
["Height", require_objects.pdfNum(height)],
|
|
150
|
-
["ColorSpace", require_objects.pdfName(colorSpace)],
|
|
151
|
-
["BitsPerComponent", require_objects.pdfNum(BITS_PER_BYTE)]
|
|
152
|
-
]);
|
|
153
|
-
if (compress) entries.set("Filter", require_objects.pdfName("FlateDecode"));
|
|
154
|
-
return require_objects.pdfDict(entries);
|
|
155
|
-
}
|
|
156
|
-
function packBilevel(raw) {
|
|
157
|
-
const rowBytes = raw.width + BIT_INDEX_MASK >> BYTE_SHIFT;
|
|
158
|
-
const packed = new Uint8Array(rowBytes * raw.height);
|
|
159
|
-
const view = new DataView(packed.buffer);
|
|
160
|
-
for (let index = 0; index < raw.data.length; index++) {
|
|
161
|
-
const sample = raw.data[index];
|
|
162
|
-
if (sample !== 0 && sample !== BYTE_MASK) return;
|
|
163
|
-
if (sample === BYTE_MASK) {
|
|
164
|
-
const x = index % raw.width;
|
|
165
|
-
const byteIndex = Math.floor(index / raw.width) * rowBytes + (x >> BYTE_SHIFT);
|
|
166
|
-
view.setUint8(byteIndex, view.getUint8(byteIndex) | PACKED_BIT_MSB_MASK >> (x & BIT_INDEX_MASK));
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
return packed;
|
|
170
|
-
}
|
|
171
|
-
function preparePngImage(bytes, compress) {
|
|
172
|
-
const raw = require_image_png_decode.decodePng(bytes);
|
|
173
|
-
const colorSpace = raw.channels === 1 ? "DeviceGray" : "DeviceRGB";
|
|
174
|
-
if (compress && raw.channels === 1 && raw.alpha === void 0) {
|
|
175
|
-
const bilevel = packBilevel(raw);
|
|
176
|
-
if (bilevel !== void 0) {
|
|
177
|
-
const flate = require_bytes_flate.deflate(raw.data);
|
|
178
|
-
const g4 = require_image_ccitt_encode.encodeCcittFax(bilevel, {
|
|
179
|
-
columns: raw.width,
|
|
180
|
-
rows: raw.height,
|
|
181
|
-
maxBytes: flate.length
|
|
182
|
-
});
|
|
183
|
-
if (g4 !== void 0) return {
|
|
184
|
-
dict: require_objects.pdfDict(/* @__PURE__ */ new Map([
|
|
185
|
-
["Type", require_objects.pdfName("XObject")],
|
|
186
|
-
["Subtype", require_objects.pdfName("Image")],
|
|
187
|
-
["Width", require_objects.pdfNum(raw.width)],
|
|
188
|
-
["Height", require_objects.pdfNum(raw.height)],
|
|
189
|
-
["ColorSpace", require_objects.pdfName("DeviceGray")],
|
|
190
|
-
["BitsPerComponent", require_objects.pdfNum(1)],
|
|
191
|
-
["Filter", require_objects.pdfName("CCITTFaxDecode")],
|
|
192
|
-
["DecodeParms", require_objects.pdfDict(/* @__PURE__ */ new Map([
|
|
193
|
-
["K", require_objects.pdfNum(-1)],
|
|
194
|
-
["Columns", require_objects.pdfNum(raw.width)],
|
|
195
|
-
["Rows", require_objects.pdfNum(raw.height)],
|
|
196
|
-
["BlackIs1", require_objects.pdfBool(false)]
|
|
197
|
-
]))]
|
|
198
|
-
])),
|
|
199
|
-
raw: g4,
|
|
200
|
-
alpha: void 0
|
|
201
|
-
};
|
|
202
|
-
return {
|
|
203
|
-
dict: pngImageDict(raw.width, raw.height, colorSpace, true),
|
|
204
|
-
raw: flate,
|
|
205
|
-
alpha: void 0
|
|
206
|
-
};
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
return {
|
|
210
|
-
dict: pngImageDict(raw.width, raw.height, colorSpace, compress),
|
|
211
|
-
raw: compress ? require_bytes_flate.deflate(raw.data) : raw.data,
|
|
212
|
-
alpha: raw.alpha === void 0 ? void 0 : {
|
|
213
|
-
dict: pngImageDict(raw.width, raw.height, "DeviceGray", compress),
|
|
214
|
-
raw: compress ? require_bytes_flate.deflate(raw.alpha) : raw.alpha
|
|
215
|
-
}
|
|
216
|
-
};
|
|
217
|
-
}
|
|
218
|
-
function preparePassthroughImage(asset, original, compress) {
|
|
219
|
-
const png = preparePngImage((0, byte_codec.base64ToBytes)(asset.base64), compress);
|
|
220
|
-
const entries = /* @__PURE__ */ new Map([
|
|
221
|
-
["Type", require_objects.pdfName("XObject")],
|
|
222
|
-
["Subtype", require_objects.pdfName("Image")],
|
|
223
|
-
["Width", require_objects.pdfNum(asset.widthPx)],
|
|
224
|
-
["Height", require_objects.pdfNum(asset.heightPx)],
|
|
225
|
-
["Filter", require_objects.pdfName(original.filter === "jbig2" ? "JBIG2Decode" : "JPXDecode")]
|
|
226
|
-
]);
|
|
227
|
-
if (original.filter === "jbig2") {
|
|
228
|
-
entries.set("ColorSpace", require_objects.pdfName("DeviceGray"));
|
|
229
|
-
entries.set("BitsPerComponent", require_objects.pdfNum(1));
|
|
230
|
-
}
|
|
231
|
-
return {
|
|
232
|
-
dict: require_objects.pdfDict(entries),
|
|
233
|
-
raw: (0, byte_codec.base64ToBytes)(original.base64),
|
|
234
|
-
alpha: png.alpha
|
|
235
|
-
};
|
|
236
|
-
}
|
|
237
|
-
function prepareImage(asset, compress) {
|
|
238
|
-
if (asset.original !== void 0) return preparePassthroughImage(asset, asset.original, compress);
|
|
239
|
-
const bytes = (0, byte_codec.base64ToBytes)(asset.base64);
|
|
240
|
-
return asset.format === "jpeg" ? prepareJpegImage(bytes) : preparePngImage(bytes, compress);
|
|
241
|
-
}
|
|
242
|
-
function buildLinkAnnotDict(link) {
|
|
243
|
-
return require_objects.pdfDict({
|
|
244
|
-
Type: require_objects.pdfName("Annot"),
|
|
245
|
-
Subtype: require_objects.pdfName("Link"),
|
|
246
|
-
Rect: require_objects.pdfArray([
|
|
247
|
-
link.xPt,
|
|
248
|
-
link.yPt,
|
|
249
|
-
link.xPt + link.widthPt,
|
|
250
|
-
link.yPt + link.heightPt
|
|
251
|
-
].map((n) => require_objects.pdfNum(n))),
|
|
252
|
-
Border: require_objects.pdfArray([
|
|
253
|
-
0,
|
|
254
|
-
0,
|
|
255
|
-
0
|
|
256
|
-
].map((n) => require_objects.pdfNum(n))),
|
|
257
|
-
A: require_objects.pdfDict({
|
|
258
|
-
Type: require_objects.pdfName("Action"),
|
|
259
|
-
S: require_objects.pdfName("URI"),
|
|
260
|
-
URI: require_objects.pdfHexString(new TextEncoder().encode(link.uri))
|
|
261
|
-
})
|
|
262
|
-
});
|
|
263
|
-
}
|
|
264
|
-
function destinationViewArray(target) {
|
|
265
|
-
const n = (value) => value === void 0 ? require_objects.pdfNull() : require_objects.pdfNum(value);
|
|
266
|
-
if (target.kind === "xyz") return [
|
|
267
|
-
require_objects.pdfName("XYZ"),
|
|
268
|
-
n(target.leftPt),
|
|
269
|
-
n(target.topPt),
|
|
270
|
-
n(target.zoom)
|
|
271
|
-
];
|
|
272
|
-
if (target.kind === "fitH") return [require_objects.pdfName("FitH"), n(target.topPt)];
|
|
273
|
-
if (target.kind === "fitV") return [require_objects.pdfName("FitV"), n(target.leftPt)];
|
|
274
|
-
if (target.kind === "fitR") return [
|
|
275
|
-
require_objects.pdfName("FitR"),
|
|
276
|
-
n(target.leftPt),
|
|
277
|
-
n(target.bottomPt),
|
|
278
|
-
n(target.rightPt),
|
|
279
|
-
n(target.topPt)
|
|
280
|
-
];
|
|
281
|
-
if (target.kind === "fitBH") return [require_objects.pdfName("FitBH"), n(target.topPt)];
|
|
282
|
-
if (target.kind === "fitBV") return [require_objects.pdfName("FitBV"), n(target.leftPt)];
|
|
283
|
-
return [require_objects.pdfName(target.kind === "fitB" ? "FitB" : "Fit")];
|
|
284
|
-
}
|
|
285
|
-
function resolveDestinationArray(doc, pageAllocs, name, what) {
|
|
286
|
-
const destination = doc.destinations?.find((d) => d.name === name);
|
|
287
|
-
if (destination === void 0) throw new Error(`${what} names destination "${name}", which the document's destinations table does not carry — this is a caller-invariant violation`);
|
|
288
|
-
const targetPage = pageAllocs[destination.pageIndex];
|
|
289
|
-
if (targetPage === void 0) throw new Error(`destination "${destination.name}" names page index ${destination.pageIndex}, which is beyond the document's own pages — this is a caller-invariant violation`);
|
|
290
|
-
return [require_objects.pdfRef(targetPage.pageNum, 0), ...destinationViewArray(destination.target)];
|
|
291
|
-
}
|
|
292
|
-
function buildInternalLinkAnnotDict(link, doc, pageAllocs) {
|
|
293
|
-
return require_objects.pdfDict({
|
|
294
|
-
Type: require_objects.pdfName("Annot"),
|
|
295
|
-
Subtype: require_objects.pdfName("Link"),
|
|
296
|
-
Rect: require_objects.pdfArray([
|
|
297
|
-
link.xPt,
|
|
298
|
-
link.yPt,
|
|
299
|
-
link.xPt + link.widthPt,
|
|
300
|
-
link.yPt + link.heightPt
|
|
301
|
-
].map((v) => require_objects.pdfNum(v))),
|
|
302
|
-
Border: require_objects.pdfArray([
|
|
303
|
-
0,
|
|
304
|
-
0,
|
|
305
|
-
0
|
|
306
|
-
].map((v) => require_objects.pdfNum(v))),
|
|
307
|
-
Dest: require_objects.pdfArray(resolveDestinationArray(doc, pageAllocs, link.destination, "internal link"))
|
|
308
|
-
});
|
|
309
|
-
}
|
|
310
|
-
function isLinkItem(item) {
|
|
311
|
-
return item.kind === "link";
|
|
312
|
-
}
|
|
313
|
-
function isInternalLinkItem(item) {
|
|
314
|
-
return item.kind === "internalLink";
|
|
315
|
-
}
|
|
316
|
-
const NOTES_ANNOTATION_HIDDEN_FLAG = 2;
|
|
317
|
-
function buildNotesAnnotDict(notes) {
|
|
318
|
-
return require_objects.pdfDict({
|
|
319
|
-
Type: require_objects.pdfName("Annot"),
|
|
320
|
-
Subtype: require_objects.pdfName("Text"),
|
|
321
|
-
Rect: require_objects.pdfArray([
|
|
322
|
-
0,
|
|
323
|
-
0,
|
|
324
|
-
0,
|
|
325
|
-
0
|
|
326
|
-
].map((n) => require_objects.pdfNum(n))),
|
|
327
|
-
Contents: textToPdfString(notes),
|
|
328
|
-
T: textToPdfString(require_notes_annotation_author.NOTES_ANNOTATION_AUTHOR),
|
|
329
|
-
F: require_objects.pdfNum(NOTES_ANNOTATION_HIDDEN_FLAG)
|
|
330
|
-
});
|
|
331
|
-
}
|
|
332
|
-
const XREF_OFFSET_DIGITS = 10;
|
|
333
|
-
const XREF_GENERATION_DIGITS = 5;
|
|
334
|
-
function xrefEntry(offset, generation, inUse) {
|
|
335
|
-
return `${offset.toString().padStart(XREF_OFFSET_DIGITS, "0")} ${generation.toString().padStart(XREF_GENERATION_DIGITS, "0")} ${inUse ? "n" : "f"} \n`;
|
|
336
|
-
}
|
|
337
|
-
function parseResidueRow(residue) {
|
|
338
|
-
const reader = new require_bytes_reader.ByteReader(new TextEncoder().encode(residue.xml));
|
|
339
|
-
return require_parse.parseValue(reader, () => void 0);
|
|
340
|
-
}
|
|
341
|
-
function objectContainsReference(obj) {
|
|
342
|
-
if (obj.kind === "ref") return true;
|
|
343
|
-
if (obj.kind === "array") return obj.items.some(objectContainsReference);
|
|
344
|
-
if (obj.kind === "dict") return [...obj.entries.values()].some(objectContainsReference);
|
|
345
|
-
if (obj.kind === "stream") return [...obj.dict.entries.values()].some(objectContainsReference);
|
|
346
|
-
return false;
|
|
347
|
-
}
|
|
348
|
-
function restoreResidueRow(source, key) {
|
|
349
|
-
const row = source?.[key];
|
|
350
|
-
if (row === void 0) return;
|
|
351
|
-
const parsed = parseResidueRow(row);
|
|
352
|
-
if (parsed === void 0 || objectContainsReference(parsed)) return;
|
|
353
|
-
return parsed;
|
|
354
|
-
}
|
|
355
72
|
function writePdf(doc, options = {}) {
|
|
356
73
|
const compress = options.compress ?? true;
|
|
357
74
|
const registry = options.fonts;
|
|
@@ -385,7 +102,7 @@ function writePdf(doc, options = {}) {
|
|
|
385
102
|
for (const [index, imageId] of [...imageIds].sort().entries()) {
|
|
386
103
|
const asset = doc.images[imageId];
|
|
387
104
|
if (asset === void 0) throw new Error(`LayoutDocument references image "${imageId}" but it is not present in images`);
|
|
388
|
-
const prepared = prepareImage(asset, compress);
|
|
105
|
+
const prepared = require_write_images.prepareImage(asset, compress);
|
|
389
106
|
const imageNum = nextObjNum++;
|
|
390
107
|
const smaskNum = prepared.alpha === void 0 ? void 0 : nextObjNum++;
|
|
391
108
|
const globalsBase64 = asset.original?.filter === "jbig2" ? asset.original.jbig2GlobalsBase64 : void 0;
|
|
@@ -497,7 +214,7 @@ function writePdf(doc, options = {}) {
|
|
|
497
214
|
if (doc.form !== void 0 && doc.form.length > 0) catalogEntries.push(["AcroForm", require_objects.pdfDict({ Fields: require_objects.pdfArray(doc.form.map((field) => require_objects.pdfRef(formNumOf(field), 0))) })]);
|
|
498
215
|
if (structRootNum !== void 0) catalogEntries.push(["StructTreeRoot", require_objects.pdfRef(structRootNum, 0)]);
|
|
499
216
|
if (residueXmpNum !== void 0) catalogEntries.push(["Metadata", require_objects.pdfRef(residueXmpNum, 0)]);
|
|
500
|
-
const trailerIdRestore = restoreResidueRow(doc.source, "trailer-id");
|
|
217
|
+
const trailerIdRestore = require_write_annotations.restoreResidueRow(doc.source, "trailer-id");
|
|
501
218
|
for (const [rowKey, catalogKey] of [
|
|
502
219
|
["viewer-preferences", "ViewerPreferences"],
|
|
503
220
|
["page-mode", "PageMode"],
|
|
@@ -507,7 +224,7 @@ function writePdf(doc, options = {}) {
|
|
|
507
224
|
["legal", "Legal"],
|
|
508
225
|
["collection", "Collection"]
|
|
509
226
|
]) {
|
|
510
|
-
const restored = restoreResidueRow(doc.source, rowKey);
|
|
227
|
+
const restored = require_write_annotations.restoreResidueRow(doc.source, rowKey);
|
|
511
228
|
if (restored !== void 0) catalogEntries.push([catalogKey, restored]);
|
|
512
229
|
}
|
|
513
230
|
objects.push({
|
|
@@ -524,7 +241,7 @@ function writePdf(doc, options = {}) {
|
|
|
524
241
|
});
|
|
525
242
|
objects.push({
|
|
526
243
|
num: infoNum,
|
|
527
|
-
value: buildInfoDict(doc)
|
|
244
|
+
value: require_write_strings.buildInfoDict(doc)
|
|
528
245
|
});
|
|
529
246
|
for (const [index, attachment] of (doc.attachments ?? []).entries()) {
|
|
530
247
|
const alloc = attachmentAllocs[index];
|
|
@@ -556,43 +273,13 @@ function writePdf(doc, options = {}) {
|
|
|
556
273
|
value: require_objects.pdfDict({ EmbeddedFiles: require_objects.pdfDict({ Names: require_objects.pdfArray(names) }) })
|
|
557
274
|
});
|
|
558
275
|
}
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
itemCursor += 1;
|
|
567
|
-
siblingNums.push(ownNum);
|
|
568
|
-
const childNums = emitItems(item.children, ownNum);
|
|
569
|
-
const entries = [["Title", require_objects.pdfLiteralString(new TextEncoder().encode(item.title))], ["Parent", require_objects.pdfRef(parentNum, 0)]];
|
|
570
|
-
if (item.destination !== void 0) entries.push(["Dest", require_objects.pdfArray(resolveDestinationArray(doc, pageAllocs, item.destination, `outline item "${item.title}"`))]);
|
|
571
|
-
if (prevNum !== void 0) entries.push(["Prev", require_objects.pdfRef(prevNum, 0)]);
|
|
572
|
-
if (siblingNums.length < items.length) entries.push(["Next", require_objects.pdfRef(outlineItemNums[itemCursor], 0)]);
|
|
573
|
-
if (childNums.length > 0) {
|
|
574
|
-
entries.push(["First", require_objects.pdfRef(childNums[0], 0)]);
|
|
575
|
-
entries.push(["Last", require_objects.pdfRef(childNums[childNums.length - 1], 0)]);
|
|
576
|
-
entries.push(["Count", require_objects.pdfNum(childNums.length)]);
|
|
577
|
-
}
|
|
578
|
-
objects.push({
|
|
579
|
-
num: ownNum,
|
|
580
|
-
value: require_objects.pdfDict(Object.fromEntries(entries))
|
|
581
|
-
});
|
|
582
|
-
prevNum = ownNum;
|
|
583
|
-
}
|
|
584
|
-
return siblingNums;
|
|
585
|
-
};
|
|
586
|
-
const topLevelNums = emitItems(doc.outline ?? [], outlineRootNum);
|
|
587
|
-
objects.push({
|
|
588
|
-
num: outlineRootNum,
|
|
589
|
-
value: require_objects.pdfDict({
|
|
590
|
-
Type: require_objects.pdfName("Outlines"),
|
|
591
|
-
First: require_objects.pdfRef(topLevelNums[0], 0),
|
|
592
|
-
Last: require_objects.pdfRef(topLevelNums[topLevelNums.length - 1], 0)
|
|
593
|
-
})
|
|
594
|
-
});
|
|
595
|
-
}
|
|
276
|
+
require_write_outline.emitOutlineObjects({
|
|
277
|
+
objects,
|
|
278
|
+
outlineItemNums,
|
|
279
|
+
outlineRootNum,
|
|
280
|
+
doc,
|
|
281
|
+
pageAllocs
|
|
282
|
+
});
|
|
596
283
|
for (const layer of doc.layers ?? []) {
|
|
597
284
|
const num = layerNumByName.get(layer.name);
|
|
598
285
|
objects.push({
|
|
@@ -604,85 +291,13 @@ function writePdf(doc, options = {}) {
|
|
|
604
291
|
});
|
|
605
292
|
}
|
|
606
293
|
const widgetAnnotsByPage = /* @__PURE__ */ new Map();
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
widget.yPt,
|
|
615
|
-
widget.xPt + widget.widthPt,
|
|
616
|
-
widget.yPt + widget.heightPt
|
|
617
|
-
].map((n) => require_objects.pdfNum(n)));
|
|
618
|
-
const widgetDict = (widget) => require_objects.pdfDict({
|
|
619
|
-
Subtype: require_objects.pdfName("Widget"),
|
|
620
|
-
Rect: widgetRectArray(widget),
|
|
621
|
-
P: require_objects.pdfRef(pageAllocs[widget.pageIndex].pageNum, 0)
|
|
622
|
-
});
|
|
623
|
-
const FIELD_TYPE_PDF_NAME = {
|
|
624
|
-
text: "Tx",
|
|
625
|
-
checkbox: "Btn",
|
|
626
|
-
radio: "Btn",
|
|
627
|
-
button: "Btn",
|
|
628
|
-
listbox: "Ch",
|
|
629
|
-
combobox: "Ch",
|
|
630
|
-
signature: "Sig"
|
|
631
|
-
};
|
|
632
|
-
const emitFormFieldObjects = (fields, parentName) => {
|
|
633
|
-
for (const field of fields) {
|
|
634
|
-
const ownName = parentName === void 0 ? field.name : field.name.startsWith(`${parentName}.`) ? field.name.slice(parentName.length + 1) : field.name;
|
|
635
|
-
const entries = [];
|
|
636
|
-
if (ownName.length > 0) entries.push(["T", require_objects.pdfLiteralString(new TextEncoder().encode(ownName))]);
|
|
637
|
-
if (field.alias !== void 0) entries.push(["TU", require_objects.pdfLiteralString(new TextEncoder().encode(field.alias))]);
|
|
638
|
-
if (field.fieldType === "group") entries.push(["Kids", require_objects.pdfArray(field.children.map((child) => require_objects.pdfRef(formNumOf(child), 0)))]);
|
|
639
|
-
else {
|
|
640
|
-
entries.push(["FT", require_objects.pdfName(FIELD_TYPE_PDF_NAME[field.fieldType])]);
|
|
641
|
-
const FLAG_READ_ONLY = 1;
|
|
642
|
-
const FLAG_PUSHBUTTON = 4;
|
|
643
|
-
const FLAG_RADIO = 32768;
|
|
644
|
-
const FLAG_COMBO = 131072;
|
|
645
|
-
let flags = 0;
|
|
646
|
-
if (field.readOnly === true) flags |= FLAG_READ_ONLY;
|
|
647
|
-
if (field.fieldType === "button") flags |= FLAG_PUSHBUTTON;
|
|
648
|
-
if (field.fieldType === "radio") flags |= FLAG_RADIO;
|
|
649
|
-
if (field.fieldType === "combobox") flags |= FLAG_COMBO;
|
|
650
|
-
if (flags !== 0) entries.push(["Ff", require_objects.pdfNum(flags)]);
|
|
651
|
-
if (field.fieldType === "text" || field.fieldType === "listbox" || field.fieldType === "combobox") {
|
|
652
|
-
if (field.value !== void 0) entries.push(["V", require_objects.pdfLiteralString(new TextEncoder().encode(field.value))]);
|
|
653
|
-
} else if (field.fieldType === "checkbox" || field.fieldType === "radio") entries.push(["V", require_objects.pdfName(field.value ?? (field.checked === true ? "Yes" : "Off"))]);
|
|
654
|
-
if (field.options !== void 0) entries.push(["Opt", require_objects.pdfArray(field.options.map((option) => require_objects.pdfLiteralString(new TextEncoder().encode(option))))]);
|
|
655
|
-
const firstWidget = field.widgets[0];
|
|
656
|
-
if (field.widgets.length === 1 && firstWidget !== void 0) {
|
|
657
|
-
entries.push(["Subtype", require_objects.pdfName("Widget")]);
|
|
658
|
-
entries.push(["Rect", widgetRectArray(firstWidget)]);
|
|
659
|
-
entries.push(["P", require_objects.pdfRef(pageAllocs[firstWidget.pageIndex].pageNum, 0)]);
|
|
660
|
-
noteWidgetAnnot(firstWidget, require_objects.pdfRef(formNumOf(field), 0));
|
|
661
|
-
} else if (formExtraWidgetNums.has(field)) {
|
|
662
|
-
const extraNums = formExtraWidgetNums.get(field) ?? [];
|
|
663
|
-
entries.push(["Kids", require_objects.pdfArray(extraNums.map((num) => require_objects.pdfRef(num, 0)))]);
|
|
664
|
-
for (const [index, num] of extraNums.entries()) {
|
|
665
|
-
const widget = field.widgets[index];
|
|
666
|
-
if (widget !== void 0) noteWidgetAnnot(widget, require_objects.pdfRef(num, 0));
|
|
667
|
-
}
|
|
668
|
-
}
|
|
669
|
-
}
|
|
670
|
-
objects.push({
|
|
671
|
-
num: formNumOf(field),
|
|
672
|
-
value: require_objects.pdfDict(Object.fromEntries(entries))
|
|
673
|
-
});
|
|
674
|
-
const extraNums = formExtraWidgetNums.get(field) ?? [];
|
|
675
|
-
for (const [index, num] of extraNums.entries()) {
|
|
676
|
-
const widget = field.widgets[index];
|
|
677
|
-
if (widget !== void 0) objects.push({
|
|
678
|
-
num,
|
|
679
|
-
value: widgetDict(widget)
|
|
680
|
-
});
|
|
681
|
-
}
|
|
682
|
-
emitFormFieldObjects(field.children, field.name);
|
|
683
|
-
}
|
|
684
|
-
};
|
|
685
|
-
emitFormFieldObjects(doc.form ?? [], void 0);
|
|
294
|
+
require_write_form.emitFormObjects({
|
|
295
|
+
objects,
|
|
296
|
+
widgetAnnotsByPage,
|
|
297
|
+
pageAllocs,
|
|
298
|
+
formNumOf,
|
|
299
|
+
formExtraWidgetNums
|
|
300
|
+
}, doc.form ?? []);
|
|
686
301
|
if (structRootNum !== void 0) {
|
|
687
302
|
const emitStructureElement = (element, parentNum) => {
|
|
688
303
|
const entries = [
|
|
@@ -748,67 +363,14 @@ function writePdf(doc, options = {}) {
|
|
|
748
363
|
value: require_objects.pdfStream(alloc.prepared.dict, alloc.prepared.raw)
|
|
749
364
|
});
|
|
750
365
|
}
|
|
751
|
-
const
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
}, compress);
|
|
760
|
-
objects.push({
|
|
761
|
-
num: mathFontAlloc.type0Num,
|
|
762
|
-
value: built.type0
|
|
763
|
-
});
|
|
764
|
-
objects.push({
|
|
765
|
-
num: mathFontAlloc.cidFontNum,
|
|
766
|
-
value: built.cidFont
|
|
767
|
-
});
|
|
768
|
-
objects.push({
|
|
769
|
-
num: mathFontAlloc.descriptorNum,
|
|
770
|
-
value: built.descriptor
|
|
771
|
-
});
|
|
772
|
-
objects.push({
|
|
773
|
-
num: mathFontAlloc.fontFileNum,
|
|
774
|
-
value: built.fontFile
|
|
775
|
-
});
|
|
776
|
-
objects.push({
|
|
777
|
-
num: mathFontAlloc.toUnicodeNum,
|
|
778
|
-
value: built.toUnicode
|
|
779
|
-
});
|
|
780
|
-
}
|
|
781
|
-
for (const [face, alloc] of embeddedAllocs) {
|
|
782
|
-
const faceUsedGlyphs = require_embedded_font.collectEmbeddedGlyphs(alloc.texts, face);
|
|
783
|
-
const subset = require_sfnt_subset.subsetSfnt(face.font, [...alloc.codePoints], [...faceUsedGlyphs.keys()]);
|
|
784
|
-
if (subset === void 0) throw new Error(`font "${face.postScriptName}" resolved to an embeddable face, but its glyph outlines could not be subsetted — only TrueType-outline ('glyf') fonts can be embedded, so supply a TrueType face for this family or drop it from the registry`);
|
|
785
|
-
const built = require_embedded_font_write.buildEmbeddedFontObjects(face, subset, faceUsedGlyphs, {
|
|
786
|
-
cidFontRef: require_objects.pdfRef(alloc.cidFontNum, 0),
|
|
787
|
-
descriptorRef: require_objects.pdfRef(alloc.descriptorNum, 0),
|
|
788
|
-
fontFileRef: require_objects.pdfRef(alloc.fontFileNum, 0),
|
|
789
|
-
toUnicodeRef: require_objects.pdfRef(alloc.toUnicodeNum, 0)
|
|
790
|
-
}, compress);
|
|
791
|
-
objects.push({
|
|
792
|
-
num: alloc.type0Num,
|
|
793
|
-
value: built.type0
|
|
794
|
-
});
|
|
795
|
-
objects.push({
|
|
796
|
-
num: alloc.cidFontNum,
|
|
797
|
-
value: built.cidFont
|
|
798
|
-
});
|
|
799
|
-
objects.push({
|
|
800
|
-
num: alloc.descriptorNum,
|
|
801
|
-
value: built.descriptor
|
|
802
|
-
});
|
|
803
|
-
objects.push({
|
|
804
|
-
num: alloc.fontFileNum,
|
|
805
|
-
value: built.fontFile
|
|
806
|
-
});
|
|
807
|
-
objects.push({
|
|
808
|
-
num: alloc.toUnicodeNum,
|
|
809
|
-
value: built.toUnicode
|
|
810
|
-
});
|
|
811
|
-
}
|
|
366
|
+
const mathFontResult = require_write_font_objects.emitFontObjects({
|
|
367
|
+
objects,
|
|
368
|
+
formulas,
|
|
369
|
+
mathFontAlloc,
|
|
370
|
+
embeddedAllocs,
|
|
371
|
+
compress
|
|
372
|
+
});
|
|
373
|
+
const mathFont = mathFontResult === void 0 ? void 0 : mathFontResult.font;
|
|
812
374
|
const resourceEntries = /* @__PURE__ */ new Map();
|
|
813
375
|
if (fontAllocs.size > 0 || embeddedAllocs.size > 0 || mathFontAlloc !== void 0) {
|
|
814
376
|
const fontEntries = new Map([...fontAllocs.values()].map((alloc) => [alloc.resourceName, require_objects.pdfRef(alloc.fontNum, 0)]));
|
|
@@ -818,86 +380,24 @@ function writePdf(doc, options = {}) {
|
|
|
818
380
|
}
|
|
819
381
|
if (imageAllocs.size > 0) resourceEntries.set("XObject", require_objects.pdfDict(new Map([...imageAllocs.values()].map((alloc) => [alloc.resourceName, require_objects.pdfRef(alloc.imageNum, 0)]))));
|
|
820
382
|
const resourcesDict = require_objects.pdfDict(resourceEntries);
|
|
821
|
-
const markedStructureByPage =
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
else forPage.push(formula);
|
|
827
|
-
}
|
|
828
|
-
const context = {
|
|
383
|
+
const markedStructureByPage = require_write_page_emit.emitPageObjects({
|
|
384
|
+
doc,
|
|
385
|
+
options,
|
|
386
|
+
objects,
|
|
387
|
+
compress,
|
|
829
388
|
measurer,
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
if (alloc === void 0) throw new Error(`font "${resolved.standardName}" was not pre-allocated — this is a writePdf internal invariant violation`);
|
|
843
|
-
return {
|
|
844
|
-
kind: "standard",
|
|
845
|
-
resourceName: alloc.resourceName,
|
|
846
|
-
standardName: resolved.standardName
|
|
847
|
-
};
|
|
848
|
-
},
|
|
849
|
-
resolveImage: (imageId) => {
|
|
850
|
-
const alloc = imageAllocs.get(imageId);
|
|
851
|
-
if (alloc === void 0) throw new Error(`image "${imageId}" was not pre-allocated — this is a writePdf internal invariant violation`);
|
|
852
|
-
return { resourceName: alloc.resourceName };
|
|
853
|
-
}
|
|
854
|
-
};
|
|
855
|
-
doc.pages.forEach((page, pageIndex) => {
|
|
856
|
-
require_util_abort.throwIfAborted(options.signal);
|
|
857
|
-
const { pageNum, contentsNum } = pageAllocs[pageIndex];
|
|
858
|
-
let pageMcid = 0;
|
|
859
|
-
const pageContext = {
|
|
860
|
-
...context,
|
|
861
|
-
nextMcid: () => pageMcid++,
|
|
862
|
-
layerObjectNumberOf: (name) => layerNumByName.get(name)
|
|
863
|
-
};
|
|
864
|
-
const { bytes: contentBytes, substitutions, missingGlyphs, markedStructure } = require_content_write.writeContentStream(page.items, pageContext);
|
|
865
|
-
if (markedStructure.length > 0) markedStructureByPage.set(pageIndex, [...markedStructure]);
|
|
866
|
-
for (const substitution of substitutions) options.onSubstitution?.(substitution, { pageIndex });
|
|
867
|
-
for (const missing of missingGlyphs) options.onMissingGlyph?.(missing, { pageIndex });
|
|
868
|
-
const pageFormulas = formulasByPage.get(pageIndex);
|
|
869
|
-
const formulaBytes = pageFormulas === void 0 || mathFontAlloc === void 0 || mathFont === void 0 ? void 0 : require_math_content_write.writeFormulaContentStream(pageFormulas, {
|
|
870
|
-
font: mathFont,
|
|
871
|
-
resourceName: mathFontAlloc.resourceName
|
|
872
|
-
});
|
|
873
|
-
const combinedContentBytes = formulaBytes === void 0 ? contentBytes : require_bytes_writer.concatBytes([contentBytes, formulaBytes]);
|
|
874
|
-
const finalContentBytes = compress ? require_bytes_flate.deflate(combinedContentBytes) : combinedContentBytes;
|
|
875
|
-
const contentsDict = require_objects.pdfDict(compress ? { Filter: require_objects.pdfName("FlateDecode") } : {});
|
|
876
|
-
objects.push({
|
|
877
|
-
num: contentsNum,
|
|
878
|
-
value: require_objects.pdfStream(contentsDict, finalContentBytes)
|
|
879
|
-
});
|
|
880
|
-
const annots = [...page.items.filter(isLinkItem).map((link) => buildLinkAnnotDict(link)), ...page.items.filter(isInternalLinkItem).map((link) => buildInternalLinkAnnotDict(link, doc, pageAllocs))];
|
|
881
|
-
if (page.notes !== void 0 && page.notes.length > 0) annots.push(buildNotesAnnotDict(page.notes));
|
|
882
|
-
annots.push(...widgetAnnotsByPage.get(pageIndex) ?? []);
|
|
883
|
-
const pageEntries = /* @__PURE__ */ new Map([
|
|
884
|
-
["Type", require_objects.pdfName("Page")],
|
|
885
|
-
["Parent", require_objects.pdfRef(pagesNum, 0)],
|
|
886
|
-
["MediaBox", require_objects.pdfArray([
|
|
887
|
-
0,
|
|
888
|
-
0,
|
|
889
|
-
page.widthPt,
|
|
890
|
-
page.heightPt
|
|
891
|
-
].map((n) => require_objects.pdfNum(n)))],
|
|
892
|
-
["Resources", resourcesDict],
|
|
893
|
-
["Contents", require_objects.pdfRef(contentsNum, 0)]
|
|
894
|
-
]);
|
|
895
|
-
if (annots.length > 0) pageEntries.set("Annots", require_objects.pdfArray(annots));
|
|
896
|
-
if (markedStructureByPage.has(pageIndex)) pageEntries.set("StructParents", require_objects.pdfNum(pageIndex));
|
|
897
|
-
objects.push({
|
|
898
|
-
num: pageNum,
|
|
899
|
-
value: require_objects.pdfDict(pageEntries)
|
|
900
|
-
});
|
|
389
|
+
registry,
|
|
390
|
+
fontAllocs,
|
|
391
|
+
embeddedAllocs,
|
|
392
|
+
imageAllocs,
|
|
393
|
+
layerNumByName,
|
|
394
|
+
formulas,
|
|
395
|
+
mathFontAlloc,
|
|
396
|
+
mathFont,
|
|
397
|
+
pageAllocs,
|
|
398
|
+
pagesNum,
|
|
399
|
+
resourcesDict,
|
|
400
|
+
widgetAnnotsByPage
|
|
901
401
|
});
|
|
902
402
|
if (structRootNum !== void 0 && structParentTreeNum !== void 0) {
|
|
903
403
|
const nums = [];
|
|
@@ -955,11 +455,11 @@ function writePdf(doc, options = {}) {
|
|
|
955
455
|
const xrefOffset = writer.length;
|
|
956
456
|
writer.writeAscii("xref\n");
|
|
957
457
|
writer.writeAscii(`0 ${maxObjNum + 1}\n`);
|
|
958
|
-
writer.writeAscii(xrefEntry(0, 65535, false));
|
|
458
|
+
writer.writeAscii(require_write_annotations.xrefEntry(0, 65535, false));
|
|
959
459
|
for (let num = 1; num <= maxObjNum; num++) {
|
|
960
460
|
const offset = offsets.get(num);
|
|
961
461
|
if (offset === void 0) throw new Error(`object ${num} was allocated but never written — this is a writePdf internal invariant violation`);
|
|
962
|
-
writer.writeAscii(xrefEntry(offset, 0, true));
|
|
462
|
+
writer.writeAscii(require_write_annotations.xrefEntry(offset, 0, true));
|
|
963
463
|
}
|
|
964
464
|
const trailerEntries = /* @__PURE__ */ new Map([
|
|
965
465
|
["Size", require_objects.pdfNum(maxObjNum + 1)],
|