pdf-lite 1.5.0 → 1.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/EXAMPLES.md +51 -70
- package/README.md +1 -1
- package/dist/acroform/appearance/pdf-button-appearance-stream.d.ts +1 -1
- package/dist/acroform/appearance/pdf-button-appearance-stream.js +6 -2
- package/dist/acroform/fields/pdf-button-form-field.d.ts +0 -9
- package/dist/acroform/fields/pdf-button-form-field.js +7 -39
- package/dist/acroform/fields/pdf-choice-form-field.d.ts +2 -1
- package/dist/acroform/fields/pdf-choice-form-field.js +19 -38
- package/dist/acroform/fields/pdf-default-appearance.js +1 -1
- package/dist/acroform/fields/pdf-form-field.d.ts +27 -32
- package/dist/acroform/fields/pdf-form-field.js +180 -94
- package/dist/acroform/fields/pdf-text-form-field.js +6 -33
- package/dist/acroform/fields/types.d.ts +1 -1
- package/dist/acroform/index.d.ts +0 -2
- package/dist/acroform/index.js +0 -2
- package/dist/acroform/pdf-acro-form.d.ts +12 -36
- package/dist/acroform/pdf-acro-form.js +111 -201
- package/dist/acroform/xfa/pdf-xfa-data.d.ts +4 -3
- package/dist/acroform/xfa/pdf-xfa-data.js +16 -12
- package/dist/acroform/xfa/pdf-xfa-form.d.ts +9 -4
- package/dist/acroform/xfa/pdf-xfa-form.js +17 -39
- package/dist/annotations/index.d.ts +0 -1
- package/dist/annotations/index.js +0 -1
- package/dist/annotations/pdf-annotation.d.ts +7 -2
- package/dist/annotations/pdf-annotation.js +30 -19
- package/dist/annotations/pdf-default-resources.d.ts +11 -0
- package/dist/annotations/pdf-default-resources.js +3 -0
- package/dist/core/decoder.js +1 -1
- package/dist/core/objects/pdf-array.d.ts +8 -1
- package/dist/core/objects/pdf-array.js +31 -0
- package/dist/core/objects/pdf-dictionary.d.ts +2 -0
- package/dist/core/objects/pdf-dictionary.js +14 -7
- package/dist/core/objects/pdf-hexadecimal.d.ts +1 -0
- package/dist/core/objects/pdf-hexadecimal.js +3 -3
- package/dist/core/objects/pdf-indirect-object.d.ts +18 -9
- package/dist/core/objects/pdf-indirect-object.js +75 -16
- package/dist/core/objects/pdf-number.d.ts +1 -0
- package/dist/core/objects/pdf-number.js +5 -4
- package/dist/core/objects/pdf-object-reference.d.ts +8 -1
- package/dist/core/objects/pdf-object-reference.js +14 -0
- package/dist/core/objects/pdf-object.d.ts +14 -0
- package/dist/core/objects/pdf-object.js +36 -0
- package/dist/core/objects/pdf-start-xref.d.ts +1 -0
- package/dist/core/objects/pdf-start-xref.js +4 -0
- package/dist/core/objects/pdf-stream.d.ts +47 -7
- package/dist/core/objects/pdf-stream.js +301 -32
- package/dist/core/objects/pdf-string.d.ts +1 -0
- package/dist/core/objects/pdf-string.js +3 -6
- package/dist/core/objects/pdf-trailer.d.ts +1 -0
- package/dist/core/objects/pdf-trailer.js +6 -3
- package/dist/core/objects/pdf-xref-table.js +1 -1
- package/dist/core/ref.d.ts +3 -1
- package/dist/core/ref.js +8 -5
- package/dist/core/tokens/token.d.ts +2 -1
- package/dist/core/tokens/token.js +3 -0
- package/dist/fonts/index.d.ts +0 -1
- package/dist/fonts/index.js +0 -1
- package/dist/fonts/pdf-font.d.ts +32 -27
- package/dist/fonts/pdf-font.js +115 -77
- package/dist/pdf/index.d.ts +2 -0
- package/dist/pdf/index.js +2 -0
- package/dist/pdf/pdf-document.d.ts +63 -37
- package/dist/pdf/pdf-document.js +351 -135
- package/dist/pdf/pdf-page.d.ts +50 -0
- package/dist/pdf/pdf-page.js +144 -0
- package/dist/pdf/pdf-pages.d.ts +28 -0
- package/dist/pdf/pdf-pages.js +94 -0
- package/dist/pdf/pdf-reader.d.ts +5 -1
- package/dist/pdf/pdf-reader.js +36 -2
- package/dist/pdf/pdf-revision.d.ts +3 -3
- package/dist/pdf/pdf-revision.js +7 -7
- package/dist/pdf/pdf-xref-lookup.js +34 -14
- package/dist/signing/document-security-store.d.ts +14 -17
- package/dist/signing/document-security-store.js +19 -34
- package/dist/signing/signer.d.ts +23 -8
- package/dist/signing/signer.js +51 -17
- package/dist/utils/index.d.ts +0 -1
- package/dist/utils/index.js +0 -1
- package/dist/utils/needsCentralWhitespace.d.ts +10 -0
- package/dist/utils/needsCentralWhitespace.js +34 -0
- package/package.json +3 -3
- package/dist/acroform/acroform.d.ts +0 -9
- package/dist/acroform/acroform.js +0 -7
- package/dist/acroform/manager.d.ts +0 -37
- package/dist/acroform/manager.js +0 -57
- package/dist/acroform/pdf-font-encoding-cache.d.ts +0 -27
- package/dist/acroform/pdf-font-encoding-cache.js +0 -188
- package/dist/annotations/pdf-annotation-writer.d.ts +0 -20
- package/dist/annotations/pdf-annotation-writer.js +0 -76
- package/dist/fonts/manager.d.ts +0 -127
- package/dist/fonts/manager.js +0 -378
- package/dist/utils/predictors.d.ts +0 -113
- package/dist/utils/predictors.js +0 -279
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { PdfDictionary } from '../../core/objects/pdf-dictionary.js';
|
|
2
2
|
import { PdfArray } from '../../core/objects/pdf-array.js';
|
|
3
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';
|
|
4
6
|
import { PdfName } from '../../core/objects/pdf-name.js';
|
|
5
7
|
import { PdfNumber } from '../../core/objects/pdf-number.js';
|
|
8
|
+
import { PdfFont } from '../../fonts/pdf-font.js';
|
|
9
|
+
import { PdfStream } from '../../core/objects/pdf-stream.js';
|
|
6
10
|
import { decodeWithFontEncoding } from '../../utils/decodeWithFontEncoding.js';
|
|
7
11
|
import { PdfWidgetAnnotation } from '../../annotations/pdf-widget-annotation.js';
|
|
8
12
|
import { PdfDefaultAppearance } from './pdf-default-appearance.js';
|
|
@@ -14,63 +18,141 @@ import { PdfFormFieldFlags } from './pdf-form-field-flags.js';
|
|
|
14
18
|
* Subclasses must implement generateAppearance().
|
|
15
19
|
*/
|
|
16
20
|
export class PdfFormField extends PdfWidgetAnnotation {
|
|
17
|
-
_parent;
|
|
18
21
|
defaultGenerateAppearance = true;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
if (options?.parent) {
|
|
26
|
-
this._parent = options.parent;
|
|
22
|
+
/** @internal */
|
|
23
|
+
_form;
|
|
24
|
+
constructor(other) {
|
|
25
|
+
super();
|
|
26
|
+
if (other && !(other instanceof PdfIndirectObject)) {
|
|
27
|
+
this._form = other.form;
|
|
27
28
|
}
|
|
28
29
|
}
|
|
30
|
+
set form(f) {
|
|
31
|
+
this._form = f;
|
|
32
|
+
}
|
|
33
|
+
static create(other) {
|
|
34
|
+
if (!(other?.content instanceof PdfDictionary))
|
|
35
|
+
throw new Error('Invalid form field object');
|
|
36
|
+
const ft = other?.content.get('FT')?.as(PdfName)?.value;
|
|
37
|
+
const cls = ft ? PdfFormField._registry.get(ft) : undefined;
|
|
38
|
+
if (!cls) {
|
|
39
|
+
if (PdfFormField._fallbackCtor) {
|
|
40
|
+
return other.becomes(PdfFormField._fallbackCtor);
|
|
41
|
+
}
|
|
42
|
+
throw new Error(`Unsupported form field type: ${ft ?? 'unknown'}`);
|
|
43
|
+
}
|
|
44
|
+
return other.becomes(cls);
|
|
45
|
+
}
|
|
29
46
|
get parent() {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if (!this.form)
|
|
47
|
+
const resolved = this.content.get('Parent')?.resolve();
|
|
48
|
+
if (!resolved || !(resolved.content instanceof PdfDictionary))
|
|
33
49
|
return undefined;
|
|
34
|
-
return
|
|
35
|
-
f.kids.some((k) => k.objectNumber === this.objectNumber &&
|
|
36
|
-
k.generationNumber === this.generationNumber));
|
|
50
|
+
return PdfFormField.create(resolved);
|
|
37
51
|
}
|
|
38
52
|
set parent(field) {
|
|
39
|
-
if (
|
|
40
|
-
this.
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
this.
|
|
44
|
-
if (field) {
|
|
45
|
-
|
|
46
|
-
k.generationNumber === this.generationNumber);
|
|
47
|
-
if (!alreadyInKids) {
|
|
48
|
-
field.kids = [...field.kids, this.reference];
|
|
49
|
-
}
|
|
53
|
+
if (!field) {
|
|
54
|
+
this.content.delete('Parent');
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
this.content.set('Parent', field.reference);
|
|
58
|
+
if (field instanceof PdfFormField) {
|
|
59
|
+
field.children = [...field.children, this];
|
|
50
60
|
}
|
|
51
61
|
}
|
|
52
62
|
get children() {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
63
|
+
const kids = this.content.get('Kids')?.items ?? [];
|
|
64
|
+
const result = [];
|
|
65
|
+
for (const ref of kids) {
|
|
66
|
+
const resolved = ref.resolve();
|
|
67
|
+
if (!resolved || !(resolved.content instanceof PdfDictionary))
|
|
68
|
+
continue;
|
|
69
|
+
result.push(PdfFormField.create(resolved));
|
|
70
|
+
}
|
|
71
|
+
return result;
|
|
56
72
|
}
|
|
57
73
|
set children(fields) {
|
|
58
|
-
|
|
59
|
-
|
|
74
|
+
if (fields.length === 0) {
|
|
75
|
+
this.content.delete('Kids');
|
|
76
|
+
return;
|
|
60
77
|
}
|
|
61
|
-
this.
|
|
78
|
+
this.content.set('Kids', PdfArray.refs(fields));
|
|
62
79
|
for (const child of fields) {
|
|
63
|
-
child.
|
|
80
|
+
child.content.set('Parent', this.reference);
|
|
64
81
|
}
|
|
65
82
|
}
|
|
66
83
|
get siblings() {
|
|
67
84
|
return this.parent?.children ?? [];
|
|
68
85
|
}
|
|
69
|
-
get
|
|
86
|
+
get font() {
|
|
70
87
|
const fontName = this.fontName;
|
|
71
88
|
if (!fontName)
|
|
72
|
-
return
|
|
73
|
-
|
|
89
|
+
return null;
|
|
90
|
+
// Try resolving from default resources (DR) dict
|
|
91
|
+
const dr = this.defaultResources;
|
|
92
|
+
const fontDict = dr?.get('Font');
|
|
93
|
+
if (fontDict instanceof PdfDictionary) {
|
|
94
|
+
const fontEntry = fontDict.get(fontName);
|
|
95
|
+
if (fontEntry instanceof PdfObjectReference) {
|
|
96
|
+
const resolved = fontEntry.resolve();
|
|
97
|
+
if (resolved?.content instanceof PdfDictionary) {
|
|
98
|
+
const font = resolved.becomes(PdfFont);
|
|
99
|
+
font.resourceName = fontName;
|
|
100
|
+
return font;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
// Fallback: standard font lookup (Helv, Helvetica, ZaDb, etc.)
|
|
105
|
+
return PdfFont.getStandardFont(fontName) ?? null;
|
|
106
|
+
}
|
|
107
|
+
get defaultResources() {
|
|
108
|
+
const dr = this.content.get('DR');
|
|
109
|
+
const drDict = dr instanceof PdfObjectReference ? dr.resolve()?.content : dr;
|
|
110
|
+
return ((drDict instanceof PdfDictionary ? drDict : null) ??
|
|
111
|
+
this.parent?.defaultResources ??
|
|
112
|
+
this._form?.defaultResources ??
|
|
113
|
+
null);
|
|
114
|
+
}
|
|
115
|
+
set defaultResources(resources) {
|
|
116
|
+
if (resources === null) {
|
|
117
|
+
this.content.delete('DR');
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
this.content.set('DR', resources);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Builds a Resources dictionary containing the font entry for `fontName`,
|
|
125
|
+
* resolved from DR (handling indirect references) or from a loaded font.
|
|
126
|
+
* Returns undefined if neither source provides the font.
|
|
127
|
+
*/
|
|
128
|
+
buildFontResources(fontName) {
|
|
129
|
+
const dr = this.defaultResources;
|
|
130
|
+
const fontRaw = dr?.get('Font');
|
|
131
|
+
let drFontDict;
|
|
132
|
+
if (fontRaw instanceof PdfObjectReference) {
|
|
133
|
+
const resolved = fontRaw.resolve()?.content;
|
|
134
|
+
if (resolved instanceof PdfDictionary)
|
|
135
|
+
drFontDict = resolved;
|
|
136
|
+
}
|
|
137
|
+
else if (fontRaw instanceof PdfDictionary) {
|
|
138
|
+
drFontDict = fontRaw;
|
|
139
|
+
}
|
|
140
|
+
if (drFontDict && drFontDict.get(fontName)) {
|
|
141
|
+
const resFontDict = new PdfDictionary();
|
|
142
|
+
resFontDict.set(fontName, drFontDict.get(fontName));
|
|
143
|
+
const resources = new PdfDictionary();
|
|
144
|
+
resources.set('Font', resFontDict);
|
|
145
|
+
return resources;
|
|
146
|
+
}
|
|
147
|
+
const font = this.font;
|
|
148
|
+
if (font && !PdfFont.getStandardFont(fontName)) {
|
|
149
|
+
const fontDict = new PdfDictionary();
|
|
150
|
+
fontDict.set(fontName, font.reference);
|
|
151
|
+
const resources = new PdfDictionary();
|
|
152
|
+
resources.set('Font', fontDict);
|
|
153
|
+
return resources;
|
|
154
|
+
}
|
|
155
|
+
return undefined;
|
|
74
156
|
}
|
|
75
157
|
get fieldType() {
|
|
76
158
|
const ft = this.content.get('FT')?.as(PdfName)?.value ??
|
|
@@ -123,8 +205,12 @@ export class PdfFormField extends PdfWidgetAnnotation {
|
|
|
123
205
|
if (v instanceof PdfString) {
|
|
124
206
|
if (v.isUTF16BE)
|
|
125
207
|
return v.value;
|
|
126
|
-
|
|
127
|
-
|
|
208
|
+
const encodingMap = this.font?.encodingMap ??
|
|
209
|
+
(this.fontName
|
|
210
|
+
? this._form?.fontEncodingMaps?.get(this.fontName)
|
|
211
|
+
: undefined);
|
|
212
|
+
if (encodingMap) {
|
|
213
|
+
return decodeWithFontEncoding(v.raw, encodingMap);
|
|
128
214
|
}
|
|
129
215
|
return v.value;
|
|
130
216
|
}
|
|
@@ -141,15 +227,29 @@ export class PdfFormField extends PdfWidgetAnnotation {
|
|
|
141
227
|
: undefined;
|
|
142
228
|
const generateAppearance = this._storeValue(val, fieldParent);
|
|
143
229
|
if (generateAppearance && this.defaultGenerateAppearance) {
|
|
144
|
-
this.
|
|
230
|
+
this.generateAppearance();
|
|
145
231
|
for (const sibling of this.siblings) {
|
|
146
232
|
if (sibling !== this &&
|
|
147
233
|
sibling.rect &&
|
|
148
234
|
sibling.defaultGenerateAppearance) {
|
|
149
|
-
|
|
235
|
+
sibling.generateAppearance();
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
// Separated field/widget structure: field has no Rect but its Kids
|
|
239
|
+
// are widget annotations that do. Generate appearances for them.
|
|
240
|
+
if (!this.rect) {
|
|
241
|
+
for (const child of this.children) {
|
|
242
|
+
if (child.rect && child.defaultGenerateAppearance) {
|
|
243
|
+
if (this._form)
|
|
244
|
+
child.form = this._form;
|
|
245
|
+
child.generateAppearance();
|
|
246
|
+
}
|
|
150
247
|
}
|
|
151
248
|
}
|
|
152
249
|
}
|
|
250
|
+
if (this._form) {
|
|
251
|
+
this._form.xfa?.datasets?.updateField(this.name, this.value);
|
|
252
|
+
}
|
|
153
253
|
}
|
|
154
254
|
/**
|
|
155
255
|
* Writes the value to the dictionary. Returns true if appearance generation
|
|
@@ -162,15 +262,6 @@ export class PdfFormField extends PdfWidgetAnnotation {
|
|
|
162
262
|
fieldParent?.content.set('V', pdfVal);
|
|
163
263
|
return true;
|
|
164
264
|
}
|
|
165
|
-
tryGenerateAppearance(field) {
|
|
166
|
-
field.generateAppearance();
|
|
167
|
-
}
|
|
168
|
-
get checked() {
|
|
169
|
-
return false;
|
|
170
|
-
}
|
|
171
|
-
set checked(_isChecked) {
|
|
172
|
-
// no-op for non-button fields; overridden in PdfButtonFormField
|
|
173
|
-
}
|
|
174
265
|
get fontSize() {
|
|
175
266
|
const da = this.defaultAppearance || '';
|
|
176
267
|
const parsed = PdfDefaultAppearance.parse(da);
|
|
@@ -342,8 +433,8 @@ export class PdfFormField extends PdfWidgetAnnotation {
|
|
|
342
433
|
}
|
|
343
434
|
get defaultAppearance() {
|
|
344
435
|
return (this.content.get('DA')?.as(PdfString)?.value ??
|
|
345
|
-
this.parent?.
|
|
346
|
-
this.
|
|
436
|
+
this.parent?.defaultAppearance ??
|
|
437
|
+
this._form?.defaultAppearance ??
|
|
347
438
|
null);
|
|
348
439
|
}
|
|
349
440
|
set defaultAppearance(da) {
|
|
@@ -365,8 +456,8 @@ export class PdfFormField extends PdfWidgetAnnotation {
|
|
|
365
456
|
.get('Kids')
|
|
366
457
|
?.as((PdfArray));
|
|
367
458
|
if (!kidsArray)
|
|
368
|
-
return
|
|
369
|
-
return kidsArray
|
|
459
|
+
return undefined;
|
|
460
|
+
return kidsArray;
|
|
370
461
|
}
|
|
371
462
|
set kids(kids) {
|
|
372
463
|
if (kids.length === 0) {
|
|
@@ -376,21 +467,44 @@ export class PdfFormField extends PdfWidgetAnnotation {
|
|
|
376
467
|
const kidsArray = new PdfArray(kids);
|
|
377
468
|
this.content.set('Kids', kidsArray);
|
|
378
469
|
}
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
470
|
+
setAppearanceStream(stream) {
|
|
471
|
+
this.appearanceStreamDict ||= new PdfDictionary();
|
|
472
|
+
if (stream instanceof PdfIndirectObject) {
|
|
473
|
+
this.appearanceStreamDict.set('N', stream.reference);
|
|
474
|
+
}
|
|
475
|
+
else {
|
|
476
|
+
const dict = new PdfDictionary();
|
|
477
|
+
for (const key in stream) {
|
|
478
|
+
dict.set(key, stream[key].reference);
|
|
479
|
+
}
|
|
480
|
+
this.appearanceStreamDict.set('N', dict);
|
|
481
|
+
}
|
|
386
482
|
}
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
if (!
|
|
390
|
-
|
|
391
|
-
|
|
483
|
+
getAppearanceStream(setting) {
|
|
484
|
+
const n = this.appearanceStreamDict?.get('N');
|
|
485
|
+
if (!n)
|
|
486
|
+
return null;
|
|
487
|
+
if (n instanceof PdfObjectReference) {
|
|
488
|
+
const resolved = n.resolve();
|
|
489
|
+
if (resolved?.content instanceof PdfStream) {
|
|
490
|
+
return resolved;
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
else if (n instanceof PdfDictionary) {
|
|
494
|
+
const key = setting ??
|
|
495
|
+
this.content.get('AS')?.as(PdfName)?.value ??
|
|
496
|
+
undefined;
|
|
497
|
+
if (key) {
|
|
498
|
+
const entry = n.get(key);
|
|
499
|
+
if (entry instanceof PdfObjectReference) {
|
|
500
|
+
const resolved = entry.resolve();
|
|
501
|
+
if (resolved?.content instanceof PdfStream) {
|
|
502
|
+
return resolved;
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
}
|
|
392
506
|
}
|
|
393
|
-
|
|
507
|
+
return null;
|
|
394
508
|
}
|
|
395
509
|
static _fallbackCtor;
|
|
396
510
|
static _registry = new Map();
|
|
@@ -400,34 +514,6 @@ export class PdfFormField extends PdfWidgetAnnotation {
|
|
|
400
514
|
PdfFormField._fallbackCtor = ctor;
|
|
401
515
|
}
|
|
402
516
|
}
|
|
403
|
-
static create(options) {
|
|
404
|
-
let ft;
|
|
405
|
-
try {
|
|
406
|
-
const dict = options.other.content.as(PdfDictionary);
|
|
407
|
-
ft = dict.get('FT')?.as(PdfName)?.value;
|
|
408
|
-
}
|
|
409
|
-
catch {
|
|
410
|
-
// content may not be a dictionary
|
|
411
|
-
}
|
|
412
|
-
if (!ft && options.parent) {
|
|
413
|
-
try {
|
|
414
|
-
ft = options.parent.content.get('FT')?.as(PdfName)?.value;
|
|
415
|
-
}
|
|
416
|
-
catch {
|
|
417
|
-
// ignore
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
const Ctor = ft ? PdfFormField._registry.get(ft) : undefined;
|
|
421
|
-
if (!Ctor) {
|
|
422
|
-
// Fields without FT are parent/container nodes — use the
|
|
423
|
-
// fallback type (typically Text) as a concrete stand-in.
|
|
424
|
-
if (!PdfFormField._fallbackCtor) {
|
|
425
|
-
throw new Error(`Unknown field type: ${ft ?? '(none)'}`);
|
|
426
|
-
}
|
|
427
|
-
return new PdfFormField._fallbackCtor(options);
|
|
428
|
-
}
|
|
429
|
-
return new Ctor(options);
|
|
430
|
-
}
|
|
431
517
|
}
|
|
432
518
|
/** Backward compatible alias */
|
|
433
519
|
export { PdfFormField as PdfAcroFormField };
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { PdfFormField } from './pdf-form-field.js';
|
|
2
2
|
import { PdfDefaultAppearance } from './pdf-default-appearance.js';
|
|
3
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
4
|
/**
|
|
7
5
|
* Text form field subtype.
|
|
8
6
|
*/
|
|
@@ -22,36 +20,11 @@ export class PdfTextFormField extends PdfFormField {
|
|
|
22
20
|
const parsed = PdfDefaultAppearance.parse(da);
|
|
23
21
|
if (!parsed)
|
|
24
22
|
return false;
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
-
|
|
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({
|
|
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({
|
|
55
28
|
rect: rect,
|
|
56
29
|
value: this.value,
|
|
57
30
|
da: parsed,
|
|
@@ -61,7 +34,7 @@ export class PdfTextFormField extends PdfFormField {
|
|
|
61
34
|
fontResources,
|
|
62
35
|
isUnicode,
|
|
63
36
|
reverseEncodingMap,
|
|
64
|
-
});
|
|
37
|
+
}));
|
|
65
38
|
if (options?.makeReadOnly) {
|
|
66
39
|
this.readOnly = true;
|
|
67
40
|
if (!this.print)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { PdfDefaultResourcesDictionary } from '../../annotations/pdf-default-resources.js';
|
|
2
2
|
import type { PdfObjectReference } from '../../core/objects/pdf-object-reference.js';
|
|
3
3
|
/**
|
|
4
4
|
* Field types for AcroForm fields
|
package/dist/acroform/index.d.ts
CHANGED
package/dist/acroform/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { PdfDocument } from '../pdf/pdf-document.js';
|
|
2
1
|
import { PdfDictionary } from '../core/objects/pdf-dictionary.js';
|
|
3
2
|
import { PdfArray } from '../core/objects/pdf-array.js';
|
|
4
3
|
import { PdfString } from '../core/objects/pdf-string.js';
|
|
@@ -6,46 +5,24 @@ import { PdfObjectReference } from '../core/objects/pdf-object-reference.js';
|
|
|
6
5
|
import { PdfIndirectObject } from '../core/objects/pdf-indirect-object.js';
|
|
7
6
|
import { PdfBoolean } from '../core/objects/pdf-boolean.js';
|
|
8
7
|
import { PdfNumber } from '../core/objects/pdf-number.js';
|
|
9
|
-
import { PdfXfaForm } from './xfa/pdf-xfa-form.js';
|
|
10
8
|
import { PdfFormField } from './fields/pdf-form-field.js';
|
|
11
9
|
import './fields/pdf-text-form-field.js';
|
|
12
10
|
import './fields/pdf-button-form-field.js';
|
|
13
11
|
import './fields/pdf-choice-form-field.js';
|
|
14
12
|
import './fields/pdf-signature-form-field.js';
|
|
15
|
-
import
|
|
16
|
-
|
|
17
|
-
Font?: PdfDictionary;
|
|
18
|
-
ProcSet?: PdfArray;
|
|
19
|
-
ExtGState?: PdfDictionary;
|
|
20
|
-
ColorSpace?: PdfDictionary;
|
|
21
|
-
Pattern?: PdfDictionary;
|
|
22
|
-
Shading?: PdfDictionary;
|
|
23
|
-
XObject?: PdfDictionary;
|
|
24
|
-
}>;
|
|
13
|
+
import { PdfDefaultResourcesDictionary } from '../annotations/pdf-default-resources.js';
|
|
14
|
+
import { PdfXfaForm } from './xfa/pdf-xfa-form.js';
|
|
25
15
|
export declare class PdfAcroForm<T extends Record<string, string> = Record<string, string>> extends PdfIndirectObject<PdfDictionary<{
|
|
26
|
-
Fields: PdfArray<PdfObjectReference
|
|
16
|
+
Fields: PdfArray<PdfObjectReference> | PdfObjectReference;
|
|
27
17
|
NeedAppearances?: PdfBoolean;
|
|
28
18
|
SigFlags?: PdfNumber;
|
|
29
19
|
CO?: PdfArray<PdfObjectReference>;
|
|
30
20
|
DR?: PdfDefaultResourcesDictionary;
|
|
31
21
|
DA?: PdfString;
|
|
32
22
|
Q?: PdfNumber;
|
|
33
|
-
XFA?:
|
|
34
|
-
}>>
|
|
35
|
-
|
|
36
|
-
private _fontEncodingCache?;
|
|
37
|
-
private document?;
|
|
38
|
-
private _xfa?;
|
|
39
|
-
constructor(options?: {
|
|
40
|
-
other?: PdfIndirectObject;
|
|
41
|
-
fields?: PdfFormField[];
|
|
42
|
-
document?: PdfDocument;
|
|
43
|
-
});
|
|
44
|
-
private get fontEncodingCache();
|
|
45
|
-
get fontEncodingMaps(): Map<string, Map<number, string>>;
|
|
46
|
-
get fontRefs(): Map<string, PdfObjectReference>;
|
|
47
|
-
setXfa(xfa: PdfXfaForm | null): void;
|
|
48
|
-
isModified(): boolean;
|
|
23
|
+
XFA?: PdfArray<PdfObjectReference>;
|
|
24
|
+
}>> {
|
|
25
|
+
constructor(options?: PdfIndirectObject);
|
|
49
26
|
get needAppearances(): boolean;
|
|
50
27
|
set needAppearances(value: boolean);
|
|
51
28
|
get signatureFlags(): number;
|
|
@@ -56,14 +33,13 @@ export declare class PdfAcroForm<T extends Record<string, string> = Record<strin
|
|
|
56
33
|
set defaultQuadding(q: number);
|
|
57
34
|
get defaultResources(): PdfDefaultResourcesDictionary | null;
|
|
58
35
|
set defaultResources(resources: PdfDefaultResourcesDictionary | null);
|
|
36
|
+
get fields(): ReadonlyArray<PdfFormField>;
|
|
37
|
+
addField(...fields: PdfFormField[]): void;
|
|
38
|
+
set fields(newFields: PdfFormField[]);
|
|
59
39
|
setValues(values: Partial<T>): void;
|
|
60
40
|
importData(fields: T): void;
|
|
61
41
|
exportData(): Partial<T>;
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
private cacheAllFontEncodings;
|
|
66
|
-
private updatePageAnnotations;
|
|
67
|
-
getXfa(document?: PdfDocument): Promise<PdfXfaForm | null>;
|
|
68
|
-
write(document?: PdfDocument): Promise<void>;
|
|
42
|
+
fontEncodingMaps: Map<string, Map<number, string>>;
|
|
43
|
+
getFontEncodingMap(fontName: string): Map<number, string> | null;
|
|
44
|
+
get xfa(): PdfXfaForm | null;
|
|
69
45
|
}
|