pdf-lite 1.4.0 → 1.6.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 (144) hide show
  1. package/EXAMPLES.md +51 -70
  2. package/README.md +1 -1
  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 +58 -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 +14 -0
  18. package/dist/acroform/fields/pdf-button-form-field.js +70 -0
  19. package/dist/acroform/fields/pdf-choice-form-field.d.ts +19 -0
  20. package/dist/acroform/fields/pdf-choice-form-field.js +112 -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} +37 -38
  24. package/dist/acroform/fields/pdf-form-field.js +519 -0
  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/{PdfTextFormField.js → pdf-text-form-field.js} +11 -13
  29. package/dist/acroform/fields/types.d.ts +6 -1
  30. package/dist/acroform/index.d.ts +1 -3
  31. package/dist/acroform/index.js +1 -3
  32. package/dist/acroform/pdf-acro-form.d.ts +45 -0
  33. package/dist/acroform/pdf-acro-form.js +203 -0
  34. package/dist/acroform/xfa/index.d.ts +3 -3
  35. package/dist/acroform/xfa/index.js +2 -2
  36. package/dist/acroform/xfa/{PdfXfaData.d.ts → pdf-xfa-data.d.ts} +4 -3
  37. package/dist/acroform/xfa/{PdfXfaData.js → pdf-xfa-data.js} +16 -12
  38. package/dist/acroform/xfa/pdf-xfa-form.d.ts +16 -0
  39. package/dist/acroform/xfa/pdf-xfa-form.js +34 -0
  40. package/dist/annotations/index.d.ts +3 -4
  41. package/dist/annotations/index.js +3 -4
  42. package/dist/annotations/{PdfAnnotationFlags.d.ts → pdf-annotation-flags.d.ts} +3 -4
  43. package/dist/annotations/{PdfAnnotationFlags.js → pdf-annotation-flags.js} +5 -6
  44. package/dist/annotations/{PdfAnnotation.d.ts → pdf-annotation.d.ts} +31 -5
  45. package/dist/annotations/{PdfAnnotation.js → pdf-annotation.js} +31 -19
  46. package/dist/annotations/pdf-default-resources.d.ts +11 -0
  47. package/dist/annotations/pdf-default-resources.js +3 -0
  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/decoder.js +1 -1
  51. package/dist/core/objects/pdf-array.d.ts +8 -1
  52. package/dist/core/objects/pdf-array.js +31 -0
  53. package/dist/core/objects/pdf-dictionary.d.ts +2 -0
  54. package/dist/core/objects/pdf-dictionary.js +14 -7
  55. package/dist/core/objects/pdf-hexadecimal.d.ts +1 -0
  56. package/dist/core/objects/pdf-hexadecimal.js +3 -3
  57. package/dist/core/objects/pdf-indirect-object.d.ts +18 -9
  58. package/dist/core/objects/pdf-indirect-object.js +75 -16
  59. package/dist/core/objects/pdf-number.d.ts +1 -0
  60. package/dist/core/objects/pdf-number.js +5 -4
  61. package/dist/core/objects/pdf-object-reference.d.ts +8 -1
  62. package/dist/core/objects/pdf-object-reference.js +14 -0
  63. package/dist/core/objects/pdf-object.d.ts +14 -0
  64. package/dist/core/objects/pdf-object.js +36 -0
  65. package/dist/core/objects/pdf-start-xref.d.ts +1 -0
  66. package/dist/core/objects/pdf-start-xref.js +4 -0
  67. package/dist/core/objects/pdf-stream.d.ts +44 -7
  68. package/dist/core/objects/pdf-stream.js +284 -26
  69. package/dist/core/objects/pdf-string.d.ts +1 -0
  70. package/dist/core/objects/pdf-string.js +3 -6
  71. package/dist/core/objects/pdf-trailer.d.ts +1 -0
  72. package/dist/core/objects/pdf-trailer.js +6 -3
  73. package/dist/core/objects/pdf-xref-table.js +1 -1
  74. package/dist/core/parser/incremental-parser.d.ts +0 -13
  75. package/dist/core/parser/incremental-parser.js +1 -18
  76. package/dist/core/ref.d.ts +3 -1
  77. package/dist/core/ref.js +8 -5
  78. package/dist/core/streams/object-stream.d.ts +1 -1
  79. package/dist/core/streams/object-stream.js +1 -1
  80. package/dist/core/tokens/token.d.ts +2 -1
  81. package/dist/core/tokens/token.js +3 -0
  82. package/dist/errors.d.ts +22 -0
  83. package/dist/errors.js +24 -0
  84. package/dist/fonts/index.d.ts +0 -1
  85. package/dist/fonts/index.js +0 -1
  86. package/dist/fonts/pdf-font.d.ts +94 -32
  87. package/dist/fonts/pdf-font.js +301 -83
  88. package/dist/index.d.ts +1 -0
  89. package/dist/index.js +1 -0
  90. package/dist/pdf/index.d.ts +2 -1
  91. package/dist/pdf/index.js +2 -1
  92. package/dist/pdf/pdf-document.d.ts +61 -36
  93. package/dist/pdf/pdf-document.js +315 -117
  94. package/dist/pdf/pdf-page.d.ts +50 -0
  95. package/dist/pdf/pdf-page.js +144 -0
  96. package/dist/pdf/pdf-pages.d.ts +28 -0
  97. package/dist/pdf/pdf-pages.js +94 -0
  98. package/dist/pdf/pdf-reader.d.ts +5 -1
  99. package/dist/pdf/pdf-reader.js +36 -2
  100. package/dist/pdf/pdf-revision.d.ts +3 -3
  101. package/dist/pdf/pdf-revision.js +7 -7
  102. package/dist/pdf/pdf-xref-lookup.js +34 -14
  103. package/dist/signing/document-security-store.d.ts +14 -17
  104. package/dist/signing/document-security-store.js +19 -34
  105. package/dist/signing/signer.d.ts +23 -8
  106. package/dist/signing/signer.js +51 -17
  107. package/dist/utils/encodePdfText.d.ts +17 -0
  108. package/dist/utils/encodePdfText.js +61 -0
  109. package/dist/utils/index.d.ts +1 -2
  110. package/dist/utils/index.js +1 -2
  111. package/dist/utils/needsCentralWhitespace.d.ts +10 -0
  112. package/dist/utils/needsCentralWhitespace.js +34 -0
  113. package/package.json +3 -3
  114. package/dist/acroform/PdfAcroForm.d.ts +0 -63
  115. package/dist/acroform/PdfAcroForm.js +0 -279
  116. package/dist/acroform/PdfFontEncodingCache.d.ts +0 -16
  117. package/dist/acroform/PdfFontEncodingCache.js +0 -75
  118. package/dist/acroform/acroform.d.ts +0 -9
  119. package/dist/acroform/acroform.js +0 -7
  120. package/dist/acroform/appearance/PdfButtonAppearanceStream.js +0 -54
  121. package/dist/acroform/appearance/PdfChoiceAppearanceStream.d.ts +0 -15
  122. package/dist/acroform/appearance/PdfChoiceAppearanceStream.js +0 -48
  123. package/dist/acroform/appearance/PdfTextAppearanceStream.js +0 -75
  124. package/dist/acroform/fields/PdfButtonFormField.d.ts +0 -9
  125. package/dist/acroform/fields/PdfButtonFormField.js +0 -35
  126. package/dist/acroform/fields/PdfChoiceFormField.d.ts +0 -9
  127. package/dist/acroform/fields/PdfChoiceFormField.js +0 -46
  128. package/dist/acroform/fields/PdfFormField.js +0 -499
  129. package/dist/acroform/manager.d.ts +0 -33
  130. package/dist/acroform/manager.js +0 -51
  131. package/dist/acroform/xfa/PdfXfaForm.d.ts +0 -12
  132. package/dist/acroform/xfa/PdfXfaForm.js +0 -64
  133. package/dist/annotations/PdfAnnotationWriter.d.ts +0 -20
  134. package/dist/annotations/PdfAnnotationWriter.js +0 -76
  135. package/dist/fonts/font-manager.d.ts +0 -127
  136. package/dist/fonts/font-manager.js +0 -378
  137. package/dist/pdf/errors.d.ts +0 -6
  138. package/dist/pdf/errors.js +0 -6
  139. package/dist/utils/predictors.d.ts +0 -113
  140. package/dist/utils/predictors.js +0 -279
  141. /package/dist/acroform/fields/{PdfDefaultAppearance.d.ts → pdf-default-appearance.d.ts} +0 -0
  142. /package/dist/acroform/fields/{PdfDefaultAppearance.js → pdf-default-appearance.js} +0 -0
  143. /package/dist/utils/{IterableReadableStream.d.ts → iterable-readable-stream.d.ts} +0 -0
  144. /package/dist/utils/{IterableReadableStream.js → iterable-readable-stream.js} +0 -0
@@ -1,7 +1,6 @@
1
- import { PdfFormField } from './PdfFormField.js';
2
- import { PdfDefaultAppearance } from './PdfDefaultAppearance.js';
3
- import { PdfTextAppearanceStream } from '../appearance/PdfTextAppearanceStream.js';
4
- import { PdfDictionary } from '../../core/objects/pdf-dictionary.js';
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';
5
4
  /**
6
5
  * Text form field subtype.
7
6
  */
@@ -21,14 +20,11 @@ export class PdfTextFormField extends PdfFormField {
21
20
  const parsed = PdfDefaultAppearance.parse(da);
22
21
  if (!parsed)
23
22
  return false;
24
- let fontResources;
25
- const drFontValue = this.form?.defaultResources?.get('Font');
26
- const drFonts = drFontValue instanceof PdfDictionary ? drFontValue : undefined;
27
- if (drFonts) {
28
- fontResources = new PdfDictionary();
29
- fontResources.set('Font', drFonts);
30
- }
31
- this._appearanceStream = new PdfTextAppearanceStream({
23
+ const font = this.font;
24
+ const fontResources = this.buildFontResources(parsed.fontName);
25
+ const isUnicode = font?.isUnicode ?? false;
26
+ const reverseEncodingMap = font?.reverseEncodingMap;
27
+ this.setAppearanceStream(new PdfTextAppearanceStream({
32
28
  rect: rect,
33
29
  value: this.value,
34
30
  da: parsed,
@@ -36,7 +32,9 @@ export class PdfTextFormField extends PdfFormField {
36
32
  comb: this.comb,
37
33
  maxLen: this.maxLen,
38
34
  fontResources,
39
- });
35
+ isUnicode,
36
+ reverseEncodingMap,
37
+ }));
40
38
  if (options?.makeReadOnly) {
41
39
  this.readOnly = true;
42
40
  if (!this.print)
@@ -1,4 +1,5 @@
1
- import type { PdfDefaultResourcesDictionary } from '../acroform.js';
1
+ import { PdfDefaultResourcesDictionary } from '../../annotations/pdf-default-resources.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,4 @@
1
- export * from './manager.js';
2
- export * from './PdfAcroForm.js';
1
+ export * from './pdf-acro-form.js';
3
2
  export * from './fields/index.js';
4
3
  export * from './appearance/index.js';
5
4
  export * from './xfa/index.js';
6
- export { PdfFontEncodingCache } from './PdfFontEncodingCache.js';
@@ -1,6 +1,4 @@
1
- export * from './manager.js';
2
- export * from './PdfAcroForm.js';
1
+ export * from './pdf-acro-form.js';
3
2
  export * from './fields/index.js';
4
3
  export * from './appearance/index.js';
5
4
  export * from './xfa/index.js';
6
- export { PdfFontEncodingCache } from './PdfFontEncodingCache.js';
@@ -0,0 +1,45 @@
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 { PdfObjectReference } from '../core/objects/pdf-object-reference.js';
5
+ import { PdfIndirectObject } from '../core/objects/pdf-indirect-object.js';
6
+ import { PdfBoolean } from '../core/objects/pdf-boolean.js';
7
+ import { PdfNumber } from '../core/objects/pdf-number.js';
8
+ import { PdfFormField } from './fields/pdf-form-field.js';
9
+ import './fields/pdf-text-form-field.js';
10
+ import './fields/pdf-button-form-field.js';
11
+ import './fields/pdf-choice-form-field.js';
12
+ import './fields/pdf-signature-form-field.js';
13
+ import { PdfDefaultResourcesDictionary } from '../annotations/pdf-default-resources.js';
14
+ import { PdfXfaForm } from './xfa/pdf-xfa-form.js';
15
+ export declare class PdfAcroForm<T extends Record<string, string> = Record<string, string>> extends PdfIndirectObject<PdfDictionary<{
16
+ Fields: PdfArray<PdfObjectReference> | PdfObjectReference;
17
+ NeedAppearances?: PdfBoolean;
18
+ SigFlags?: PdfNumber;
19
+ CO?: PdfArray<PdfObjectReference>;
20
+ DR?: PdfDefaultResourcesDictionary;
21
+ DA?: PdfString;
22
+ Q?: PdfNumber;
23
+ XFA?: PdfArray<PdfObjectReference>;
24
+ }>> {
25
+ constructor(options?: PdfIndirectObject);
26
+ get needAppearances(): boolean;
27
+ set needAppearances(value: boolean);
28
+ get signatureFlags(): number;
29
+ set signatureFlags(flags: number);
30
+ get defaultAppearance(): string | null;
31
+ set defaultAppearance(da: string);
32
+ get defaultQuadding(): number;
33
+ set defaultQuadding(q: number);
34
+ get defaultResources(): PdfDefaultResourcesDictionary | null;
35
+ set defaultResources(resources: PdfDefaultResourcesDictionary | null);
36
+ get fields(): ReadonlyArray<PdfFormField>;
37
+ addField(...fields: PdfFormField[]): void;
38
+ set fields(newFields: PdfFormField[]);
39
+ setValues(values: Partial<T>): void;
40
+ importData(fields: T): void;
41
+ exportData(): Partial<T>;
42
+ fontEncodingMaps: Map<string, Map<number, string>>;
43
+ getFontEncodingMap(fontName: string): Map<number, string> | null;
44
+ get xfa(): PdfXfaForm | null;
45
+ }
@@ -0,0 +1,203 @@
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 { PdfObjectReference } from '../core/objects/pdf-object-reference.js';
5
+ import { PdfIndirectObject } from '../core/objects/pdf-indirect-object.js';
6
+ import { PdfBoolean } from '../core/objects/pdf-boolean.js';
7
+ import { PdfNumber } from '../core/objects/pdf-number.js';
8
+ import { PdfFormField } from './fields/pdf-form-field.js';
9
+ // Import subclasses to trigger static registration blocks
10
+ import './fields/pdf-text-form-field.js';
11
+ import './fields/pdf-button-form-field.js';
12
+ import './fields/pdf-choice-form-field.js';
13
+ import './fields/pdf-signature-form-field.js';
14
+ import { buildEncodingMap } from '../utils/decodeWithFontEncoding.js';
15
+ import { PdfXfaForm } from './xfa/pdf-xfa-form.js';
16
+ export class PdfAcroForm extends PdfIndirectObject {
17
+ constructor(options) {
18
+ super(options ??
19
+ new PdfIndirectObject({
20
+ content: new PdfDictionary(),
21
+ }));
22
+ }
23
+ get needAppearances() {
24
+ return (this.content.get('NeedAppearances')?.as(PdfBoolean)?.value ?? false);
25
+ }
26
+ set needAppearances(value) {
27
+ this.content.set('NeedAppearances', new PdfBoolean(value));
28
+ }
29
+ get signatureFlags() {
30
+ return this.content.get('SigFlags')?.as(PdfNumber)?.value ?? 0;
31
+ }
32
+ set signatureFlags(flags) {
33
+ this.content.set('SigFlags', new PdfNumber(flags));
34
+ }
35
+ get defaultAppearance() {
36
+ return this.content.get('DA')?.as(PdfString)?.value ?? null;
37
+ }
38
+ set defaultAppearance(da) {
39
+ this.content.set('DA', new PdfString(da));
40
+ }
41
+ get defaultQuadding() {
42
+ return this.content.get('Q')?.as(PdfNumber)?.value ?? 0;
43
+ }
44
+ set defaultQuadding(q) {
45
+ this.content.set('Q', new PdfNumber(q));
46
+ }
47
+ get defaultResources() {
48
+ return this.content.get('DR')?.as(PdfDictionary) ?? null;
49
+ }
50
+ set defaultResources(resources) {
51
+ if (resources === null) {
52
+ this.content.delete('DR');
53
+ }
54
+ else {
55
+ this.content.set('DR', resources);
56
+ }
57
+ }
58
+ get fields() {
59
+ const result = [];
60
+ const seen = new Set();
61
+ const collect = (refs) => {
62
+ for (const ref of refs) {
63
+ const key = ref.key;
64
+ if (seen.has(key))
65
+ continue;
66
+ seen.add(key);
67
+ const resolved = ref.resolve();
68
+ if (!(resolved?.content instanceof PdfDictionary))
69
+ continue;
70
+ const dict = resolved.content;
71
+ const tEntry = dict.get('T');
72
+ const tValue = tEntry instanceof PdfString ? tEntry.value : null;
73
+ const hasFt = dict.has('FT');
74
+ if (tValue) {
75
+ const field = PdfFormField.create(resolved);
76
+ field.form = this;
77
+ result.push(field);
78
+ }
79
+ // Only recurse into Kids for non-terminal (group) fields — those
80
+ // without FT. Terminal fields may have Kids that are pure widget
81
+ // annotations (no T) which would produce duplicate names.
82
+ if (!hasFt) {
83
+ const kids = dict.get('Kids');
84
+ if (kids instanceof PdfArray && kids.items.length > 0) {
85
+ collect(kids.items);
86
+ }
87
+ }
88
+ }
89
+ };
90
+ const fieldsRaw = this.content.get('Fields');
91
+ const resolvedFields = fieldsRaw instanceof PdfObjectReference
92
+ ? fieldsRaw.resolve()?.content
93
+ : fieldsRaw;
94
+ collect(resolvedFields instanceof PdfArray
95
+ ? resolvedFields.items
96
+ : []);
97
+ return result;
98
+ }
99
+ addField(...fields) {
100
+ const content = this.content;
101
+ const fieldsRaw = content.get('Fields');
102
+ let fieldsArray = fieldsRaw instanceof PdfObjectReference
103
+ ? fieldsRaw.resolve()?.content
104
+ : fieldsRaw;
105
+ if (!fieldsArray) {
106
+ fieldsArray = new PdfArray();
107
+ content.set('Fields', fieldsArray);
108
+ }
109
+ for (const field of fields) {
110
+ fieldsArray.items.push(field.reference);
111
+ // Auto-add to the page's Annots array
112
+ const page = field.page;
113
+ if (page) {
114
+ page.annotations.items.push(field.reference);
115
+ }
116
+ }
117
+ }
118
+ set fields(newFields) {
119
+ this.content.set('Fields', PdfArray.refs(newFields));
120
+ }
121
+ setValues(values) {
122
+ for (const field of this.fields) {
123
+ const name = field.name;
124
+ if (name in values && values[name] !== undefined) {
125
+ field.value = values[name];
126
+ }
127
+ }
128
+ }
129
+ importData(fields) {
130
+ for (const field of this.fields) {
131
+ const name = field.name;
132
+ if (name && name in fields) {
133
+ field.value = fields[name];
134
+ }
135
+ }
136
+ }
137
+ exportData() {
138
+ const result = {};
139
+ for (const field of this.fields) {
140
+ const name = field.name;
141
+ if (name) {
142
+ result[name] = field.value;
143
+ }
144
+ }
145
+ return result;
146
+ }
147
+ fontEncodingMaps = new Map();
148
+ getFontEncodingMap(fontName) {
149
+ if (this.fontEncodingMaps.has(fontName)) {
150
+ return this.fontEncodingMaps.get(fontName);
151
+ }
152
+ const dr = this.defaultResources;
153
+ const fontRaw = dr?.get('Font');
154
+ let fontDict;
155
+ if (fontRaw instanceof PdfObjectReference) {
156
+ const resolved = fontRaw.resolve()?.content;
157
+ if (resolved instanceof PdfDictionary)
158
+ fontDict = resolved;
159
+ }
160
+ else if (fontRaw instanceof PdfDictionary) {
161
+ fontDict = fontRaw;
162
+ }
163
+ if (!fontDict)
164
+ return null;
165
+ const fontEntry = fontDict.get(fontName);
166
+ if (!fontEntry)
167
+ return null;
168
+ let fontObj;
169
+ if (fontEntry instanceof PdfObjectReference) {
170
+ const resolved = fontEntry.resolve();
171
+ if (resolved?.content instanceof PdfDictionary) {
172
+ fontObj = resolved.content;
173
+ }
174
+ }
175
+ else if (fontEntry instanceof PdfDictionary) {
176
+ fontObj = fontEntry;
177
+ }
178
+ if (!fontObj)
179
+ return null;
180
+ let encObj = fontObj.get('Encoding');
181
+ if (encObj instanceof PdfObjectReference) {
182
+ encObj = encObj.resolve()?.content;
183
+ }
184
+ const encDict = encObj instanceof PdfDictionary ? encObj : undefined;
185
+ const diffs = encDict?.get('Differences')?.as(PdfArray);
186
+ if (!diffs)
187
+ return null;
188
+ const map = buildEncodingMap(diffs);
189
+ if (map) {
190
+ this.fontEncodingMaps.set(fontName, map);
191
+ }
192
+ return map;
193
+ }
194
+ get xfa() {
195
+ const xfaEntry = this.content.get('XFA');
196
+ if (!xfaEntry)
197
+ return null;
198
+ if (!(xfaEntry instanceof PdfArray)) {
199
+ return null;
200
+ }
201
+ return new PdfXfaForm(xfaEntry);
202
+ }
203
+ }
@@ -1,3 +1,3 @@
1
- export { PdfXfaForm } from './PdfXfaForm.js';
2
- export { PdfXfaData } from './PdfXfaData.js';
3
- export type { XfaFieldData } from './PdfXfaData.js';
1
+ export { PdfXfaForm } from './pdf-xfa-form.js';
2
+ export { PdfXfaData } from './pdf-xfa-data.js';
3
+ export type { XfaFieldData } from './pdf-xfa-data.js';
@@ -1,2 +1,2 @@
1
- export { PdfXfaForm } from './PdfXfaForm.js';
2
- export { PdfXfaData } from './PdfXfaData.js';
1
+ export { PdfXfaForm } from './pdf-xfa-form.js';
2
+ export { PdfXfaData } from './pdf-xfa-data.js';
@@ -9,12 +9,13 @@ export interface XfaFieldData {
9
9
  * Provides methods to read/write XML and update individual field values.
10
10
  */
11
11
  export declare class PdfXfaData extends PdfIndirectObject<PdfStream> {
12
- constructor(stream: PdfIndirectObject<PdfStream>);
13
- readXml(): string;
14
- writeXml(xml: string): void;
12
+ constructor(stream: PdfIndirectObject);
13
+ get xml(): string;
14
+ set xml(xml: string);
15
15
  updateField(name: string, value: string): void;
16
16
  updateFields(fields: XfaFieldData[]): void;
17
17
  getFieldValue(name: string): string | null;
18
+ importData(fields: Record<string, string | undefined>): void;
18
19
  private static updateFieldValue;
19
20
  private static escapeRegex;
20
21
  }
@@ -1,5 +1,4 @@
1
1
  import { PdfIndirectObject } from '../../core/objects/pdf-indirect-object.js';
2
- import { PdfStream } from '../../core/objects/pdf-stream.js';
3
2
  /**
4
3
  * Wraps an XFA datasets stream as a typed PDF indirect object.
5
4
  * Provides methods to read/write XML and update individual field values.
@@ -8,29 +7,26 @@ export class PdfXfaData extends PdfIndirectObject {
8
7
  constructor(stream) {
9
8
  super(stream);
10
9
  }
11
- readXml() {
12
- const decompressed = this.content.decode();
13
- return new TextDecoder().decode(decompressed);
10
+ get xml() {
11
+ return this.content.dataAsString;
14
12
  }
15
- writeXml(xml) {
16
- this.content = PdfStream.fromString(xml);
13
+ set xml(xml) {
14
+ this.content.dataAsString = xml;
17
15
  }
18
16
  updateField(name, value) {
19
- let xml = this.readXml();
20
- xml = PdfXfaData.updateFieldValue(xml, name, value);
21
- this.writeXml(xml);
17
+ this.xml = PdfXfaData.updateFieldValue(this.xml, name, value);
22
18
  }
23
19
  updateFields(fields) {
24
20
  if (fields.length === 0)
25
21
  return;
26
- let xml = this.readXml();
22
+ let xml = this.xml;
27
23
  for (const { name, value } of fields) {
28
24
  xml = PdfXfaData.updateFieldValue(xml, name, value);
29
25
  }
30
- this.writeXml(xml);
26
+ this.xml = xml;
31
27
  }
32
28
  getFieldValue(name) {
33
- const xml = this.readXml();
29
+ const xml = this.xml;
34
30
  const segments = name.split('.');
35
31
  const leafSegment = segments[segments.length - 1];
36
32
  const leafName = leafSegment.replace(/\[\d+\]$/, '');
@@ -40,6 +36,14 @@ export class PdfXfaData extends PdfIndirectObject {
40
36
  const match = xml.match(contentRegex);
41
37
  return match ? match[1] : null;
42
38
  }
39
+ importData(fields) {
40
+ for (const field in fields) {
41
+ const value = fields[field];
42
+ if (value === undefined)
43
+ continue;
44
+ this.updateField(field, value);
45
+ }
46
+ }
43
47
  static updateFieldValue(xml, fieldName, value) {
44
48
  const segments = fieldName.split('.');
45
49
  const leafSegment = segments[segments.length - 1];
@@ -0,0 +1,16 @@
1
+ import { PdfArray } from '../../core/objects/pdf-array.js';
2
+ import { PdfObjectReference } from '../../core/objects/pdf-object-reference.js';
3
+ import { PdfIndirectObject } from '../../core/objects/pdf-indirect-object.js';
4
+ import { PdfXfaData } from './pdf-xfa-data.js';
5
+ /**
6
+ * Typed wrapper around the XFA name/stream-ref array.
7
+ * Holds eagerly-loaded references to component streams like datasets.
8
+ */
9
+ export declare class PdfXfaForm {
10
+ private xfaEntry?;
11
+ constructor(xfaEntry?: PdfArray<PdfObjectReference>);
12
+ get components(): {
13
+ [type: string]: PdfIndirectObject;
14
+ };
15
+ get datasets(): PdfXfaData | null;
16
+ }
@@ -0,0 +1,34 @@
1
+ import { PdfString } from '../../core/objects/pdf-string.js';
2
+ import { PdfObjectReference } from '../../core/objects/pdf-object-reference.js';
3
+ import { PdfIndirectObject } from '../../core/objects/pdf-indirect-object.js';
4
+ import { PdfXfaData } from './pdf-xfa-data.js';
5
+ /**
6
+ * Typed wrapper around the XFA name/stream-ref array.
7
+ * Holds eagerly-loaded references to component streams like datasets.
8
+ */
9
+ export class PdfXfaForm {
10
+ xfaEntry;
11
+ constructor(xfaEntry) {
12
+ this.xfaEntry = xfaEntry;
13
+ }
14
+ get components() {
15
+ const result = {};
16
+ const items = this.xfaEntry?.items ?? [];
17
+ for (let i = 0; i < items.length - 1; i += 2) {
18
+ const name = items[i];
19
+ const ref = items[i + 1];
20
+ if (name instanceof PdfString &&
21
+ ref instanceof PdfObjectReference) {
22
+ result[name.value] = ref.resolve().as(PdfIndirectObject);
23
+ }
24
+ }
25
+ return result;
26
+ }
27
+ get datasets() {
28
+ const datasetsRef = this.components['datasets'];
29
+ if (!datasetsRef) {
30
+ return null;
31
+ }
32
+ return datasetsRef.becomes(PdfXfaData);
33
+ }
34
+ }
@@ -1,4 +1,3 @@
1
- export { PdfAnnotation, type PdfAppearanceStreamDictionary, } from './PdfAnnotation.js';
2
- export { PdfAnnotationFlags } from './PdfAnnotationFlags.js';
3
- export { PdfWidgetAnnotation } from './PdfWidgetAnnotation.js';
4
- export { PdfAnnotationWriter } from './PdfAnnotationWriter.js';
1
+ export { PdfAnnotation, type PdfAppearanceStreamDictionary, } from './pdf-annotation.js';
2
+ export { PdfAnnotationFlags } from './pdf-annotation-flags.js';
3
+ export { PdfWidgetAnnotation } from './pdf-widget-annotation.js';
@@ -1,4 +1,3 @@
1
- export { PdfAnnotation, } from './PdfAnnotation.js';
2
- export { PdfAnnotationFlags } from './PdfAnnotationFlags.js';
3
- export { PdfWidgetAnnotation } from './PdfWidgetAnnotation.js';
4
- export { PdfAnnotationWriter } from './PdfAnnotationWriter.js';
1
+ export { PdfAnnotation, } from './pdf-annotation.js';
2
+ export { PdfAnnotationFlags } from './pdf-annotation-flags.js';
3
+ export { PdfWidgetAnnotation } from './pdf-widget-annotation.js';
@@ -1,11 +1,10 @@
1
- import { PdfDictionary } from '../core/objects/pdf-dictionary.js';
1
+ import { PdfNumber } from '../core/objects/pdf-number.js';
2
2
  /**
3
3
  * Provides annotation flag (F field) accessors for PDF annotations.
4
4
  * These are generic to all annotation types per the PDF spec.
5
5
  */
6
- export declare class PdfAnnotationFlags {
7
- readonly dict: PdfDictionary;
8
- constructor(dict: PdfDictionary);
6
+ export declare class PdfAnnotationFlags extends PdfNumber {
7
+ constructor(value?: number);
9
8
  get annotationFlags(): number;
10
9
  set annotationFlags(flags: number);
11
10
  get invisible(): boolean;
@@ -3,16 +3,15 @@ import { PdfNumber } from '../core/objects/pdf-number.js';
3
3
  * Provides annotation flag (F field) accessors for PDF annotations.
4
4
  * These are generic to all annotation types per the PDF spec.
5
5
  */
6
- export class PdfAnnotationFlags {
7
- dict;
8
- constructor(dict) {
9
- this.dict = dict;
6
+ export class PdfAnnotationFlags extends PdfNumber {
7
+ constructor(value = 0) {
8
+ super(value);
10
9
  }
11
10
  get annotationFlags() {
12
- return this.dict.get('F')?.as(PdfNumber)?.value ?? 0;
11
+ return this.value;
13
12
  }
14
13
  set annotationFlags(flags) {
15
- this.dict.set('F', new PdfNumber(flags));
14
+ this.value = flags;
16
15
  }
17
16
  get invisible() {
18
17
  return (this.annotationFlags & 1) !== 0;
@@ -1,6 +1,11 @@
1
1
  import { PdfDictionary } from '../core/objects/pdf-dictionary.js';
2
2
  import { PdfIndirectObject } from '../core/objects/pdf-indirect-object.js';
3
3
  import { PdfObjectReference } from '../core/objects/pdf-object-reference.js';
4
+ import { PdfArray } from '../core/objects/pdf-array.js';
5
+ import { PdfNumber } from '../core/objects/pdf-number.js';
6
+ import { PdfName } from '../core/objects/pdf-name.js';
7
+ import { PdfString } from '../core/objects/pdf-string.js';
8
+ import { PdfPage } from '../pdf/pdf-page.js';
4
9
  export type PdfAppearanceStreamDictionary = PdfDictionary<{
5
10
  N: PdfObjectReference | PdfDictionary;
6
11
  R?: PdfObjectReference | PdfDictionary;
@@ -8,15 +13,35 @@ export type PdfAppearanceStreamDictionary = PdfDictionary<{
8
13
  }>;
9
14
  /**
10
15
  * Base class for all PDF annotations.
11
- * Owns: Rect, annotation flags (F), AP (appearance streams), P (page reference).
12
16
  */
13
- export declare class PdfAnnotation extends PdfIndirectObject<PdfDictionary> {
14
- private _annotationFlags;
17
+ export declare class PdfAnnotation extends PdfIndirectObject<PdfDictionary<{
18
+ Type: PdfName;
19
+ Subtype: PdfName;
20
+ AS: PdfName;
21
+ Ff: PdfNumber;
22
+ FT: PdfName;
23
+ T: PdfString;
24
+ DV: PdfString | PdfName;
25
+ V: PdfString | PdfName;
26
+ DA: PdfString;
27
+ DR: PdfDictionary | PdfObjectReference;
28
+ Opt: PdfArray<PdfString | PdfArray<PdfString>> | PdfObjectReference;
29
+ MaxLen: PdfNumber;
30
+ Q: PdfNumber;
31
+ Kids: PdfArray<PdfObjectReference>;
32
+ Rect: PdfArray<PdfNumber>;
33
+ F: PdfNumber;
34
+ AP?: PdfAppearanceStreamDictionary;
35
+ P?: PdfObjectReference;
36
+ Parent?: PdfObjectReference<PdfPage>;
37
+ }>> {
38
+ private _annotationFlags?;
39
+ private get flags_();
15
40
  constructor(options?: {
16
41
  other?: PdfIndirectObject;
17
42
  });
18
- get rect(): number[] | null;
19
- set rect(rect: number[] | null);
43
+ get rect(): [number, number, number, number] | null;
44
+ set rect(rect: [number, number, number, number] | null);
20
45
  get annotationFlags(): number;
21
46
  set annotationFlags(flags: number);
22
47
  get invisible(): boolean;
@@ -37,4 +62,5 @@ export declare class PdfAnnotation extends PdfIndirectObject<PdfDictionary> {
37
62
  set appearanceStreamDict(dict: PdfAppearanceStreamDictionary | null);
38
63
  get parentRef(): PdfObjectReference | null;
39
64
  set parentRef(ref: PdfObjectReference | null);
65
+ get page(): PdfPage | null;
40
66
  }