pdf-lite 1.3.3 → 1.4.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 (100) hide show
  1. package/dist/acroform/PdfAcroForm.d.ts +63 -0
  2. package/dist/acroform/PdfAcroForm.js +279 -0
  3. package/dist/acroform/PdfFontEncodingCache.d.ts +16 -0
  4. package/dist/acroform/PdfFontEncodingCache.js +75 -0
  5. package/dist/acroform/acroform.d.ts +7 -454
  6. package/dist/acroform/acroform.js +5 -1664
  7. package/dist/acroform/appearance/PdfAppearanceStream.d.ts +15 -0
  8. package/dist/acroform/appearance/PdfAppearanceStream.js +32 -0
  9. package/dist/acroform/appearance/PdfButtonAppearanceStream.d.ts +12 -0
  10. package/dist/acroform/appearance/PdfButtonAppearanceStream.js +54 -0
  11. package/dist/acroform/appearance/PdfChoiceAppearanceStream.d.ts +15 -0
  12. package/dist/acroform/appearance/PdfChoiceAppearanceStream.js +48 -0
  13. package/dist/acroform/appearance/PdfTextAppearanceStream.d.ts +17 -0
  14. package/dist/acroform/appearance/PdfTextAppearanceStream.js +75 -0
  15. package/dist/acroform/appearance/index.d.ts +4 -0
  16. package/dist/acroform/appearance/index.js +4 -0
  17. package/dist/acroform/fields/PdfButtonFormField.d.ts +9 -0
  18. package/dist/acroform/fields/PdfButtonFormField.js +35 -0
  19. package/dist/acroform/fields/PdfChoiceFormField.d.ts +9 -0
  20. package/dist/acroform/fields/PdfChoiceFormField.js +46 -0
  21. package/dist/acroform/fields/PdfDefaultAppearance.d.ts +23 -0
  22. package/dist/acroform/fields/PdfDefaultAppearance.js +68 -0
  23. package/dist/acroform/fields/PdfFormField.d.ts +119 -0
  24. package/dist/acroform/fields/PdfFormField.js +499 -0
  25. package/dist/acroform/fields/PdfFormFieldFlags.d.ts +46 -0
  26. package/dist/acroform/fields/PdfFormFieldFlags.js +128 -0
  27. package/dist/acroform/fields/PdfSignatureFormField.d.ts +7 -0
  28. package/dist/acroform/fields/PdfSignatureFormField.js +12 -0
  29. package/dist/acroform/fields/PdfTextFormField.d.ts +10 -0
  30. package/dist/acroform/fields/PdfTextFormField.js +52 -0
  31. package/dist/acroform/fields/index.d.ts +8 -0
  32. package/dist/acroform/fields/index.js +8 -0
  33. package/dist/acroform/fields/types.d.ts +21 -0
  34. package/dist/acroform/fields/types.js +9 -0
  35. package/dist/acroform/index.d.ts +5 -1
  36. package/dist/acroform/index.js +5 -1
  37. package/dist/acroform/manager.d.ts +7 -0
  38. package/dist/acroform/manager.js +12 -0
  39. package/dist/acroform/xfa/PdfXfaData.d.ts +20 -0
  40. package/dist/acroform/xfa/PdfXfaData.js +68 -0
  41. package/dist/acroform/xfa/PdfXfaForm.d.ts +12 -0
  42. package/dist/acroform/xfa/PdfXfaForm.js +64 -0
  43. package/dist/acroform/xfa/index.d.ts +3 -0
  44. package/dist/acroform/xfa/index.js +2 -0
  45. package/dist/annotations/PdfAnnotation.d.ts +40 -0
  46. package/dist/annotations/PdfAnnotation.js +105 -0
  47. package/dist/annotations/PdfAnnotationFlags.d.ts +25 -0
  48. package/dist/annotations/PdfAnnotationFlags.js +94 -0
  49. package/dist/annotations/PdfAnnotationWriter.d.ts +20 -0
  50. package/dist/annotations/PdfAnnotationWriter.js +76 -0
  51. package/dist/annotations/PdfWidgetAnnotation.d.ts +15 -0
  52. package/dist/annotations/PdfWidgetAnnotation.js +37 -0
  53. package/dist/annotations/index.d.ts +4 -0
  54. package/dist/annotations/index.js +4 -0
  55. package/dist/core/objects/pdf-array.d.ts +1 -1
  56. package/dist/core/objects/pdf-array.js +3 -2
  57. package/dist/core/objects/pdf-boolean.d.ts +1 -1
  58. package/dist/core/objects/pdf-boolean.js +3 -2
  59. package/dist/core/objects/pdf-comment.d.ts +1 -1
  60. package/dist/core/objects/pdf-comment.js +1 -1
  61. package/dist/core/objects/pdf-dictionary.d.ts +1 -1
  62. package/dist/core/objects/pdf-dictionary.js +3 -2
  63. package/dist/core/objects/pdf-hexadecimal.d.ts +1 -1
  64. package/dist/core/objects/pdf-hexadecimal.js +3 -2
  65. package/dist/core/objects/pdf-indirect-object.d.ts +1 -1
  66. package/dist/core/objects/pdf-indirect-object.js +1 -1
  67. package/dist/core/objects/pdf-name.d.ts +1 -1
  68. package/dist/core/objects/pdf-name.js +3 -2
  69. package/dist/core/objects/pdf-null.d.ts +1 -1
  70. package/dist/core/objects/pdf-null.js +3 -2
  71. package/dist/core/objects/pdf-number.d.ts +1 -1
  72. package/dist/core/objects/pdf-number.js +3 -2
  73. package/dist/core/objects/pdf-object-reference.d.ts +1 -1
  74. package/dist/core/objects/pdf-object-reference.js +3 -2
  75. package/dist/core/objects/pdf-object.d.ts +3 -1
  76. package/dist/core/objects/pdf-object.js +6 -0
  77. package/dist/core/objects/pdf-start-xref.d.ts +1 -1
  78. package/dist/core/objects/pdf-start-xref.js +3 -2
  79. package/dist/core/objects/pdf-stream.d.ts +3 -3
  80. package/dist/core/objects/pdf-stream.js +39 -14
  81. package/dist/core/objects/pdf-string.d.ts +2 -1
  82. package/dist/core/objects/pdf-string.js +17 -2
  83. package/dist/core/objects/pdf-trailer.d.ts +1 -1
  84. package/dist/core/objects/pdf-trailer.js +3 -2
  85. package/dist/core/objects/pdf-xref-table.d.ts +3 -3
  86. package/dist/core/objects/pdf-xref-table.js +3 -3
  87. package/dist/index.d.ts +1 -0
  88. package/dist/index.js +1 -0
  89. package/dist/pdf/pdf-document.d.ts +14 -11
  90. package/dist/pdf/pdf-document.js +36 -26
  91. package/dist/pdf/pdf-revision.d.ts +1 -1
  92. package/dist/pdf/pdf-revision.js +1 -1
  93. package/dist/pdf/pdf-xref-lookup.d.ts +8 -0
  94. package/dist/pdf/pdf-xref-lookup.js +12 -0
  95. package/dist/security/handlers/base.js +3 -0
  96. package/package.json +1 -1
  97. package/dist/xfa/index.d.ts +0 -1
  98. package/dist/xfa/index.js +0 -1
  99. package/dist/xfa/manager.d.ts +0 -44
  100. package/dist/xfa/manager.js +0 -136
@@ -0,0 +1,499 @@
1
+ import { PdfDictionary } from '../../core/objects/pdf-dictionary.js';
2
+ import { PdfArray } from '../../core/objects/pdf-array.js';
3
+ import { PdfString } from '../../core/objects/pdf-string.js';
4
+ import { PdfName } from '../../core/objects/pdf-name.js';
5
+ import { PdfNumber } from '../../core/objects/pdf-number.js';
6
+ import { decodeWithFontEncoding } from '../../utils/decodeWithFontEncoding.js';
7
+ import { PdfWidgetAnnotation } from '../../annotations/PdfWidgetAnnotation.js';
8
+ import { PdfDefaultAppearance } from './PdfDefaultAppearance.js';
9
+ import { PdfFieldType as PdfFieldTypeConst } from './types.js';
10
+ /**
11
+ * Abstract base form field class. Extends PdfWidgetAnnotation with form-specific properties:
12
+ * FT, V, DA, Ff, T (name), field hierarchy (parent/children/siblings).
13
+ * Subclasses must implement generateAppearance().
14
+ */
15
+ export class PdfFormField extends PdfWidgetAnnotation {
16
+ _parent;
17
+ defaultGenerateAppearance = true;
18
+ _appearanceStream;
19
+ _appearanceStreamYes;
20
+ form;
21
+ constructor(options) {
22
+ super({ other: options?.other });
23
+ this.form = options?.form;
24
+ if (options?.parent) {
25
+ this._parent = options.parent;
26
+ }
27
+ }
28
+ get parent() {
29
+ if (this._parent)
30
+ return this._parent;
31
+ if (!this.form)
32
+ return undefined;
33
+ return this.form.fields.find((f) => f !== this &&
34
+ f.kids.some((k) => k.objectNumber === this.objectNumber &&
35
+ k.generationNumber === this.generationNumber));
36
+ }
37
+ set parent(field) {
38
+ if (this._parent) {
39
+ this._parent.kids = this._parent.kids.filter((k) => k.objectNumber !== this.objectNumber ||
40
+ k.generationNumber !== this.generationNumber);
41
+ }
42
+ this._parent = field;
43
+ if (field) {
44
+ const alreadyInKids = field.kids.some((k) => k.objectNumber === this.objectNumber &&
45
+ k.generationNumber === this.generationNumber);
46
+ if (!alreadyInKids) {
47
+ field.kids = [...field.kids, this.reference];
48
+ }
49
+ }
50
+ }
51
+ get children() {
52
+ if (!this.form)
53
+ return [];
54
+ return this.form.fields.filter((f) => f.parent === this);
55
+ }
56
+ set children(fields) {
57
+ for (const child of this.children) {
58
+ child._parent = undefined;
59
+ }
60
+ this.kids = fields.map((f) => f.reference);
61
+ for (const child of fields) {
62
+ child._parent = this;
63
+ }
64
+ }
65
+ get siblings() {
66
+ return this.parent?.children ?? [];
67
+ }
68
+ get encodingMap() {
69
+ const fontName = this.fontName;
70
+ if (!fontName)
71
+ return undefined;
72
+ return this.form?.fontEncodingMaps?.get(fontName);
73
+ }
74
+ get fieldType() {
75
+ const ft = this.content.get('FT')?.as(PdfName)?.value ??
76
+ this.parent?.content.get('FT')?.as(PdfName)?.value;
77
+ switch (ft) {
78
+ case 'Tx':
79
+ return 'Text';
80
+ case 'Btn':
81
+ return 'Button';
82
+ case 'Ch':
83
+ return 'Choice';
84
+ case 'Sig':
85
+ return 'Signature';
86
+ default:
87
+ return null;
88
+ }
89
+ }
90
+ set fieldType(type) {
91
+ if (type === null) {
92
+ this.content.delete('FT');
93
+ }
94
+ else {
95
+ this.content.set('FT', new PdfName(PdfFieldTypeConst[type]));
96
+ }
97
+ }
98
+ get name() {
99
+ const parentName = this.parent?.name ?? '';
100
+ const ownName = this.content.get('T')?.as(PdfString)?.value ?? '';
101
+ if (parentName && ownName) {
102
+ return `${parentName}.${ownName}`;
103
+ }
104
+ return parentName || ownName;
105
+ }
106
+ set name(name) {
107
+ this.content.set('T', new PdfString(name));
108
+ }
109
+ get defaultValue() {
110
+ const dv = this.content.get('DV') ?? this.parent?.content.get('DV');
111
+ if (dv instanceof PdfString)
112
+ return dv.value;
113
+ if (dv instanceof PdfName)
114
+ return dv.value;
115
+ return '';
116
+ }
117
+ set defaultValue(val) {
118
+ if (this.fieldType === 'Button') {
119
+ this.content.set('DV', new PdfName(val));
120
+ }
121
+ else {
122
+ this.content.set('DV', new PdfString(val));
123
+ }
124
+ }
125
+ get value() {
126
+ const v = this.content.get('V') ?? this.parent?.content.get('V');
127
+ if (v instanceof PdfString) {
128
+ if (v.isUTF16BE)
129
+ return v.value;
130
+ if (this.encodingMap) {
131
+ return decodeWithFontEncoding(v.raw, this.encodingMap);
132
+ }
133
+ return v.value;
134
+ }
135
+ else if (v instanceof PdfName) {
136
+ return v.value;
137
+ }
138
+ return '';
139
+ }
140
+ set value(val) {
141
+ if (this.value === val)
142
+ return;
143
+ const fieldParent = this.parent?.content.get('FT')
144
+ ? this.parent
145
+ : undefined;
146
+ const fieldType = this.fieldType;
147
+ if (fieldType === 'Button') {
148
+ val = val instanceof PdfString ? val.value : val;
149
+ if (val.trim() === '') {
150
+ this.content.delete('V');
151
+ fieldParent?.content.delete('V');
152
+ this.content.delete('AS');
153
+ return;
154
+ }
155
+ this.content.set('V', new PdfName(val));
156
+ fieldParent?.content.set('V', new PdfName(val));
157
+ this.content.set('AS', new PdfName(val));
158
+ }
159
+ else {
160
+ const pdfVal = val instanceof PdfString ? val : new PdfString(val);
161
+ this.content.set('V', pdfVal);
162
+ fieldParent?.content.set('V', pdfVal);
163
+ }
164
+ if (this.defaultGenerateAppearance) {
165
+ this.generateAppearance();
166
+ for (const sibling of this.siblings) {
167
+ if (sibling !== this &&
168
+ sibling.rect &&
169
+ sibling.defaultGenerateAppearance) {
170
+ sibling.generateAppearance();
171
+ }
172
+ }
173
+ }
174
+ }
175
+ get checked() {
176
+ if (this.fieldType === 'Button') {
177
+ const v = this.content.get('V') ?? this.parent?.content.get('V');
178
+ return v instanceof PdfName && v.value === 'Yes';
179
+ }
180
+ return false;
181
+ }
182
+ set checked(isChecked) {
183
+ if (this.fieldType === 'Button') {
184
+ const target = this.parent ?? this;
185
+ if (isChecked) {
186
+ target.content.set('V', new PdfName('Yes'));
187
+ this.content.set('AS', new PdfName('Yes'));
188
+ }
189
+ else {
190
+ target.content.set('V', new PdfName('Off'));
191
+ this.content.set('AS', new PdfName('Off'));
192
+ }
193
+ }
194
+ }
195
+ get fontSize() {
196
+ const da = this.defaultAppearance || '';
197
+ const parsed = PdfDefaultAppearance.parse(da);
198
+ return parsed?.fontSize ?? null;
199
+ }
200
+ set fontSize(size) {
201
+ const da = this.defaultAppearance || '';
202
+ if (!da) {
203
+ this.content.set('DA', new PdfDefaultAppearance('F1', size, '0 g'));
204
+ return;
205
+ }
206
+ const parsed = PdfDefaultAppearance.parse(da);
207
+ if (parsed) {
208
+ parsed.fontSize = size;
209
+ this.content.set('DA', parsed);
210
+ }
211
+ }
212
+ get fontName() {
213
+ const da = this.defaultAppearance || '';
214
+ const parsed = PdfDefaultAppearance.parse(da);
215
+ return parsed?.fontName ?? null;
216
+ }
217
+ set fontName(fontName) {
218
+ const da = this.defaultAppearance || '';
219
+ if (!da) {
220
+ this.content.set('DA', new PdfDefaultAppearance(fontName, 12, '0 g'));
221
+ return;
222
+ }
223
+ const parsed = PdfDefaultAppearance.parse(da);
224
+ if (parsed) {
225
+ parsed.fontName = fontName;
226
+ this.content.set('DA', parsed);
227
+ }
228
+ }
229
+ set font(font) {
230
+ if (font === null) {
231
+ this.content.set('DA', new PdfString(''));
232
+ return;
233
+ }
234
+ const resourceName = font.resourceName;
235
+ const currentSize = this.fontSize ?? 12;
236
+ const da = this.defaultAppearance || '';
237
+ if (!da) {
238
+ this.content.set('DA', new PdfDefaultAppearance(resourceName, currentSize, '0 g'));
239
+ return;
240
+ }
241
+ const parsed = PdfDefaultAppearance.parse(da);
242
+ if (parsed) {
243
+ parsed.fontName = resourceName;
244
+ this.content.set('DA', parsed);
245
+ }
246
+ }
247
+ // Field flags (Ff) - with parent inheritance
248
+ get flags() {
249
+ const own = this.content.get('Ff')?.as(PdfNumber)?.value;
250
+ if (own !== undefined)
251
+ return own;
252
+ return this.parent?.flags ?? 0;
253
+ }
254
+ set flags(flags) {
255
+ this.content.set('Ff', new PdfNumber(flags));
256
+ }
257
+ getFlag(bit) {
258
+ return (this.flags & bit) !== 0;
259
+ }
260
+ setFlag(bit, value) {
261
+ if (value) {
262
+ this.flags = this.flags | bit;
263
+ }
264
+ else {
265
+ this.flags = this.flags & ~bit;
266
+ }
267
+ }
268
+ get readOnly() {
269
+ return this.getFlag(1);
270
+ }
271
+ set readOnly(v) {
272
+ this.setFlag(1, v);
273
+ }
274
+ get required() {
275
+ return this.getFlag(2);
276
+ }
277
+ set required(v) {
278
+ this.setFlag(2, v);
279
+ }
280
+ get multiline() {
281
+ return this.getFlag(4096);
282
+ }
283
+ set multiline(v) {
284
+ this.setFlag(4096, v);
285
+ }
286
+ get password() {
287
+ return this.getFlag(8192);
288
+ }
289
+ set password(v) {
290
+ this.setFlag(8192, v);
291
+ }
292
+ get comb() {
293
+ return this.getFlag(16777216);
294
+ }
295
+ get combField() {
296
+ return this.getFlag(16777216);
297
+ }
298
+ set combField(v) {
299
+ this.setFlag(16777216, v);
300
+ }
301
+ get combo() {
302
+ return this.getFlag(131072);
303
+ }
304
+ set combo(v) {
305
+ this.setFlag(131072, v);
306
+ }
307
+ get radio() {
308
+ return this.getFlag(32768);
309
+ }
310
+ set radio(v) {
311
+ this.setFlag(32768, v);
312
+ }
313
+ get noToggleToOff() {
314
+ return this.getFlag(16384);
315
+ }
316
+ set noToggleToOff(v) {
317
+ this.setFlag(16384, v);
318
+ }
319
+ get noExport() {
320
+ return this.getFlag(4);
321
+ }
322
+ set noExport(v) {
323
+ this.setFlag(4, v);
324
+ }
325
+ get pushButton() {
326
+ return this.getFlag(65536);
327
+ }
328
+ set pushButton(v) {
329
+ this.setFlag(65536, v);
330
+ }
331
+ get edit() {
332
+ return this.getFlag(262144);
333
+ }
334
+ set edit(v) {
335
+ this.setFlag(262144, v);
336
+ }
337
+ get sort() {
338
+ return this.getFlag(524288);
339
+ }
340
+ set sort(v) {
341
+ this.setFlag(524288, v);
342
+ }
343
+ get multiSelect() {
344
+ return this.getFlag(2097152);
345
+ }
346
+ set multiSelect(v) {
347
+ this.setFlag(2097152, v);
348
+ }
349
+ get doNotSpellCheck() {
350
+ return this.getFlag(4194304);
351
+ }
352
+ set doNotSpellCheck(v) {
353
+ this.setFlag(4194304, v);
354
+ }
355
+ get doNotScroll() {
356
+ return this.getFlag(8388608);
357
+ }
358
+ set doNotScroll(v) {
359
+ this.setFlag(8388608, v);
360
+ }
361
+ get commitOnSelChange() {
362
+ return this.getFlag(67108864);
363
+ }
364
+ set commitOnSelChange(v) {
365
+ this.setFlag(67108864, v);
366
+ }
367
+ get quadding() {
368
+ return (this.content.get('Q')?.as(PdfNumber)?.value ??
369
+ this.parent?.content.get('Q')?.as(PdfNumber)?.value ??
370
+ 0);
371
+ }
372
+ set quadding(q) {
373
+ this.content.set('Q', new PdfNumber(q));
374
+ }
375
+ get options() {
376
+ const opt = this.content.get('Opt')?.as((PdfArray)) ??
377
+ this.parent?.content.get('Opt')?.as((PdfArray));
378
+ if (!opt)
379
+ return [];
380
+ return opt.items.map((item) => item.value);
381
+ }
382
+ set options(options) {
383
+ if (options.length === 0) {
384
+ this.content.delete('Opt');
385
+ return;
386
+ }
387
+ const optArray = new PdfArray(options.map((opt) => new PdfString(opt)));
388
+ this.content.set('Opt', optArray);
389
+ }
390
+ get defaultAppearance() {
391
+ return (this.content.get('DA')?.as(PdfString)?.value ??
392
+ this.parent?.content.get('DA')?.as(PdfString)?.value ??
393
+ this.form?.defaultAppearance ??
394
+ null);
395
+ }
396
+ set defaultAppearance(da) {
397
+ this.content.set('DA', new PdfString(da));
398
+ }
399
+ get maxLen() {
400
+ return this.content.get('MaxLen')?.as(PdfNumber)?.value ?? null;
401
+ }
402
+ set maxLen(maxLen) {
403
+ if (maxLen === null) {
404
+ this.content.delete('MaxLen');
405
+ }
406
+ else {
407
+ this.content.set('MaxLen', new PdfNumber(maxLen));
408
+ }
409
+ }
410
+ get kids() {
411
+ const kidsArray = this.content
412
+ .get('Kids')
413
+ ?.as((PdfArray));
414
+ if (!kidsArray)
415
+ return [];
416
+ return kidsArray.items;
417
+ }
418
+ set kids(kids) {
419
+ if (kids.length === 0) {
420
+ this.content.delete('Kids');
421
+ return;
422
+ }
423
+ const kidsArray = new PdfArray(kids);
424
+ this.content.set('Kids', kidsArray);
425
+ }
426
+ getAppearanceStream() {
427
+ if (this.fieldType === 'Button') {
428
+ if (this.checked && this._appearanceStreamYes) {
429
+ return this._appearanceStreamYes?.content;
430
+ }
431
+ return this._appearanceStream?.content;
432
+ }
433
+ return this._appearanceStream?.content;
434
+ }
435
+ getAppearanceStreamsForWriting() {
436
+ if (!this._appearanceStream)
437
+ return undefined;
438
+ return {
439
+ primary: this._appearanceStream,
440
+ secondary: this.fieldType === 'Button'
441
+ ? this._appearanceStreamYes
442
+ : undefined,
443
+ };
444
+ }
445
+ setAppearanceReference(appearanceStreamRef, appearanceStreamYesRef) {
446
+ let apDict = this.appearanceStreamDict;
447
+ if (!apDict) {
448
+ apDict = new PdfDictionary();
449
+ this.appearanceStreamDict = apDict;
450
+ }
451
+ if (appearanceStreamYesRef && this.fieldType === 'Button') {
452
+ const stateDict = new PdfDictionary();
453
+ stateDict.set('Off', appearanceStreamRef);
454
+ stateDict.set('Yes', appearanceStreamYesRef);
455
+ apDict.set('N', stateDict);
456
+ }
457
+ else {
458
+ apDict.set('N', appearanceStreamRef);
459
+ }
460
+ }
461
+ static _fallbackCtor;
462
+ static _registry = new Map();
463
+ static registerFieldType(ft, ctor, options) {
464
+ PdfFormField._registry.set(ft, ctor);
465
+ if (options?.fallback) {
466
+ PdfFormField._fallbackCtor = ctor;
467
+ }
468
+ }
469
+ static create(options) {
470
+ let ft;
471
+ try {
472
+ const dict = options.other.content.as(PdfDictionary);
473
+ ft = dict.get('FT')?.as(PdfName)?.value;
474
+ }
475
+ catch {
476
+ // content may not be a dictionary
477
+ }
478
+ if (!ft && options.parent) {
479
+ try {
480
+ ft = options.parent.content.get('FT')?.as(PdfName)?.value;
481
+ }
482
+ catch {
483
+ // ignore
484
+ }
485
+ }
486
+ const Ctor = ft ? PdfFormField._registry.get(ft) : undefined;
487
+ if (!Ctor) {
488
+ // Fields without FT are parent/container nodes — use the
489
+ // fallback type (typically Text) as a concrete stand-in.
490
+ if (!PdfFormField._fallbackCtor) {
491
+ throw new Error(`Unknown field type: ${ft ?? '(none)'}`);
492
+ }
493
+ return new PdfFormField._fallbackCtor(options);
494
+ }
495
+ return new Ctor(options);
496
+ }
497
+ }
498
+ /** Backward compatible alias */
499
+ export { PdfFormField as PdfAcroFormField };
@@ -0,0 +1,46 @@
1
+ import { PdfDictionary } from '../../core/objects/pdf-dictionary.js';
2
+ /**
3
+ * Field-specific Ff flag accessors for form fields.
4
+ * These are separate from annotation flags (F field).
5
+ */
6
+ export declare class PdfFormFieldFlags {
7
+ dict: PdfDictionary;
8
+ parentDict?: PdfDictionary;
9
+ constructor(dict: PdfDictionary, parentDict?: PdfDictionary);
10
+ get flags(): number;
11
+ set flags(flags: number);
12
+ private getFlag;
13
+ private setFlag;
14
+ get readOnly(): boolean;
15
+ set readOnly(v: boolean);
16
+ get required(): boolean;
17
+ set required(v: boolean);
18
+ get noExport(): boolean;
19
+ set noExport(v: boolean);
20
+ get multiline(): boolean;
21
+ set multiline(v: boolean);
22
+ get password(): boolean;
23
+ set password(v: boolean);
24
+ get noToggleToOff(): boolean;
25
+ set noToggleToOff(v: boolean);
26
+ get radio(): boolean;
27
+ set radio(v: boolean);
28
+ get pushButton(): boolean;
29
+ set pushButton(v: boolean);
30
+ get combo(): boolean;
31
+ set combo(v: boolean);
32
+ get edit(): boolean;
33
+ set edit(v: boolean);
34
+ get sort(): boolean;
35
+ set sort(v: boolean);
36
+ get multiSelect(): boolean;
37
+ set multiSelect(v: boolean);
38
+ get doNotSpellCheck(): boolean;
39
+ set doNotSpellCheck(v: boolean);
40
+ get doNotScroll(): boolean;
41
+ set doNotScroll(v: boolean);
42
+ get comb(): boolean;
43
+ set comb(v: boolean);
44
+ get commitOnSelChange(): boolean;
45
+ set commitOnSelChange(v: boolean);
46
+ }
@@ -0,0 +1,128 @@
1
+ import { PdfNumber } from '../../core/objects/pdf-number.js';
2
+ /**
3
+ * Field-specific Ff flag accessors for form fields.
4
+ * These are separate from annotation flags (F field).
5
+ */
6
+ export class PdfFormFieldFlags {
7
+ dict;
8
+ parentDict;
9
+ constructor(dict, parentDict) {
10
+ this.dict = dict;
11
+ this.parentDict = parentDict;
12
+ }
13
+ get flags() {
14
+ return (this.dict.get('Ff')?.as(PdfNumber)?.value ??
15
+ this.parentDict?.get('Ff')?.as(PdfNumber)?.value ??
16
+ 0);
17
+ }
18
+ set flags(flags) {
19
+ this.dict.set('Ff', new PdfNumber(flags));
20
+ }
21
+ getFlag(bit) {
22
+ return (this.flags & bit) !== 0;
23
+ }
24
+ setFlag(bit, value) {
25
+ if (value) {
26
+ this.flags = this.flags | bit;
27
+ }
28
+ else {
29
+ this.flags = this.flags & ~bit;
30
+ }
31
+ }
32
+ get readOnly() {
33
+ return this.getFlag(1);
34
+ }
35
+ set readOnly(v) {
36
+ this.setFlag(1, v);
37
+ }
38
+ get required() {
39
+ return this.getFlag(2);
40
+ }
41
+ set required(v) {
42
+ this.setFlag(2, v);
43
+ }
44
+ get noExport() {
45
+ return this.getFlag(4);
46
+ }
47
+ set noExport(v) {
48
+ this.setFlag(4, v);
49
+ }
50
+ get multiline() {
51
+ return this.getFlag(4096);
52
+ }
53
+ set multiline(v) {
54
+ this.setFlag(4096, v);
55
+ }
56
+ get password() {
57
+ return this.getFlag(8192);
58
+ }
59
+ set password(v) {
60
+ this.setFlag(8192, v);
61
+ }
62
+ get noToggleToOff() {
63
+ return this.getFlag(16384);
64
+ }
65
+ set noToggleToOff(v) {
66
+ this.setFlag(16384, v);
67
+ }
68
+ get radio() {
69
+ return this.getFlag(32768);
70
+ }
71
+ set radio(v) {
72
+ this.setFlag(32768, v);
73
+ }
74
+ get pushButton() {
75
+ return this.getFlag(65536);
76
+ }
77
+ set pushButton(v) {
78
+ this.setFlag(65536, v);
79
+ }
80
+ get combo() {
81
+ return this.getFlag(131072);
82
+ }
83
+ set combo(v) {
84
+ this.setFlag(131072, v);
85
+ }
86
+ get edit() {
87
+ return this.getFlag(262144);
88
+ }
89
+ set edit(v) {
90
+ this.setFlag(262144, v);
91
+ }
92
+ get sort() {
93
+ return this.getFlag(524288);
94
+ }
95
+ set sort(v) {
96
+ this.setFlag(524288, v);
97
+ }
98
+ get multiSelect() {
99
+ return this.getFlag(2097152);
100
+ }
101
+ set multiSelect(v) {
102
+ this.setFlag(2097152, v);
103
+ }
104
+ get doNotSpellCheck() {
105
+ return this.getFlag(4194304);
106
+ }
107
+ set doNotSpellCheck(v) {
108
+ this.setFlag(4194304, v);
109
+ }
110
+ get doNotScroll() {
111
+ return this.getFlag(8388608);
112
+ }
113
+ set doNotScroll(v) {
114
+ this.setFlag(8388608, v);
115
+ }
116
+ get comb() {
117
+ return this.getFlag(16777216);
118
+ }
119
+ set comb(v) {
120
+ this.setFlag(16777216, v);
121
+ }
122
+ get commitOnSelChange() {
123
+ return this.getFlag(67108864);
124
+ }
125
+ set commitOnSelChange(v) {
126
+ this.setFlag(67108864, v);
127
+ }
128
+ }
@@ -0,0 +1,7 @@
1
+ import { PdfFormField } from './PdfFormField.js';
2
+ /**
3
+ * Signature form field subtype.
4
+ */
5
+ export declare class PdfSignatureFormField extends PdfFormField {
6
+ generateAppearance(): boolean;
7
+ }
@@ -0,0 +1,12 @@
1
+ import { PdfFormField } from './PdfFormField.js';
2
+ /**
3
+ * Signature form field subtype.
4
+ */
5
+ export class PdfSignatureFormField extends PdfFormField {
6
+ static {
7
+ PdfFormField.registerFieldType('Sig', PdfSignatureFormField);
8
+ }
9
+ generateAppearance() {
10
+ return false;
11
+ }
12
+ }
@@ -0,0 +1,10 @@
1
+ import { PdfFormField } from './PdfFormField.js';
2
+ /**
3
+ * Text form field subtype.
4
+ */
5
+ export declare class PdfTextFormField extends PdfFormField {
6
+ generateAppearance(options?: {
7
+ makeReadOnly?: boolean;
8
+ textYOffset?: number;
9
+ }): boolean;
10
+ }