pdf-lite 1.4.0 → 1.5.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 (94) hide show
  1. package/dist/acroform/acroform.d.ts +3 -3
  2. package/dist/acroform/acroform.js +2 -2
  3. package/dist/acroform/appearance/index.d.ts +4 -4
  4. package/dist/acroform/appearance/index.js +4 -4
  5. package/dist/acroform/appearance/{PdfAppearanceStream.d.ts → pdf-appearance-stream.d.ts} +9 -3
  6. package/dist/acroform/appearance/{PdfAppearanceStream.js → pdf-appearance-stream.js} +14 -5
  7. package/dist/acroform/appearance/{PdfButtonAppearanceStream.d.ts → pdf-button-appearance-stream.d.ts} +3 -2
  8. package/dist/acroform/appearance/pdf-button-appearance-stream.js +54 -0
  9. package/dist/acroform/appearance/pdf-choice-appearance-stream.d.ts +22 -0
  10. package/dist/acroform/appearance/pdf-choice-appearance-stream.js +75 -0
  11. package/dist/acroform/appearance/pdf-graphics.d.ts +51 -0
  12. package/dist/acroform/appearance/pdf-graphics.js +239 -0
  13. package/dist/acroform/appearance/{PdfTextAppearanceStream.d.ts → pdf-text-appearance-stream.d.ts} +7 -2
  14. package/dist/acroform/appearance/pdf-text-appearance-stream.js +104 -0
  15. package/dist/acroform/fields/index.d.ts +7 -7
  16. package/dist/acroform/fields/index.js +7 -7
  17. package/dist/acroform/fields/pdf-button-form-field.d.ts +23 -0
  18. package/dist/acroform/fields/pdf-button-form-field.js +102 -0
  19. package/dist/acroform/fields/pdf-choice-form-field.d.ts +18 -0
  20. package/dist/acroform/fields/pdf-choice-form-field.js +131 -0
  21. package/dist/acroform/fields/{PdfFormFieldFlags.d.ts → pdf-form-field-flags.d.ts} +5 -6
  22. package/dist/acroform/fields/{PdfFormFieldFlags.js → pdf-form-field-flags.js} +12 -18
  23. package/dist/acroform/fields/{PdfFormField.d.ts → pdf-form-field.d.ts} +15 -11
  24. package/dist/acroform/fields/{PdfFormField.js → pdf-form-field.js} +68 -134
  25. package/dist/acroform/fields/{PdfSignatureFormField.d.ts → pdf-signature-form-field.d.ts} +1 -1
  26. package/dist/acroform/fields/{PdfSignatureFormField.js → pdf-signature-form-field.js} +1 -1
  27. package/dist/acroform/fields/{PdfTextFormField.d.ts → pdf-text-form-field.d.ts} +1 -1
  28. package/dist/acroform/fields/pdf-text-form-field.js +77 -0
  29. package/dist/acroform/fields/types.d.ts +5 -0
  30. package/dist/acroform/index.d.ts +2 -2
  31. package/dist/acroform/index.js +2 -2
  32. package/dist/acroform/manager.d.ts +7 -3
  33. package/dist/acroform/manager.js +14 -8
  34. package/dist/acroform/{PdfAcroForm.d.ts → pdf-acro-form.d.ts} +12 -6
  35. package/dist/acroform/{PdfAcroForm.js → pdf-acro-form.js} +43 -29
  36. package/dist/acroform/{PdfFontEncodingCache.d.ts → pdf-font-encoding-cache.d.ts} +11 -0
  37. package/dist/acroform/pdf-font-encoding-cache.js +188 -0
  38. package/dist/acroform/xfa/index.d.ts +3 -3
  39. package/dist/acroform/xfa/index.js +2 -2
  40. package/dist/acroform/xfa/{PdfXfaForm.d.ts → pdf-xfa-form.d.ts} +1 -2
  41. package/dist/acroform/xfa/{PdfXfaForm.js → pdf-xfa-form.js} +2 -10
  42. package/dist/annotations/index.d.ts +4 -4
  43. package/dist/annotations/index.js +4 -4
  44. package/dist/annotations/{PdfAnnotationFlags.d.ts → pdf-annotation-flags.d.ts} +3 -4
  45. package/dist/annotations/{PdfAnnotationFlags.js → pdf-annotation-flags.js} +5 -6
  46. package/dist/annotations/{PdfAnnotation.d.ts → pdf-annotation.d.ts} +25 -4
  47. package/dist/annotations/{PdfAnnotation.js → pdf-annotation.js} +4 -3
  48. package/dist/annotations/{PdfWidgetAnnotation.d.ts → pdf-widget-annotation.d.ts} +1 -1
  49. package/dist/annotations/{PdfWidgetAnnotation.js → pdf-widget-annotation.js} +1 -1
  50. package/dist/core/objects/pdf-stream.d.ts +1 -0
  51. package/dist/core/objects/pdf-stream.js +6 -2
  52. package/dist/core/parser/incremental-parser.d.ts +0 -13
  53. package/dist/core/parser/incremental-parser.js +1 -18
  54. package/dist/core/streams/object-stream.d.ts +1 -1
  55. package/dist/core/streams/object-stream.js +1 -1
  56. package/dist/errors.d.ts +22 -0
  57. package/dist/errors.js +24 -0
  58. package/dist/fonts/index.d.ts +1 -1
  59. package/dist/fonts/index.js +1 -1
  60. package/dist/fonts/pdf-font.d.ts +64 -7
  61. package/dist/fonts/pdf-font.js +188 -8
  62. package/dist/index.d.ts +1 -0
  63. package/dist/index.js +1 -0
  64. package/dist/pdf/index.d.ts +0 -1
  65. package/dist/pdf/index.js +0 -1
  66. package/dist/pdf/pdf-document.d.ts +2 -1
  67. package/dist/pdf/pdf-document.js +15 -11
  68. package/dist/utils/encodePdfText.d.ts +17 -0
  69. package/dist/utils/encodePdfText.js +61 -0
  70. package/dist/utils/index.d.ts +1 -1
  71. package/dist/utils/index.js +1 -1
  72. package/package.json +1 -1
  73. package/dist/acroform/PdfFontEncodingCache.js +0 -75
  74. package/dist/acroform/appearance/PdfButtonAppearanceStream.js +0 -54
  75. package/dist/acroform/appearance/PdfChoiceAppearanceStream.d.ts +0 -15
  76. package/dist/acroform/appearance/PdfChoiceAppearanceStream.js +0 -48
  77. package/dist/acroform/appearance/PdfTextAppearanceStream.js +0 -75
  78. package/dist/acroform/fields/PdfButtonFormField.d.ts +0 -9
  79. package/dist/acroform/fields/PdfButtonFormField.js +0 -35
  80. package/dist/acroform/fields/PdfChoiceFormField.d.ts +0 -9
  81. package/dist/acroform/fields/PdfChoiceFormField.js +0 -46
  82. package/dist/acroform/fields/PdfTextFormField.js +0 -52
  83. package/dist/pdf/errors.d.ts +0 -6
  84. package/dist/pdf/errors.js +0 -6
  85. /package/dist/acroform/fields/{PdfDefaultAppearance.d.ts → pdf-default-appearance.d.ts} +0 -0
  86. /package/dist/acroform/fields/{PdfDefaultAppearance.js → pdf-default-appearance.js} +0 -0
  87. /package/dist/acroform/xfa/{PdfXfaData.d.ts → pdf-xfa-data.d.ts} +0 -0
  88. /package/dist/acroform/xfa/{PdfXfaData.js → pdf-xfa-data.js} +0 -0
  89. /package/dist/annotations/{PdfAnnotationWriter.d.ts → pdf-annotation-writer.d.ts} +0 -0
  90. /package/dist/annotations/{PdfAnnotationWriter.js → pdf-annotation-writer.js} +0 -0
  91. /package/dist/fonts/{font-manager.d.ts → manager.d.ts} +0 -0
  92. /package/dist/fonts/{font-manager.js → manager.js} +0 -0
  93. /package/dist/utils/{IterableReadableStream.d.ts → iterable-readable-stream.d.ts} +0 -0
  94. /package/dist/utils/{IterableReadableStream.js → iterable-readable-stream.js} +0 -0
@@ -4,9 +4,10 @@ import { PdfString } from '../../core/objects/pdf-string.js';
4
4
  import { PdfName } from '../../core/objects/pdf-name.js';
5
5
  import { PdfNumber } from '../../core/objects/pdf-number.js';
6
6
  import { decodeWithFontEncoding } from '../../utils/decodeWithFontEncoding.js';
7
- import { PdfWidgetAnnotation } from '../../annotations/PdfWidgetAnnotation.js';
8
- import { PdfDefaultAppearance } from './PdfDefaultAppearance.js';
7
+ import { PdfWidgetAnnotation } from '../../annotations/pdf-widget-annotation.js';
8
+ import { PdfDefaultAppearance } from './pdf-default-appearance.js';
9
9
  import { PdfFieldType as PdfFieldTypeConst } from './types.js';
10
+ import { PdfFormFieldFlags } from './pdf-form-field-flags.js';
10
11
  /**
11
12
  * Abstract base form field class. Extends PdfWidgetAnnotation with form-specific properties:
12
13
  * FT, V, DA, Ff, T (name), field hierarchy (parent/children/siblings).
@@ -115,12 +116,7 @@ export class PdfFormField extends PdfWidgetAnnotation {
115
116
  return '';
116
117
  }
117
118
  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
- }
119
+ this.content.set('DV', new PdfString(val));
124
120
  }
125
121
  get value() {
126
122
  const v = this.content.get('V') ?? this.parent?.content.get('V');
@@ -143,54 +139,37 @@ export class PdfFormField extends PdfWidgetAnnotation {
143
139
  const fieldParent = this.parent?.content.get('FT')
144
140
  ? this.parent
145
141
  : 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();
142
+ const generateAppearance = this._storeValue(val, fieldParent);
143
+ if (generateAppearance && this.defaultGenerateAppearance) {
144
+ this.tryGenerateAppearance(this);
166
145
  for (const sibling of this.siblings) {
167
146
  if (sibling !== this &&
168
147
  sibling.rect &&
169
148
  sibling.defaultGenerateAppearance) {
170
- sibling.generateAppearance();
149
+ this.tryGenerateAppearance(sibling);
171
150
  }
172
151
  }
173
152
  }
174
153
  }
154
+ /**
155
+ * Writes the value to the dictionary. Returns true if appearance generation
156
+ * should proceed, false to skip it (e.g. when value was cleared).
157
+ * Override in subclasses to change the stored representation.
158
+ */
159
+ _storeValue(val, fieldParent) {
160
+ const pdfVal = val instanceof PdfString ? val : new PdfString(val);
161
+ this.content.set('V', pdfVal);
162
+ fieldParent?.content.set('V', pdfVal);
163
+ return true;
164
+ }
165
+ tryGenerateAppearance(field) {
166
+ field.generateAppearance();
167
+ }
175
168
  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
169
  return false;
181
170
  }
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
- }
171
+ set checked(_isChecked) {
172
+ // no-op for non-button fields; overridden in PdfButtonFormField
194
173
  }
195
174
  get fontSize() {
196
175
  const da = this.defaultAppearance || '';
@@ -244,125 +223,114 @@ export class PdfFormField extends PdfWidgetAnnotation {
244
223
  this.content.set('DA', parsed);
245
224
  }
246
225
  }
247
- // Field flags (Ff) - with parent inheritance
248
226
  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));
227
+ const flags = new PdfFormFieldFlags(this.content.get('Ff') ?? this.parent?.content.get('Ff') ?? 0);
228
+ flags.onChange(() => {
229
+ this.flags = flags;
230
+ });
231
+ return flags;
256
232
  }
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
- }
233
+ set flags(v) {
234
+ this.content.set('Ff', v);
267
235
  }
268
236
  get readOnly() {
269
- return this.getFlag(1);
237
+ return this.flags.readOnly;
270
238
  }
271
239
  set readOnly(v) {
272
- this.setFlag(1, v);
240
+ this.flags.readOnly = v;
273
241
  }
274
242
  get required() {
275
- return this.getFlag(2);
243
+ return this.flags.required;
276
244
  }
277
245
  set required(v) {
278
- this.setFlag(2, v);
246
+ this.flags.required = v;
279
247
  }
280
248
  get multiline() {
281
- return this.getFlag(4096);
249
+ return this.flags.multiline;
282
250
  }
283
251
  set multiline(v) {
284
- this.setFlag(4096, v);
252
+ this.flags.multiline = v;
285
253
  }
286
254
  get password() {
287
- return this.getFlag(8192);
255
+ return this.flags.password;
288
256
  }
289
257
  set password(v) {
290
- this.setFlag(8192, v);
258
+ this.flags.password = v;
291
259
  }
292
260
  get comb() {
293
- return this.getFlag(16777216);
261
+ return this.flags.comb;
294
262
  }
295
263
  get combField() {
296
- return this.getFlag(16777216);
264
+ return this.flags.comb;
297
265
  }
298
266
  set combField(v) {
299
- this.setFlag(16777216, v);
267
+ this.flags.comb = v;
300
268
  }
301
269
  get combo() {
302
- return this.getFlag(131072);
270
+ return this.flags.combo;
303
271
  }
304
272
  set combo(v) {
305
- this.setFlag(131072, v);
273
+ this.flags.combo = v;
306
274
  }
307
275
  get radio() {
308
- return this.getFlag(32768);
276
+ return this.flags.radio;
309
277
  }
310
278
  set radio(v) {
311
- this.setFlag(32768, v);
279
+ this.flags.radio = v;
312
280
  }
313
281
  get noToggleToOff() {
314
- return this.getFlag(16384);
282
+ return this.flags.noToggleToOff;
315
283
  }
316
284
  set noToggleToOff(v) {
317
- this.setFlag(16384, v);
285
+ this.flags.noToggleToOff = v;
318
286
  }
319
287
  get noExport() {
320
- return this.getFlag(4);
288
+ return this.flags.noExport;
321
289
  }
322
290
  set noExport(v) {
323
- this.setFlag(4, v);
291
+ this.flags.noExport = v;
324
292
  }
325
293
  get pushButton() {
326
- return this.getFlag(65536);
294
+ return this.flags.pushButton;
327
295
  }
328
296
  set pushButton(v) {
329
- this.setFlag(65536, v);
297
+ this.flags.pushButton = v;
330
298
  }
331
299
  get edit() {
332
- return this.getFlag(262144);
300
+ return this.flags.edit;
333
301
  }
334
302
  set edit(v) {
335
- this.setFlag(262144, v);
303
+ this.flags.edit = v;
336
304
  }
337
305
  get sort() {
338
- return this.getFlag(524288);
306
+ return this.flags.sort;
339
307
  }
340
308
  set sort(v) {
341
- this.setFlag(524288, v);
309
+ this.flags.sort = v;
342
310
  }
343
311
  get multiSelect() {
344
- return this.getFlag(2097152);
312
+ return this.flags.multiSelect;
345
313
  }
346
314
  set multiSelect(v) {
347
- this.setFlag(2097152, v);
315
+ this.flags.multiSelect = v;
348
316
  }
349
317
  get doNotSpellCheck() {
350
- return this.getFlag(4194304);
318
+ return this.flags.doNotSpellCheck;
351
319
  }
352
320
  set doNotSpellCheck(v) {
353
- this.setFlag(4194304, v);
321
+ this.flags.doNotSpellCheck = v;
354
322
  }
355
323
  get doNotScroll() {
356
- return this.getFlag(8388608);
324
+ return this.flags.doNotScroll;
357
325
  }
358
326
  set doNotScroll(v) {
359
- this.setFlag(8388608, v);
327
+ this.flags.doNotScroll = v;
360
328
  }
361
329
  get commitOnSelChange() {
362
- return this.getFlag(67108864);
330
+ return this.flags.commitOnSelChange;
363
331
  }
364
332
  set commitOnSelChange(v) {
365
- this.setFlag(67108864, v);
333
+ this.flags.commitOnSelChange = v;
366
334
  }
367
335
  get quadding() {
368
336
  return (this.content.get('Q')?.as(PdfNumber)?.value ??
@@ -372,21 +340,6 @@ export class PdfFormField extends PdfWidgetAnnotation {
372
340
  set quadding(q) {
373
341
  this.content.set('Q', new PdfNumber(q));
374
342
  }
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
343
  get defaultAppearance() {
391
344
  return (this.content.get('DA')?.as(PdfString)?.value ??
392
345
  this.parent?.content.get('DA')?.as(PdfString)?.value ??
@@ -424,39 +377,20 @@ export class PdfFormField extends PdfWidgetAnnotation {
424
377
  this.content.set('Kids', kidsArray);
425
378
  }
426
379
  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
380
  return this._appearanceStream?.content;
434
381
  }
435
382
  getAppearanceStreamsForWriting() {
436
383
  if (!this._appearanceStream)
437
384
  return undefined;
438
- return {
439
- primary: this._appearanceStream,
440
- secondary: this.fieldType === 'Button'
441
- ? this._appearanceStreamYes
442
- : undefined,
443
- };
444
- }
445
- setAppearanceReference(appearanceStreamRef, appearanceStreamYesRef) {
385
+ return { primary: this._appearanceStream };
386
+ }
387
+ setAppearanceReference(appearanceStreamRef, _appearanceStreamYesRef) {
446
388
  let apDict = this.appearanceStreamDict;
447
389
  if (!apDict) {
448
390
  apDict = new PdfDictionary();
449
391
  this.appearanceStreamDict = apDict;
450
392
  }
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
- }
393
+ apDict.set('N', appearanceStreamRef);
460
394
  }
461
395
  static _fallbackCtor;
462
396
  static _registry = new Map();
@@ -1,4 +1,4 @@
1
- import { PdfFormField } from './PdfFormField.js';
1
+ import { PdfFormField } from './pdf-form-field.js';
2
2
  /**
3
3
  * Signature form field subtype.
4
4
  */
@@ -1,4 +1,4 @@
1
- import { PdfFormField } from './PdfFormField.js';
1
+ import { PdfFormField } from './pdf-form-field.js';
2
2
  /**
3
3
  * Signature form field subtype.
4
4
  */
@@ -1,4 +1,4 @@
1
- import { PdfFormField } from './PdfFormField.js';
1
+ import { PdfFormField } from './pdf-form-field.js';
2
2
  /**
3
3
  * Text form field subtype.
4
4
  */
@@ -0,0 +1,77 @@
1
+ import { PdfFormField } from './pdf-form-field.js';
2
+ import { PdfDefaultAppearance } from './pdf-default-appearance.js';
3
+ import { PdfTextAppearanceStream } from '../appearance/pdf-text-appearance-stream.js';
4
+ import { PdfDictionary } from '../../core/objects/pdf-dictionary.js';
5
+ import { PdfObjectReference } from '../../core/objects/pdf-object-reference.js';
6
+ /**
7
+ * Text form field subtype.
8
+ */
9
+ export class PdfTextFormField extends PdfFormField {
10
+ static {
11
+ PdfFormField.registerFieldType('Tx', PdfTextFormField, {
12
+ fallback: true,
13
+ });
14
+ }
15
+ generateAppearance(options) {
16
+ const rect = this.rect;
17
+ if (!rect || rect.length !== 4)
18
+ return false;
19
+ const da = this.defaultAppearance;
20
+ if (!da)
21
+ return false;
22
+ const parsed = PdfDefaultAppearance.parse(da);
23
+ if (!parsed)
24
+ return false;
25
+ let fontResources;
26
+ const drFontValue = this.form?.defaultResources?.get('Font');
27
+ const drFonts = drFontValue instanceof PdfDictionary ? drFontValue : undefined;
28
+ const daFontRef = this.form?.fontRefs?.get(parsed.fontName);
29
+ if (drFonts || daFontRef) {
30
+ // Build a fresh font dict using clean PdfObjectReferences (no
31
+ // pre/postTokens inherited from the original parse context).
32
+ const fontDict = new PdfDictionary();
33
+ if (drFonts) {
34
+ for (const [key, val] of drFonts.entries()) {
35
+ if (val instanceof PdfObjectReference) {
36
+ fontDict.set(key, new PdfObjectReference(val.objectNumber, val.generationNumber));
37
+ }
38
+ else if (val != null) {
39
+ fontDict.set(key, val);
40
+ }
41
+ }
42
+ }
43
+ if (daFontRef && !fontDict.has(parsed.fontName)) {
44
+ fontDict.set(parsed.fontName, new PdfObjectReference(daFontRef.objectNumber, daFontRef.generationNumber));
45
+ }
46
+ fontResources = new PdfDictionary();
47
+ fontResources.set('Font', fontDict);
48
+ }
49
+ const isUnicode = this.form?.isFontUnicode(parsed.fontName) ?? false;
50
+ const encodingMap = this.form?.fontEncodingMaps?.get(parsed.fontName);
51
+ const reverseEncodingMap = encodingMap
52
+ ? new Map(Array.from(encodingMap, ([code, char]) => [char, code]))
53
+ : undefined;
54
+ this._appearanceStream = new PdfTextAppearanceStream({
55
+ rect: rect,
56
+ value: this.value,
57
+ da: parsed,
58
+ multiline: this.multiline,
59
+ comb: this.comb,
60
+ maxLen: this.maxLen,
61
+ fontResources,
62
+ isUnicode,
63
+ reverseEncodingMap,
64
+ });
65
+ if (options?.makeReadOnly) {
66
+ this.readOnly = true;
67
+ if (!this.print)
68
+ this.print = true;
69
+ this.noZoom = true;
70
+ }
71
+ else {
72
+ if (!this.print)
73
+ this.print = true;
74
+ }
75
+ return true;
76
+ }
77
+ }
@@ -1,4 +1,5 @@
1
1
  import type { PdfDefaultResourcesDictionary } from '../acroform.js';
2
+ import type { PdfObjectReference } from '../../core/objects/pdf-object-reference.js';
2
3
  /**
3
4
  * Field types for AcroForm fields
4
5
  */
@@ -17,5 +18,9 @@ export interface FormContext<TField = any> {
17
18
  defaultResources: PdfDefaultResourcesDictionary | null;
18
19
  defaultAppearance: string | null;
19
20
  fontEncodingMaps: Map<string, Map<number, string>>;
21
+ /** Object references for all resolved fonts, keyed by resource name. */
22
+ fontRefs: Map<string, PdfObjectReference>;
20
23
  fields: TField[];
24
+ isFontUnicode: (fontName: string) => boolean;
25
+ needAppearances: boolean;
21
26
  }
@@ -1,6 +1,6 @@
1
1
  export * from './manager.js';
2
- export * from './PdfAcroForm.js';
2
+ export * from './pdf-acro-form.js';
3
3
  export * from './fields/index.js';
4
4
  export * from './appearance/index.js';
5
5
  export * from './xfa/index.js';
6
- export { PdfFontEncodingCache } from './PdfFontEncodingCache.js';
6
+ export { PdfFontEncodingCache } from './pdf-font-encoding-cache.js';
@@ -1,6 +1,6 @@
1
1
  export * from './manager.js';
2
- export * from './PdfAcroForm.js';
2
+ export * from './pdf-acro-form.js';
3
3
  export * from './fields/index.js';
4
4
  export * from './appearance/index.js';
5
5
  export * from './xfa/index.js';
6
- export { PdfFontEncodingCache } from './PdfFontEncodingCache.js';
6
+ export { PdfFontEncodingCache } from './pdf-font-encoding-cache.js';
@@ -1,13 +1,13 @@
1
1
  import { PdfDocument } from '../pdf/pdf-document.js';
2
2
  import { PdfAcroForm } from './acroform.js';
3
- import { PdfXfaForm } from './xfa/PdfXfaForm.js';
3
+ import { PdfXfaForm } from './xfa/pdf-xfa-form.js';
4
4
  /**
5
5
  * Manages AcroForm fields in PDF documents.
6
6
  * Provides methods to read and write form field values.
7
7
  */
8
8
  export declare class PdfAcroFormManager {
9
9
  private document;
10
- private _xfa;
10
+ private _acroform;
11
11
  constructor(document: PdfDocument);
12
12
  /**
13
13
  * Gets the XFA form wrapper, loading it lazily on first access.
@@ -24,10 +24,14 @@ export declare class PdfAcroFormManager {
24
24
  * @returns The AcroForm object or null if not found
25
25
  */
26
26
  read(): Promise<PdfAcroForm | null>;
27
+ /**
28
+ * Explicitly sets the XFA form instance, bypassing the lazy load on next write.
29
+ */
30
+ setXfa(xfa: PdfXfaForm): Promise<void>;
27
31
  /**
28
32
  * Writes the provided AcroForm to the associated PDF document.
29
33
  * @param acroForm The AcroForm instance to serialize into the document.
30
34
  * @throws Error If writing the AcroForm to the document fails.
31
35
  */
32
- write(acroForm: PdfAcroForm): Promise<void>;
36
+ write(acroForm?: PdfAcroForm): Promise<void>;
33
37
  }
@@ -1,12 +1,11 @@
1
1
  import { PdfAcroForm } from './acroform.js';
2
- import { PdfXfaForm } from './xfa/PdfXfaForm.js';
3
2
  /**
4
3
  * Manages AcroForm fields in PDF documents.
5
4
  * Provides methods to read and write form field values.
6
5
  */
7
6
  export class PdfAcroFormManager {
8
7
  document;
9
- _xfa = undefined;
8
+ _acroform = null;
10
9
  constructor(document) {
11
10
  this.document = document;
12
11
  }
@@ -15,10 +14,7 @@ export class PdfAcroFormManager {
15
14
  * @returns The PdfXfaForm or null if no XFA forms exist
16
15
  */
17
16
  async getXfa() {
18
- if (this._xfa === undefined) {
19
- this._xfa = await PdfXfaForm.fromDocument(this.document);
20
- }
21
- return this._xfa;
17
+ return (await (await this.read())?.getXfa()) || null;
22
18
  }
23
19
  /**
24
20
  * Checks if the document contains AcroForm fields.
@@ -38,7 +34,17 @@ export class PdfAcroFormManager {
38
34
  * @returns The AcroForm object or null if not found
39
35
  */
40
36
  async read() {
41
- return await PdfAcroForm.fromDocument(this.document);
37
+ if (this._acroform)
38
+ return this._acroform;
39
+ this._acroform = await PdfAcroForm.fromDocument(this.document);
40
+ return this._acroform;
41
+ }
42
+ /**
43
+ * Explicitly sets the XFA form instance, bypassing the lazy load on next write.
44
+ */
45
+ async setXfa(xfa) {
46
+ ;
47
+ (await this.read())?.setXfa(xfa);
42
48
  }
43
49
  /**
44
50
  * Writes the provided AcroForm to the associated PDF document.
@@ -46,6 +52,6 @@ export class PdfAcroFormManager {
46
52
  * @throws Error If writing the AcroForm to the document fails.
47
53
  */
48
54
  async write(acroForm) {
49
- await acroForm.write(this.document);
55
+ await (acroForm ?? (await this.read()))?.write(this.document);
50
56
  }
51
57
  }
@@ -6,11 +6,12 @@ import { PdfObjectReference } from '../core/objects/pdf-object-reference.js';
6
6
  import { PdfIndirectObject } from '../core/objects/pdf-indirect-object.js';
7
7
  import { PdfBoolean } from '../core/objects/pdf-boolean.js';
8
8
  import { PdfNumber } from '../core/objects/pdf-number.js';
9
- import { PdfFormField } from './fields/PdfFormField.js';
10
- import './fields/PdfTextFormField.js';
11
- import './fields/PdfButtonFormField.js';
12
- import './fields/PdfChoiceFormField.js';
13
- import './fields/PdfSignatureFormField.js';
9
+ import { PdfXfaForm } from './xfa/pdf-xfa-form.js';
10
+ import { PdfFormField } from './fields/pdf-form-field.js';
11
+ import './fields/pdf-text-form-field.js';
12
+ import './fields/pdf-button-form-field.js';
13
+ import './fields/pdf-choice-form-field.js';
14
+ import './fields/pdf-signature-form-field.js';
14
15
  import type { FormContext } from './fields/types.js';
15
16
  export type PdfDefaultResourcesDictionary = PdfDictionary<{
16
17
  Font?: PdfDictionary;
@@ -34,6 +35,7 @@ export declare class PdfAcroForm<T extends Record<string, string> = Record<strin
34
35
  fields: PdfFormField[];
35
36
  private _fontEncodingCache?;
36
37
  private document?;
38
+ private _xfa?;
37
39
  constructor(options?: {
38
40
  other?: PdfIndirectObject;
39
41
  fields?: PdfFormField[];
@@ -41,6 +43,8 @@ export declare class PdfAcroForm<T extends Record<string, string> = Record<strin
41
43
  });
42
44
  private get fontEncodingCache();
43
45
  get fontEncodingMaps(): Map<string, Map<number, string>>;
46
+ get fontRefs(): Map<string, PdfObjectReference>;
47
+ setXfa(xfa: PdfXfaForm | null): void;
44
48
  isModified(): boolean;
45
49
  get needAppearances(): boolean;
46
50
  set needAppearances(value: boolean);
@@ -56,8 +60,10 @@ export declare class PdfAcroForm<T extends Record<string, string> = Record<strin
56
60
  importData(fields: T): void;
57
61
  exportData(): Partial<T>;
58
62
  getFontEncodingMap(fontName: string): Promise<Map<number, string> | null>;
63
+ isFontUnicode(fontName: string): boolean;
59
64
  static fromDocument(document: PdfDocument): Promise<PdfAcroForm | null>;
60
65
  private cacheAllFontEncodings;
61
66
  private updatePageAnnotations;
62
- write(document: PdfDocument): Promise<void>;
67
+ getXfa(document?: PdfDocument): Promise<PdfXfaForm | null>;
68
+ write(document?: PdfDocument): Promise<void>;
63
69
  }