modern-pdf-lib 0.25.0 → 0.28.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.
Files changed (110) hide show
  1. package/README.md +16 -3
  2. package/dist/{batchOptimize-Ba_pWw71.cjs → batchOptimize-CXC9gNqD.cjs} +55 -55
  3. package/dist/{batchOptimize-DtRwBOqR.mjs → batchOptimize-CjLGD5ie.mjs} +25 -25
  4. package/dist/{bridge-DYCQzxF7.cjs → bridge-ByvzPu5h.cjs} +29 -31
  5. package/dist/{bridge-CcivG_Sm.mjs → bridge-ZD6O6QQa.mjs} +4 -5
  6. package/dist/browser.cjs +263 -151
  7. package/dist/browser.d.cts +166 -166
  8. package/dist/browser.d.cts.map +1 -1
  9. package/dist/browser.d.mts +166 -166
  10. package/dist/browser.d.mts.map +1 -1
  11. package/dist/browser.mjs +15 -19
  12. package/dist/cli/index.cjs +7 -7
  13. package/dist/cli/index.mjs +8 -8
  14. package/dist/{compressionAnalysis-odbHC7Uk.mjs → compressionAnalysis-BgKy45pA.mjs} +60 -74
  15. package/dist/{compressionAnalysis-DGs-MqTe.d.mts → compressionAnalysis-CDOp_vPr.d.mts} +136 -136
  16. package/dist/compressionAnalysis-CDOp_vPr.d.mts.map +1 -0
  17. package/dist/{compressionAnalysis-B84FPXaQ.cjs → compressionAnalysis-Djv-Zvcd.cjs} +90 -104
  18. package/dist/{compressionAnalysis-VtYV9Zmq.d.cts → compressionAnalysis-UfmonqbM.d.cts} +136 -136
  19. package/dist/compressionAnalysis-UfmonqbM.d.cts.map +1 -0
  20. package/dist/create.cjs +21 -23
  21. package/dist/create.d.cts +2 -2
  22. package/dist/create.d.mts +2 -2
  23. package/dist/create.mjs +3 -5
  24. package/dist/{deduplicateImages-MfUDPxQz.mjs → deduplicateImages-BTCyAPfJ.mjs} +4 -5
  25. package/dist/{deduplicateImages-cKsnD6Ep.cjs → deduplicateImages-CaGgaqyS.cjs} +14 -15
  26. package/dist/{fieldAppearance-C8PoLFSc.d.mts → fieldAppearance-Df1262CT.d.cts} +44 -44
  27. package/dist/fieldAppearance-Df1262CT.d.cts.map +1 -0
  28. package/dist/{fieldAppearance-CdiGFG5e.d.cts → fieldAppearance-_CZdoUCD.d.mts} +44 -44
  29. package/dist/fieldAppearance-_CZdoUCD.d.mts.map +1 -0
  30. package/dist/fontEmbed-DGiZS0h2.d.cts +677 -0
  31. package/dist/fontEmbed-DGiZS0h2.d.cts.map +1 -0
  32. package/dist/fontEmbed-DtA_riGC.d.mts +677 -0
  33. package/dist/fontEmbed-DtA_riGC.d.mts.map +1 -0
  34. package/dist/forms.cjs +3 -4
  35. package/dist/forms.d.cts +2 -2
  36. package/dist/forms.d.mts +2 -2
  37. package/dist/forms.mjs +2 -3
  38. package/dist/{grayscaleDetect-C6kFF3dk.mjs → grayscaleDetect-6GJrgBRT.mjs} +3 -3
  39. package/dist/{grayscaleDetect-C2m-eEXR.cjs → grayscaleDetect-DAUqxjgR.cjs} +13 -14
  40. package/dist/{imageExtract-zEb1gnkb.cjs → imageExtract-DT50Hp_g.cjs} +13 -14
  41. package/dist/{imageExtract-Dnk_Ssv7.mjs → imageExtract-Dapir-ux.mjs} +3 -4
  42. package/dist/index-C1lZe66f.d.mts +8682 -0
  43. package/dist/index-C1lZe66f.d.mts.map +1 -0
  44. package/dist/index-D1SvXWSI.d.cts +8682 -0
  45. package/dist/index-D1SvXWSI.d.cts.map +1 -0
  46. package/dist/index.cjs +263 -150
  47. package/dist/index.d.cts +7 -7
  48. package/dist/index.d.mts +7 -7
  49. package/dist/index.mjs +14 -17
  50. package/dist/{layout-DH61a1iR.cjs → layout-C4vbTlBW.cjs} +184 -134
  51. package/dist/{layout-D6EUKSP8.mjs → layout-lO4x64kY.mjs} +50 -12
  52. package/dist/{loader-C7B5dVCI.mjs → loader-B1Ix7ozU.mjs} +259 -13
  53. package/dist/{loader-I4zdkoWc.cjs → loader-DR7H0XOf.cjs} +343 -67
  54. package/dist/parse.cjs +7 -8
  55. package/dist/parse.d.cts +3 -3
  56. package/dist/parse.d.mts +3 -3
  57. package/dist/parse.mjs +6 -7
  58. package/dist/pdfDocument-CH2E4UCc.d.mts +5160 -0
  59. package/dist/pdfDocument-CH2E4UCc.d.mts.map +1 -0
  60. package/dist/{pdfDocument-CEbbUP9i.cjs → pdfDocument-C_7mrBCL.cjs} +20493 -9511
  61. package/dist/pdfDocument-CzOipXnw.d.cts +5160 -0
  62. package/dist/pdfDocument-CzOipXnw.d.cts.map +1 -0
  63. package/dist/{pdfDocument-B0_XwS4X.mjs → pdfDocument-DRbT6HZw.mjs} +11017 -863
  64. package/dist/{pdfForm-9gd40uz9.cjs → pdfForm-BVS_do95.cjs} +113 -102
  65. package/dist/pdfForm-Ca86NDWn.d.cts +897 -0
  66. package/dist/pdfForm-Ca86NDWn.d.cts.map +1 -0
  67. package/dist/pdfForm-Ca86NDWn.d.mts +897 -0
  68. package/dist/pdfForm-Ca86NDWn.d.mts.map +1 -0
  69. package/dist/{pdfForm-Cn-cVicP.mjs → pdfForm-CfLnlsj-.mjs} +23 -18
  70. package/dist/{pdfObjects-1veop1_d.cjs → pdfObjects-BcPlSI0a.cjs} +62 -53
  71. package/dist/{pdfObjects-uEsWlfzU.mjs → pdfObjects-CB7TEdbW.mjs} +12 -2
  72. package/dist/rolldown-runtime-ak5kbic3.cjs +18 -0
  73. package/dist/{src-B1iDGLCL.cjs → src-C-IDXuvi.cjs} +9886 -1421
  74. package/dist/{src-Db6Qknoz.mjs → src-DJaD-bJ2.mjs} +8392 -515
  75. package/dist/{streamDecode-Bj568Nc9.mjs → streamDecode-BamENT3k.mjs} +129 -150
  76. package/dist/{streamDecode-CvgErkFu.cjs → streamDecode-DcaZz309.cjs} +139 -160
  77. package/package.json +26 -22
  78. package/dist/compressionAnalysis-DGs-MqTe.d.mts.map +0 -1
  79. package/dist/compressionAnalysis-VtYV9Zmq.d.cts.map +0 -1
  80. package/dist/fflateAdapter-LTAeAhaD.cjs +0 -207
  81. package/dist/fflateAdapter-PSiW_ML7.mjs +0 -196
  82. package/dist/fieldAppearance-C8PoLFSc.d.mts.map +0 -1
  83. package/dist/fieldAppearance-CdiGFG5e.d.cts.map +0 -1
  84. package/dist/fontEmbed-BN842wlb.d.cts +0 -659
  85. package/dist/fontEmbed-BN842wlb.d.cts.map +0 -1
  86. package/dist/fontEmbed-Dgq5K89o.d.mts +0 -659
  87. package/dist/fontEmbed-Dgq5K89o.d.mts.map +0 -1
  88. package/dist/fontSubset-5SLWMmEw.cjs +0 -518
  89. package/dist/fontSubset-D-vQQems.mjs +0 -495
  90. package/dist/index-DCSbmXWh.d.mts +0 -5939
  91. package/dist/index-DCSbmXWh.d.mts.map +0 -1
  92. package/dist/index-J1W3FdL8.d.cts +0 -5939
  93. package/dist/index-J1W3FdL8.d.cts.map +0 -1
  94. package/dist/libdeflateWasm-8b91Vmia.mjs +0 -220
  95. package/dist/libdeflateWasm-BdiDEJOj.cjs +0 -237
  96. package/dist/pdfCatalog-3yMIhJtt.mjs +0 -138
  97. package/dist/pdfCatalog-CYy4NXEY.cjs +0 -173
  98. package/dist/pdfDocument-BgvEP5Po.d.mts +0 -4673
  99. package/dist/pdfDocument-BgvEP5Po.d.mts.map +0 -1
  100. package/dist/pdfDocument-CbU-2TjT.d.cts +0 -4673
  101. package/dist/pdfDocument-CbU-2TjT.d.cts.map +0 -1
  102. package/dist/pdfForm-BiyNtYem.d.mts +0 -905
  103. package/dist/pdfForm-BiyNtYem.d.mts.map +0 -1
  104. package/dist/pdfForm-SOXJ72LW.d.cts +0 -905
  105. package/dist/pdfForm-SOXJ72LW.d.cts.map +0 -1
  106. package/dist/pdfPage-B_d9HmkG.mjs +0 -8015
  107. package/dist/pdfPage-Cd8jOJp6.cjs +0 -8728
  108. package/dist/pngEmbed-BWAbEUKF.mjs +0 -552
  109. package/dist/pngEmbed-D4X4ZN-3.cjs +0 -563
  110. package/dist/rolldown-runtime-CKhH4XqG.cjs +0 -24
@@ -0,0 +1,897 @@
1
+ //#region src/core/pdfObjects.d.ts
2
+ /**
3
+ * @module core/pdfObjects
4
+ *
5
+ * Low-level PDF object model. Every PDF value type has a class with a
6
+ * `serialize(writer)` method that appends valid PDF syntax to a
7
+ * {@link ByteWriter}. The module also provides `PdfObjectRegistry` for
8
+ * allocating indirect-object numbers.
9
+ *
10
+ * Reference: PDF 1.7 spec, §7.3 (Objects).
11
+ */
12
+ /**
13
+ * Minimal interface consumed by every `serialize()` method.
14
+ * Implementations may write to a growing `Uint8Array`, a `WritableStream`,
15
+ * etc.
16
+ */
17
+ interface ByteWriter {
18
+ /** Append raw bytes. */
19
+ write(data: Uint8Array): void;
20
+ /** Append an ASCII / Latin-1 string — callers guarantee all chars < 0x100. */
21
+ writeString(str: string): void;
22
+ }
23
+ /** The PDF `null` object. */
24
+ declare class PdfNull {
25
+ static readonly instance: PdfNull;
26
+ /** @internal */
27
+ readonly kind = "null";
28
+ private constructor();
29
+ /** Serialize as `null`. */
30
+ serialize(writer: ByteWriter): void;
31
+ }
32
+ /** A PDF boolean — `true` or `false`. */
33
+ declare class PdfBool {
34
+ readonly value: boolean;
35
+ static readonly TRUE: PdfBool;
36
+ static readonly FALSE: PdfBool;
37
+ /** @internal */
38
+ readonly kind = "bool";
39
+ private constructor();
40
+ static of(value: boolean): PdfBool;
41
+ serialize(writer: ByteWriter): void;
42
+ }
43
+ /** A PDF numeric object (integer or real). */
44
+ declare class PdfNumber {
45
+ readonly value: number;
46
+ /** @internal */
47
+ readonly kind = "number";
48
+ constructor(value: number);
49
+ static of(value: number): PdfNumber;
50
+ serialize(writer: ByteWriter): void;
51
+ }
52
+ /**
53
+ * A PDF string — either literal `(…)` or hexadecimal `<…>`.
54
+ *
55
+ * By default the constructor produces a literal string. Use the static
56
+ * helpers for explicit control.
57
+ */
58
+ declare class PdfString {
59
+ /** The raw string content (unescaped). */
60
+ readonly value: string;
61
+ /** When `true` the string is serialized in hexadecimal form `<…>`. */
62
+ readonly hex: boolean;
63
+ /** @internal */
64
+ readonly kind = "string";
65
+ private constructor();
66
+ /** Create a literal string `(…)`. */
67
+ static literal(value: string): PdfString;
68
+ /** Create a hexadecimal string `<…>` from a plain string. */
69
+ static hex(value: string): PdfString;
70
+ /** Create a hexadecimal string from raw bytes. */
71
+ static hexFromBytes(data: Uint8Array): PdfString;
72
+ serialize(writer: ByteWriter): void;
73
+ }
74
+ /**
75
+ * A PDF name object — e.g. `/Type`, `/Page`.
76
+ *
77
+ * The leading `/` is stored and serialized. Characters outside the
78
+ * printable ASCII range (33–126) and `#` are encoded as `#XX`.
79
+ */
80
+ declare class PdfName {
81
+ /** The name value *including* the leading `/`. */
82
+ readonly value: string;
83
+ /** @internal */
84
+ readonly kind = "name";
85
+ /** Cache for frequently used names. */
86
+ private static readonly cache;
87
+ private constructor();
88
+ /** Create or retrieve a cached `PdfName`. */
89
+ static of(name: string): PdfName;
90
+ serialize(writer: ByteWriter): void;
91
+ }
92
+ /** A PDF array `[…]`. */
93
+ declare class PdfArray {
94
+ readonly items: PdfObject[];
95
+ /** @internal */
96
+ readonly kind = "array";
97
+ constructor(items?: PdfObject[]);
98
+ static of(items: PdfObject[]): PdfArray;
99
+ /** Convenience: create an array of PdfNumbers. */
100
+ static fromNumbers(values: number[]): PdfArray;
101
+ /** Add an item. */
102
+ push(item: PdfObject): void;
103
+ /** Number of items. */
104
+ get length(): number;
105
+ serialize(writer: ByteWriter): void;
106
+ }
107
+ /** A PDF dictionary `<< … >>`. */
108
+ declare class PdfDict {
109
+ /** @internal */
110
+ readonly kind = "dict";
111
+ private readonly entries;
112
+ constructor(entries?: Iterable<readonly [string, PdfObject]>);
113
+ /**
114
+ * Set a key-value pair. Keys are always stored / looked up *with*
115
+ * the leading `/`.
116
+ */
117
+ set(key: string, value: PdfObject): this;
118
+ /** Get a value by key. */
119
+ get(key: string): PdfObject | undefined;
120
+ /** Check if a key exists. */
121
+ has(key: string): boolean;
122
+ /** Delete a key. */
123
+ delete(key: string): boolean;
124
+ /** Number of entries. */
125
+ get size(): number;
126
+ /** Iterate over entries as `[key, value]` pairs. */
127
+ [Symbol.iterator](): IterableIterator<[string, PdfObject]>;
128
+ serialize(writer: ByteWriter): void;
129
+ }
130
+ /**
131
+ * A PDF stream object — a dictionary followed by `stream … endstream`.
132
+ *
133
+ * The `data` field holds the (possibly compressed) payload. The caller
134
+ * is responsible for setting `/Length` in the dict before serialization.
135
+ */
136
+ declare class PdfStream {
137
+ /** Stream metadata dictionary. */
138
+ readonly dict: PdfDict;
139
+ /** Raw stream data (already encoded / compressed). */
140
+ data: Uint8Array;
141
+ /** @internal */
142
+ readonly kind = "stream";
143
+ constructor(dict: PdfDict, data: Uint8Array);
144
+ /**
145
+ * Create a stream from a plain UTF-8 string (e.g. content-stream
146
+ * operators). Sets `/Length` automatically.
147
+ */
148
+ static fromString(content: string, extraEntries?: PdfDict): PdfStream;
149
+ /**
150
+ * Create a stream from raw bytes. Sets `/Length` automatically.
151
+ */
152
+ static fromBytes(data: Uint8Array, extraEntries?: PdfDict): PdfStream;
153
+ /** Update `/Length` to reflect the current data size. */
154
+ syncLength(): void;
155
+ serialize(writer: ByteWriter): void;
156
+ }
157
+ /** An indirect reference `N G R`. */
158
+ declare class PdfRef {
159
+ /** Object number (≥ 1). */
160
+ readonly objectNumber: number;
161
+ /** Generation number (usually 0). */
162
+ readonly generationNumber: number;
163
+ /** @internal */
164
+ readonly kind = "ref";
165
+ constructor(objectNumber: number, generationNumber?: number);
166
+ static of(objectNumber: number, generationNumber?: number): PdfRef;
167
+ /** The string form used inside PDF bodies: `N G R`. */
168
+ serialize(writer: ByteWriter): void;
169
+ /** Return the `N G obj` header for an indirect-object definition. */
170
+ toObjectHeader(): string;
171
+ /** Return `endobj`. */
172
+ toObjectFooter(): string;
173
+ toString(): string;
174
+ }
175
+ /**
176
+ * Union of all PDF object types. Every member has a `serialize()` method
177
+ * and a discriminating `kind` literal.
178
+ */
179
+ type PdfObject = PdfNull | PdfBool | PdfNumber | PdfString | PdfName | PdfArray | PdfDict | PdfStream | PdfRef;
180
+ /** Entry stored in the registry. */
181
+ interface RegistryEntry {
182
+ /** Indirect reference (object number + generation). */
183
+ readonly ref: PdfRef;
184
+ /** The object itself. */
185
+ object: PdfObject;
186
+ }
187
+ /**
188
+ * Allocates monotonically increasing object numbers and stores the
189
+ * mapping from `PdfRef` → object value.
190
+ */
191
+ declare class PdfObjectRegistry {
192
+ private nextObjectNumber;
193
+ private readonly entries;
194
+ private readonly refMap;
195
+ /**
196
+ * Register a new object, allocate an object number, and return its
197
+ * indirect reference.
198
+ */
199
+ register(object: PdfObject): PdfRef;
200
+ /**
201
+ * Register a pre-built `PdfRef` with an object.
202
+ * Useful when the ref must be known before the object is fully built
203
+ * (e.g. the catalog references the page tree, and vice-versa).
204
+ */
205
+ registerWithRef(ref: PdfRef, object: PdfObject): void;
206
+ /**
207
+ * Pre-allocate an object number and return the reference.
208
+ * Call {@link assign} later to attach the actual object.
209
+ */
210
+ allocate(): PdfRef;
211
+ /**
212
+ * Assign an object to a previously allocated (or registered) reference.
213
+ */
214
+ assign(ref: PdfRef, object: PdfObject): void;
215
+ /** Look up the object for a given reference. */
216
+ resolve(ref: PdfRef): PdfObject | undefined;
217
+ /** Iterate all entries in allocation order. */
218
+ [Symbol.iterator](): IterableIterator<RegistryEntry>;
219
+ /** Total number of registered objects (≥ 1 in a valid PDF because of
220
+ * the free entry at object 0). */
221
+ get size(): number;
222
+ /** The next object number that *would* be assigned. */
223
+ get nextNumber(): number;
224
+ /**
225
+ * Remove all registry entries that are not reachable from the given
226
+ * root references. This is used after rebuilding the document
227
+ * structure so that orphaned objects from the original (loaded) PDF
228
+ * don't bloat the output.
229
+ *
230
+ * The walk follows every `PdfRef` found inside `PdfDict`, `PdfArray`,
231
+ * and `PdfStream` objects, handling cycles via a visited set.
232
+ */
233
+ filterReachable(rootRefs: PdfRef[]): void;
234
+ }
235
+ //#endregion
236
+ //#region src/form/pdfField.d.ts
237
+ /**
238
+ * Minimal interface for a PDF page that can receive widget annotations.
239
+ * Used by {@link PdfField.addToPage} to avoid importing PdfPage directly.
240
+ */
241
+ interface WidgetAnnotationHost {
242
+ /** Add a raw widget annotation dictionary to this page. */
243
+ addWidgetAnnotation(widgetDict: PdfDict): void;
244
+ }
245
+ /** Discriminated union tag for PDF form field types. */
246
+ type FieldType = "text" | "checkbox" | "radio" | "dropdown" | "listbox" | "button" | "signature";
247
+ /** Common field flags (/Ff) — bit positions (0-indexed). */
248
+ declare const FieldFlags: {
249
+ readonly ReadOnly: number;
250
+ readonly Required: number;
251
+ readonly NoExport: number;
252
+ readonly Multiline: number;
253
+ readonly Password: number;
254
+ readonly DoNotScroll: number;
255
+ readonly RichText: number;
256
+ readonly NoToggleToOff: number;
257
+ readonly Radio: number;
258
+ readonly Pushbutton: number;
259
+ readonly RadiosInUnison: number;
260
+ readonly Combo: number;
261
+ readonly Edit: number;
262
+ readonly Sort: number;
263
+ readonly MultiSelect: number;
264
+ };
265
+ /**
266
+ * Abstract base class for all AcroForm field types.
267
+ *
268
+ * Each field holds a reference to the underlying field dictionary
269
+ * (which may be a merged field+widget dictionary in simple forms)
270
+ * and an optional separate widget annotation dictionary.
271
+ */
272
+ declare abstract class PdfField {
273
+ /** Discriminator for the concrete field type. */
274
+ abstract readonly fieldType: FieldType;
275
+ /** The fully-qualified field name. */
276
+ readonly name: string;
277
+ /**
278
+ * The underlying field dictionary (may contain both field and widget
279
+ * entries for simple one-widget fields).
280
+ */
281
+ protected readonly dict: PdfDict;
282
+ /**
283
+ * The widget annotation dictionary. For merged field+widget dicts,
284
+ * this is the same object as `dict`.
285
+ */
286
+ protected readonly widgetDict: PdfDict;
287
+ /** Parent field dictionary chain for building full names. */
288
+ protected readonly parentNames: string[];
289
+ constructor(name: string, dict: PdfDict, widgetDict: PdfDict, parentNames?: string[]);
290
+ /** Get the partial field name (/T entry). */
291
+ getName(): string;
292
+ /**
293
+ * Get the fully qualified field name (Parent.Child.Name format).
294
+ * Per PDF spec SS12.7.3.2, the full name is formed by concatenating
295
+ * ancestor /T values with periods.
296
+ */
297
+ getFullName(): string;
298
+ /** Return the underlying field dictionary (for internal use by PdfForm). */
299
+ getDict(): PdfDict;
300
+ /** Get the raw /Ff (field flags) integer value. */
301
+ protected getFieldFlags(): number;
302
+ /** Set the raw /Ff (field flags) integer value. */
303
+ protected setFieldFlags(flags: number): void;
304
+ /** Check if a specific flag bit is set. */
305
+ protected hasFlag(flag: number): boolean;
306
+ /** Set or clear a specific flag bit. */
307
+ protected setFlag(flag: number, on: boolean): void;
308
+ /** Whether the field is read-only. */
309
+ isReadOnly(): boolean;
310
+ /** Set the read-only flag. */
311
+ setReadOnly(readOnly: boolean): void;
312
+ /** Whether the field is required. */
313
+ isRequired(): boolean;
314
+ /** Set the required flag. */
315
+ setRequired(required: boolean): void;
316
+ /** Whether the field should not be exported. */
317
+ isNoExport(): boolean;
318
+ /** Whether the field is exported (inverse of NoExport flag). */
319
+ isExported(): boolean;
320
+ /** Enable exporting this field (clear the NoExport flag). */
321
+ enableExporting(): void;
322
+ /** Disable exporting this field (set the NoExport flag). */
323
+ disableExporting(): void;
324
+ /**
325
+ * Get the field's widget rectangle as `[x1, y1, x2, y2]`.
326
+ * The /Rect entry comes from the widget annotation dictionary.
327
+ */
328
+ getRect(): [number, number, number, number];
329
+ /**
330
+ * Add this field's widget annotation to a page.
331
+ *
332
+ * Ensures the widget dict has `/Type /Annot` and `/Subtype /Widget`,
333
+ * then adds it to the page's annotation list so it appears in the
334
+ * rendered PDF.
335
+ *
336
+ * @param page A page that implements {@link WidgetAnnotationHost}.
337
+ */
338
+ addToPage(page: WidgetAnnotationHost): void;
339
+ /**
340
+ * Get the underlying widget annotation dictionary.
341
+ * @internal
342
+ */
343
+ getWidgetDict(): PdfDict;
344
+ /** Get the current value of this field. */
345
+ abstract getValue(): string | boolean | string[];
346
+ /** Set the value of this field. */
347
+ abstract setValue(value: string | boolean | string[]): void;
348
+ /**
349
+ * Generate the /AP (appearance) stream for this field's current value.
350
+ * Returns a PdfStream suitable for the /N (normal) appearance.
351
+ */
352
+ abstract generateAppearance(): PdfStream;
353
+ }
354
+ //#endregion
355
+ //#region src/form/fields/textField.d.ts
356
+ /**
357
+ * A PDF text form field (/FT /Tx).
358
+ *
359
+ * Stores a string value and supports properties like alignment,
360
+ * multiline mode, password masking, and maximum length.
361
+ */
362
+ declare class PdfTextField extends PdfField {
363
+ readonly fieldType: FieldType;
364
+ /** Get the text value of this field. */
365
+ getText(): string;
366
+ /**
367
+ * Set the text value of this field.
368
+ * Also updates /V and removes /AP to force regeneration.
369
+ */
370
+ setText(value: string): void;
371
+ /** Alias for getText(). */
372
+ getValue(): string;
373
+ /** Alias for setText(). */
374
+ setValue(value: string | boolean | string[]): void;
375
+ /**
376
+ * Get the font size from the /DA (default appearance) string.
377
+ * Returns 0 if the font size is not specified or is auto.
378
+ */
379
+ getFontSize(): number;
380
+ /**
381
+ * Set the font size in the /DA string.
382
+ * Creates or updates the /DA entry.
383
+ */
384
+ setFontSize(size: number): void;
385
+ /**
386
+ * Get the font name from the /DA string.
387
+ * Returns "Helv" (Helvetica) as default.
388
+ */
389
+ getFontName(): string;
390
+ /**
391
+ * Get the text alignment.
392
+ * /Q: 0 = left, 1 = center, 2 = right.
393
+ */
394
+ getAlignment(): "left" | "center" | "right";
395
+ /** Set the text alignment. */
396
+ setAlignment(align: "left" | "center" | "right"): void;
397
+ /** Whether this is a multiline text field. */
398
+ isMultiline(): boolean;
399
+ /** Set the multiline flag. */
400
+ setMultiline(multiline: boolean): void;
401
+ /** Whether this is a password field. */
402
+ isPassword(): boolean;
403
+ /** Get the maximum length, or undefined if no limit. */
404
+ getMaxLength(): number | undefined;
405
+ /** Set the maximum length. */
406
+ setMaxLength(maxLength: number): void;
407
+ /**
408
+ * Set an image on this text field.
409
+ *
410
+ * Creates an appearance stream that paints the image XObject scaled
411
+ * to fit the widget rectangle. This replaces the text appearance.
412
+ *
413
+ * @param imageRef An object with `name` (resource name) and `ref` (PdfRef)
414
+ * pointing to the image XObject, plus `width` and `height`.
415
+ */
416
+ setImage(imageRef: {
417
+ name: string;
418
+ ref: PdfRef;
419
+ width: number;
420
+ height: number;
421
+ }): void;
422
+ /** Generate the appearance stream for this text field. */
423
+ generateAppearance(): PdfStream;
424
+ }
425
+ //#endregion
426
+ //#region src/form/fields/checkboxField.d.ts
427
+ /**
428
+ * A PDF checkbox form field (/FT /Btn).
429
+ *
430
+ * The value is either the "on" name (typically "Yes") or "/Off".
431
+ * The /AS (appearance state) entry controls which appearance is shown.
432
+ */
433
+ declare class PdfCheckboxField extends PdfField {
434
+ readonly fieldType: FieldType;
435
+ /**
436
+ * Check whether the checkbox is currently checked.
437
+ *
438
+ * The checkbox is checked when /V or /AS is not "/Off".
439
+ */
440
+ isChecked(): boolean;
441
+ /** Check the checkbox (set to the "on" value). */
442
+ check(): void;
443
+ /** Uncheck the checkbox (set to /Off). */
444
+ uncheck(): void;
445
+ /** Toggle the checkbox. */
446
+ toggle(): void;
447
+ /**
448
+ * Get the "on" value name for this checkbox.
449
+ *
450
+ * Examines the /AP /N dictionary for a key that is not "/Off".
451
+ * Falls back to "Yes" if no appearance dictionary is found.
452
+ */
453
+ getOnValue(): string;
454
+ /** Get the value: "Yes"/"Off" as boolean for convenience. */
455
+ getValue(): boolean;
456
+ /** Set the value as boolean. */
457
+ setValue(value: string | boolean | string[]): void;
458
+ /** Generate the appearance stream for this checkbox. */
459
+ generateAppearance(): PdfStream;
460
+ }
461
+ //#endregion
462
+ //#region src/form/fields/radioGroup.d.ts
463
+ /**
464
+ * A PDF radio button group (/FT /Btn with Radio flag).
465
+ *
466
+ * Multiple widget annotations represent the individual options.
467
+ * The field's /V value is the name of the selected option.
468
+ */
469
+ declare class PdfRadioGroup extends PdfField {
470
+ readonly fieldType: FieldType;
471
+ /** The individual widget annotation dictionaries. */
472
+ private readonly widgets;
473
+ constructor(name: string, dict: PdfDict, widgetDict: PdfDict, parentNames?: string[], widgets?: PdfDict[]);
474
+ /**
475
+ * Add all radio button widgets to a page.
476
+ *
477
+ * Unlike other field types that have a single widget, a radio group
478
+ * has multiple widget annotations (one per option). This override
479
+ * adds all of them.
480
+ */
481
+ override addToPage(page: WidgetAnnotationHost): void;
482
+ /**
483
+ * Get the currently selected option name.
484
+ * Returns undefined if no option is selected.
485
+ */
486
+ getSelected(): string | undefined;
487
+ /**
488
+ * Select an option by its name.
489
+ *
490
+ * Sets /V on the field and updates /AS on each widget to
491
+ * show the correct appearance state.
492
+ */
493
+ select(optionName: string): void;
494
+ /**
495
+ * Get the list of option names available in this radio group.
496
+ * Derived from the /AP /N dictionaries of each widget.
497
+ */
498
+ getOptions(): string[];
499
+ /** Get the widget annotation dictionaries. */
500
+ getWidgets(): PdfDict[];
501
+ /** Get the value: the selected option name or undefined. */
502
+ getValue(): string;
503
+ /** Set the value: select the named option. */
504
+ setValue(value: string | boolean | string[]): void;
505
+ /**
506
+ * Get the option name for a widget annotation.
507
+ * Looks in the /AP /N dictionary for a key that is not "Off".
508
+ */
509
+ private getWidgetOptionName;
510
+ /**
511
+ * Generate the appearance stream for the first widget.
512
+ * For full appearance generation, use generateAppearanceForWidget().
513
+ */
514
+ generateAppearance(): PdfStream;
515
+ }
516
+ //#endregion
517
+ //#region src/form/fields/dropdownField.d.ts
518
+ /**
519
+ * A PDF dropdown (combo box) field (/FT /Ch with Combo flag).
520
+ *
521
+ * Options are stored in the /Opt array. The selected value is in /V.
522
+ * Optionally editable (bit 18 of /Ff).
523
+ */
524
+ declare class PdfDropdownField extends PdfField {
525
+ readonly fieldType: FieldType;
526
+ /** Get the currently selected value. */
527
+ getSelected(): string;
528
+ /** Select a value from the options. */
529
+ select(value: string): void;
530
+ /** Alias for getSelected(). */
531
+ getValue(): string;
532
+ /** Alias for select(). */
533
+ setValue(value: string | boolean | string[]): void;
534
+ /**
535
+ * Get the list of options.
536
+ *
537
+ * /Opt may be an array of strings, or an array of two-element arrays
538
+ * where element [0] is the export value and element [1] is the display
539
+ * value. We return the display values (or export values if no display).
540
+ */
541
+ getOptions(): string[];
542
+ /** Set the list of options. */
543
+ setOptions(options: string[]): void;
544
+ /** Whether the dropdown allows manual text entry. */
545
+ isEditable(): boolean;
546
+ /** Set whether the dropdown allows manual text entry. */
547
+ setEditable(editable: boolean): void;
548
+ /** Generate the appearance stream for this dropdown. */
549
+ generateAppearance(): PdfStream;
550
+ }
551
+ //#endregion
552
+ //#region src/form/fields/listboxField.d.ts
553
+ /**
554
+ * A PDF listbox field (/FT /Ch without Combo flag).
555
+ *
556
+ * Displays a scrollable list of options. May allow multi-select.
557
+ * The /V entry holds the selected value(s).
558
+ */
559
+ declare class PdfListboxField extends PdfField {
560
+ readonly fieldType: FieldType;
561
+ /**
562
+ * Get the currently selected value(s).
563
+ *
564
+ * Returns an array of strings (may contain one element for
565
+ * single-select listboxes).
566
+ */
567
+ getSelected(): string[];
568
+ /** Select one or more values. */
569
+ select(values: string[]): void;
570
+ /** Get value as string array. */
571
+ getValue(): string[];
572
+ /** Set value from string array. */
573
+ setValue(value: string | boolean | string[]): void;
574
+ /** Get the list of options. */
575
+ getOptions(): string[];
576
+ /** Set the list of options. */
577
+ setOptions(options: string[]): void;
578
+ /** Generate the appearance stream for this listbox. */
579
+ generateAppearance(): PdfStream;
580
+ }
581
+ //#endregion
582
+ //#region src/form/fields/buttonField.d.ts
583
+ /**
584
+ * A PDF pushbutton field (/FT /Btn with Pushbutton flag).
585
+ *
586
+ * Pushbuttons have no permanent value. They may have an associated
587
+ * action (e.g. JavaScript, submit form, reset form) and display a
588
+ * caption via the /MK dictionary.
589
+ */
590
+ declare class PdfButtonField extends PdfField {
591
+ readonly fieldType: FieldType;
592
+ /**
593
+ * Get the button caption from the /MK dictionary.
594
+ * Returns undefined if no caption is set.
595
+ */
596
+ getCaption(): string | undefined;
597
+ /**
598
+ * Set the button caption in the /MK dictionary.
599
+ * Creates the /MK dictionary if it does not exist.
600
+ */
601
+ setCaption(caption: string): void;
602
+ /**
603
+ * Set an image on this button field.
604
+ *
605
+ * Creates an appearance stream that paints the image XObject scaled
606
+ * to fit the widget rectangle.
607
+ *
608
+ * @param imageRef An object with `name` (resource name) and `ref` (PdfRef)
609
+ * pointing to the image XObject, plus `width` and `height`.
610
+ */
611
+ setImage(imageRef: {
612
+ name: string;
613
+ ref: PdfRef;
614
+ width: number;
615
+ height: number;
616
+ }): void;
617
+ /** Pushbuttons have no value; returns empty string. */
618
+ getValue(): string;
619
+ /** Pushbuttons have no value; no-op. */
620
+ setValue(_value: string | boolean | string[]): void;
621
+ /** Generate the appearance stream for this button. */
622
+ generateAppearance(): PdfStream;
623
+ }
624
+ //#endregion
625
+ //#region src/form/fields/signatureField.d.ts
626
+ /**
627
+ * A PDF signature form field (/FT /Sig).
628
+ *
629
+ * The /V entry is a signature dictionary containing the cryptographic
630
+ * signature data. This class provides read access to check whether the
631
+ * field is signed, but does not implement signing (see Phase 6).
632
+ */
633
+ declare class PdfSignatureField extends PdfField {
634
+ readonly fieldType: FieldType;
635
+ /**
636
+ * Whether this signature field has been signed.
637
+ * A signed field has a /V entry that is a dictionary.
638
+ */
639
+ isSigned(): boolean;
640
+ /**
641
+ * Get the signature dictionary, if signed.
642
+ * Returns undefined if the field has not been signed.
643
+ */
644
+ getSignatureValue(): PdfDict | undefined;
645
+ /** Get value: returns "signed" or "unsigned". */
646
+ getValue(): string;
647
+ /** Signature fields cannot be set via setValue. */
648
+ setValue(_value: string | boolean | string[]): void;
649
+ /** Generate the appearance stream for this signature field. */
650
+ generateAppearance(): PdfStream;
651
+ }
652
+ //#endregion
653
+ //#region src/form/pdfForm.d.ts
654
+ /**
655
+ * Function that resolves a PdfRef to its underlying PdfObject.
656
+ * Used when traversing the field tree from parsed PDF data.
657
+ */
658
+ type RefResolver = (ref: PdfRef) => PdfObject;
659
+ /**
660
+ * Represents a PDF document's interactive form (AcroForm).
661
+ *
662
+ * Provides access to all form fields, bulk fill, and flatten operations.
663
+ */
664
+ declare class PdfForm {
665
+ /** All fields in the form (flat list). */
666
+ private readonly fields;
667
+ /** The underlying /AcroForm dictionary. */
668
+ private readonly acroFormDict;
669
+ /** Map from field name to field for fast lookup. */
670
+ private readonly fieldsByName;
671
+ constructor(fields: PdfField[], acroFormDict: PdfDict);
672
+ /**
673
+ * Build a PdfForm from a parsed /AcroForm dictionary.
674
+ *
675
+ * Traverses the /Fields array and resolves indirect references to
676
+ * construct the field tree, then flattens it into a list of concrete
677
+ * field instances.
678
+ *
679
+ * @param acroFormDict The /AcroForm dictionary from the document catalog.
680
+ * @param resolver Function to resolve PdfRef to PdfObject.
681
+ */
682
+ static fromDict(acroFormDict: PdfDict, resolver: RefResolver): PdfForm;
683
+ /**
684
+ * Recursively traverse the field tree rooted at `dict`.
685
+ *
686
+ * The AcroForm field tree uses /Kids for both child fields and
687
+ * widget annotations. A node is a field if it has /FT; it is a
688
+ * widget annotation if it has /Subtype /Widget.
689
+ */
690
+ private static traverseFieldTree;
691
+ /** Get all fields in the form. */
692
+ getFields(): PdfField[];
693
+ /**
694
+ * Get a field by name (partial or fully-qualified).
695
+ * Returns undefined if not found.
696
+ */
697
+ getField(name: string): PdfField | undefined;
698
+ /**
699
+ * Get a text field by name.
700
+ * Throws if the field is not found or is not a text field.
701
+ */
702
+ getTextField(name: string): PdfTextField;
703
+ /**
704
+ * Get a checkbox field by name.
705
+ * Throws if the field is not found or is not a checkbox.
706
+ */
707
+ getCheckbox(name: string): PdfCheckboxField;
708
+ /**
709
+ * Get a radio group by name.
710
+ * Throws if the field is not found or is not a radio group.
711
+ */
712
+ getRadioGroup(name: string): PdfRadioGroup;
713
+ /**
714
+ * Get a dropdown field by name.
715
+ * Throws if the field is not found or is not a dropdown.
716
+ */
717
+ getDropdown(name: string): PdfDropdownField;
718
+ /**
719
+ * Get a listbox field by name.
720
+ * Throws if the field is not found or is not a listbox.
721
+ */
722
+ getListbox(name: string): PdfListboxField;
723
+ /**
724
+ * Get a button field by name.
725
+ * Throws if the field is not found or is not a button.
726
+ */
727
+ getButton(name: string): PdfButtonField;
728
+ /**
729
+ * Get a signature field by name.
730
+ * Throws if the field is not found or is not a signature field.
731
+ */
732
+ getSignatureField(name: string): PdfSignatureField;
733
+ /**
734
+ * Fill multiple fields at once.
735
+ *
736
+ * Accepts a record where keys are field names and values are the
737
+ * field values to set. Strings map to text/dropdown/listbox values;
738
+ * booleans map to checkbox checked states.
739
+ *
740
+ * @param values A mapping of field name to value.
741
+ * @throws If a field name is not found.
742
+ */
743
+ fill(values: Record<string, string | boolean>): void;
744
+ /**
745
+ * Flatten the form: burn field values into the page content streams
746
+ * and remove the interactive form structure.
747
+ *
748
+ * After flattening, the document is no longer interactive — field
749
+ * values become static page content. This is done by:
750
+ *
751
+ * 1. Generating appearance streams for all fields that lack them
752
+ * 2. Removing the /AcroForm entry from the catalog
753
+ * 3. Removing /Widget annotations from page /Annots arrays
754
+ *
755
+ * Note: In this implementation, we mark the form as flattened by
756
+ * setting a flag and clearing the /Fields array. The appearance
757
+ * streams remain as page annotations will reference them.
758
+ */
759
+ flatten(): void;
760
+ /**
761
+ * Check whether the AcroForm dictionary contains XFA data.
762
+ *
763
+ * XFA (XML Forms Architecture) data causes PDF viewers to use the
764
+ * XFA renderer instead of the standard AcroForm renderer. Use
765
+ * {@link deleteXFA} to remove it.
766
+ *
767
+ * @returns `true` if the form has an /XFA entry.
768
+ */
769
+ hasXFA(): boolean;
770
+ /**
771
+ * Remove the /XFA entry from the AcroForm dictionary, if present.
772
+ *
773
+ * XFA (XML Forms Architecture) data can cause PDF viewers to use the
774
+ * XFA renderer instead of the standard AcroForm renderer, which is
775
+ * often undesirable. Removing /XFA forces viewers to fall back to
776
+ * the AcroForm fields.
777
+ *
778
+ * After removing /XFA, `/NeedAppearances` is set to `true` so that
779
+ * the viewer knows it must generate appearances for the AcroForm
780
+ * fields (since XFA appearances are no longer available).
781
+ *
782
+ * This method is a no-op if the AcroForm dictionary does not contain
783
+ * an /XFA entry.
784
+ */
785
+ deleteXFA(): void;
786
+ /**
787
+ * Create a new text field and add it to the form.
788
+ *
789
+ * @param name Field name.
790
+ * @param page Page index (zero-based) where the widget appears.
791
+ * @param rect Widget rectangle [x1, y1, x2, y2].
792
+ * @returns The newly created text field.
793
+ */
794
+ createTextField(name: string, page: number, rect: [number, number, number, number]): PdfTextField;
795
+ /**
796
+ * Create a new checkbox and add it to the form.
797
+ *
798
+ * @param name Field name.
799
+ * @param page Page index (zero-based).
800
+ * @param rect Widget rectangle [x1, y1, x2, y2].
801
+ * @returns The newly created checkbox field.
802
+ */
803
+ createCheckbox(name: string, page: number, rect: [number, number, number, number]): PdfCheckboxField;
804
+ /**
805
+ * Create a new dropdown and add it to the form.
806
+ *
807
+ * @param name Field name.
808
+ * @param page Page index (zero-based).
809
+ * @param rect Widget rectangle [x1, y1, x2, y2].
810
+ * @param options The list of option strings.
811
+ * @returns The newly created dropdown field.
812
+ */
813
+ createDropdown(name: string, page: number, rect: [number, number, number, number], options: string[]): PdfDropdownField;
814
+ /**
815
+ * Create a new radio button group and add it to the form.
816
+ *
817
+ * A radio group is a single field with multiple widget annotations,
818
+ * one per rectangle in `rects`. Each widget corresponds to an
819
+ * option; if `options` is supplied the n-th option labels the n-th
820
+ * widget, otherwise options default to `"Option0"`, `"Option1"`, etc.
821
+ *
822
+ * @param name Field name.
823
+ * @param page The PdfPage where the widgets appear (unused for
824
+ * positioning in the low-level dict, but reserved
825
+ * for future page-level annotation linking).
826
+ * @param rects Array of widget rectangles `{x, y, width, height}`.
827
+ * @param options Optional option labels (one per rect).
828
+ * @returns The newly created radio group.
829
+ */
830
+ createRadioGroup(name: string, page: unknown, rects: Array<{
831
+ x: number;
832
+ y: number;
833
+ width: number;
834
+ height: number;
835
+ }>, options?: string[]): PdfRadioGroup;
836
+ /**
837
+ * Create a new push button and add it to the form.
838
+ *
839
+ * @param name Field name.
840
+ * @param page The PdfPage where the widget appears.
841
+ * @param rect Widget rectangle `{x, y, width, height}`.
842
+ * @param label Optional button caption.
843
+ * @returns The newly created button field.
844
+ */
845
+ createButton(name: string, page: unknown, rect: {
846
+ x: number;
847
+ y: number;
848
+ width: number;
849
+ height: number;
850
+ }, label?: string): PdfButtonField;
851
+ /**
852
+ * Create a new listbox and add it to the form.
853
+ *
854
+ * A listbox is a choice field (/FT /Ch) without the Combo flag,
855
+ * displaying a scrollable list of options.
856
+ *
857
+ * @param name Field name.
858
+ * @param page The PdfPage where the widget appears.
859
+ * @param rect Widget rectangle `{x, y, width, height}`.
860
+ * @param options The list of option strings.
861
+ * @returns The newly created listbox field.
862
+ */
863
+ createListbox(name: string, page: unknown, rect: {
864
+ x: number;
865
+ y: number;
866
+ width: number;
867
+ height: number;
868
+ }, options: string[]): PdfListboxField;
869
+ /**
870
+ * Remove a field from the form by name.
871
+ *
872
+ * Removes the field from the internal field list, the name index,
873
+ * and the /Fields array in the AcroForm dictionary.
874
+ *
875
+ * @param name The field name (partial or fully-qualified).
876
+ * @throws If no field with the given name exists.
877
+ */
878
+ removeField(name: string): void;
879
+ /**
880
+ * Serialize the form back to a PdfDict.
881
+ *
882
+ * Updates /NeedAppearances if appearances need to be generated
883
+ * by the viewer.
884
+ */
885
+ toDict(_registry: PdfObjectRegistry): PdfDict;
886
+ /**
887
+ * Create a basic field dictionary with common entries.
888
+ */
889
+ private createFieldDict;
890
+ /**
891
+ * Add a field dictionary to the /Fields array in the AcroForm.
892
+ */
893
+ private addFieldToAcroForm;
894
+ }
895
+ //#endregion
896
+ export { PdfRef as C, RegistryEntry as E, PdfObjectRegistry as S, PdfString as T, PdfDict as _, PdfListboxField as a, PdfNumber as b, PdfCheckboxField as c, FieldType as d, PdfField as f, PdfBool as g, PdfArray as h, PdfButtonField as i, PdfTextField as l, ByteWriter as m, RefResolver as n, PdfDropdownField as o, WidgetAnnotationHost as p, PdfSignatureField as r, PdfRadioGroup as s, PdfForm as t, FieldFlags as u, PdfName as v, PdfStream as w, PdfObject as x, PdfNull as y };
897
+ //# sourceMappingURL=pdfForm-Ca86NDWn.d.mts.map