pdf-lite 1.3.3 → 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 (124) hide show
  1. package/dist/acroform/acroform.d.ts +7 -454
  2. package/dist/acroform/acroform.js +5 -1664
  3. package/dist/acroform/appearance/index.d.ts +4 -0
  4. package/dist/acroform/appearance/index.js +4 -0
  5. package/dist/acroform/appearance/pdf-appearance-stream.d.ts +21 -0
  6. package/dist/acroform/appearance/pdf-appearance-stream.js +41 -0
  7. package/dist/acroform/appearance/pdf-button-appearance-stream.d.ts +13 -0
  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/pdf-text-appearance-stream.d.ts +22 -0
  14. package/dist/acroform/appearance/pdf-text-appearance-stream.js +104 -0
  15. package/dist/acroform/fields/index.d.ts +8 -0
  16. package/dist/acroform/fields/index.js +8 -0
  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/pdf-default-appearance.d.ts +23 -0
  22. package/dist/acroform/fields/pdf-default-appearance.js +68 -0
  23. package/dist/acroform/fields/pdf-form-field-flags.d.ts +45 -0
  24. package/dist/acroform/fields/pdf-form-field-flags.js +122 -0
  25. package/dist/acroform/fields/pdf-form-field.d.ts +123 -0
  26. package/dist/acroform/fields/pdf-form-field.js +433 -0
  27. package/dist/acroform/fields/pdf-signature-form-field.d.ts +7 -0
  28. package/dist/acroform/fields/pdf-signature-form-field.js +12 -0
  29. package/dist/acroform/fields/pdf-text-form-field.d.ts +10 -0
  30. package/dist/acroform/fields/pdf-text-form-field.js +77 -0
  31. package/dist/acroform/fields/types.d.ts +26 -0
  32. package/dist/acroform/fields/types.js +9 -0
  33. package/dist/acroform/index.d.ts +5 -1
  34. package/dist/acroform/index.js +5 -1
  35. package/dist/acroform/manager.d.ts +12 -1
  36. package/dist/acroform/manager.js +20 -2
  37. package/dist/acroform/pdf-acro-form.d.ts +69 -0
  38. package/dist/acroform/pdf-acro-form.js +293 -0
  39. package/dist/acroform/pdf-font-encoding-cache.d.ts +27 -0
  40. package/dist/acroform/pdf-font-encoding-cache.js +188 -0
  41. package/dist/acroform/xfa/index.d.ts +3 -0
  42. package/dist/acroform/xfa/index.js +2 -0
  43. package/dist/acroform/xfa/pdf-xfa-data.d.ts +20 -0
  44. package/dist/acroform/xfa/pdf-xfa-data.js +68 -0
  45. package/dist/acroform/xfa/pdf-xfa-form.d.ts +11 -0
  46. package/dist/acroform/xfa/pdf-xfa-form.js +56 -0
  47. package/dist/annotations/index.d.ts +4 -0
  48. package/dist/annotations/index.js +4 -0
  49. package/dist/annotations/pdf-annotation-flags.d.ts +24 -0
  50. package/dist/annotations/pdf-annotation-flags.js +93 -0
  51. package/dist/annotations/pdf-annotation-writer.d.ts +20 -0
  52. package/dist/annotations/pdf-annotation-writer.js +76 -0
  53. package/dist/annotations/pdf-annotation.d.ts +61 -0
  54. package/dist/annotations/pdf-annotation.js +106 -0
  55. package/dist/annotations/pdf-widget-annotation.d.ts +15 -0
  56. package/dist/annotations/pdf-widget-annotation.js +37 -0
  57. package/dist/core/objects/pdf-array.d.ts +1 -1
  58. package/dist/core/objects/pdf-array.js +3 -2
  59. package/dist/core/objects/pdf-boolean.d.ts +1 -1
  60. package/dist/core/objects/pdf-boolean.js +3 -2
  61. package/dist/core/objects/pdf-comment.d.ts +1 -1
  62. package/dist/core/objects/pdf-comment.js +1 -1
  63. package/dist/core/objects/pdf-dictionary.d.ts +1 -1
  64. package/dist/core/objects/pdf-dictionary.js +3 -2
  65. package/dist/core/objects/pdf-hexadecimal.d.ts +1 -1
  66. package/dist/core/objects/pdf-hexadecimal.js +3 -2
  67. package/dist/core/objects/pdf-indirect-object.d.ts +1 -1
  68. package/dist/core/objects/pdf-indirect-object.js +1 -1
  69. package/dist/core/objects/pdf-name.d.ts +1 -1
  70. package/dist/core/objects/pdf-name.js +3 -2
  71. package/dist/core/objects/pdf-null.d.ts +1 -1
  72. package/dist/core/objects/pdf-null.js +3 -2
  73. package/dist/core/objects/pdf-number.d.ts +1 -1
  74. package/dist/core/objects/pdf-number.js +3 -2
  75. package/dist/core/objects/pdf-object-reference.d.ts +1 -1
  76. package/dist/core/objects/pdf-object-reference.js +3 -2
  77. package/dist/core/objects/pdf-object.d.ts +3 -1
  78. package/dist/core/objects/pdf-object.js +6 -0
  79. package/dist/core/objects/pdf-start-xref.d.ts +1 -1
  80. package/dist/core/objects/pdf-start-xref.js +3 -2
  81. package/dist/core/objects/pdf-stream.d.ts +4 -3
  82. package/dist/core/objects/pdf-stream.js +45 -16
  83. package/dist/core/objects/pdf-string.d.ts +2 -1
  84. package/dist/core/objects/pdf-string.js +17 -2
  85. package/dist/core/objects/pdf-trailer.d.ts +1 -1
  86. package/dist/core/objects/pdf-trailer.js +3 -2
  87. package/dist/core/objects/pdf-xref-table.d.ts +3 -3
  88. package/dist/core/objects/pdf-xref-table.js +3 -3
  89. package/dist/core/parser/incremental-parser.d.ts +0 -13
  90. package/dist/core/parser/incremental-parser.js +1 -18
  91. package/dist/core/streams/object-stream.d.ts +1 -1
  92. package/dist/core/streams/object-stream.js +1 -1
  93. package/dist/errors.d.ts +22 -0
  94. package/dist/errors.js +24 -0
  95. package/dist/fonts/index.d.ts +1 -1
  96. package/dist/fonts/index.js +1 -1
  97. package/dist/fonts/pdf-font.d.ts +64 -7
  98. package/dist/fonts/pdf-font.js +188 -8
  99. package/dist/index.d.ts +2 -0
  100. package/dist/index.js +2 -0
  101. package/dist/pdf/index.d.ts +0 -1
  102. package/dist/pdf/index.js +0 -1
  103. package/dist/pdf/pdf-document.d.ts +16 -12
  104. package/dist/pdf/pdf-document.js +51 -37
  105. package/dist/pdf/pdf-revision.d.ts +1 -1
  106. package/dist/pdf/pdf-revision.js +1 -1
  107. package/dist/pdf/pdf-xref-lookup.d.ts +8 -0
  108. package/dist/pdf/pdf-xref-lookup.js +12 -0
  109. package/dist/security/handlers/base.js +3 -0
  110. package/dist/utils/encodePdfText.d.ts +17 -0
  111. package/dist/utils/encodePdfText.js +61 -0
  112. package/dist/utils/index.d.ts +1 -1
  113. package/dist/utils/index.js +1 -1
  114. package/package.json +1 -1
  115. package/dist/pdf/errors.d.ts +0 -6
  116. package/dist/pdf/errors.js +0 -6
  117. package/dist/xfa/index.d.ts +0 -1
  118. package/dist/xfa/index.js +0 -1
  119. package/dist/xfa/manager.d.ts +0 -44
  120. package/dist/xfa/manager.js +0 -136
  121. /package/dist/fonts/{font-manager.d.ts → manager.d.ts} +0 -0
  122. /package/dist/fonts/{font-manager.js → manager.js} +0 -0
  123. /package/dist/utils/{IterableReadableStream.d.ts → iterable-readable-stream.d.ts} +0 -0
  124. /package/dist/utils/{IterableReadableStream.js → iterable-readable-stream.js} +0 -0
@@ -0,0 +1,23 @@
1
+ import { PdfFormField } from './pdf-form-field.js';
2
+ import { PdfString } from '../../core/objects/pdf-string.js';
3
+ import { PdfObjectReference } from '../../core/objects/pdf-object-reference.js';
4
+ import type { PdfAppearanceStream } from '../appearance/pdf-appearance-stream.js';
5
+ import type { PdfStream } from '../../core/objects/pdf-stream.js';
6
+ /**
7
+ * Button form field subtype (checkboxes, radio buttons, push buttons).
8
+ */
9
+ export declare class PdfButtonFormField extends PdfFormField {
10
+ set defaultValue(val: string);
11
+ protected _storeValue(val: string | PdfString, fieldParent: PdfFormField | undefined): boolean;
12
+ get checked(): boolean;
13
+ set checked(isChecked: boolean);
14
+ getAppearanceStream(): PdfStream | undefined;
15
+ getAppearanceStreamsForWriting(): {
16
+ primary: PdfAppearanceStream;
17
+ secondary?: PdfAppearanceStream;
18
+ } | undefined;
19
+ setAppearanceReference(appearanceStreamRef: PdfObjectReference, appearanceStreamYesRef?: PdfObjectReference): void;
20
+ generateAppearance(options?: {
21
+ makeReadOnly?: boolean;
22
+ }): boolean;
23
+ }
@@ -0,0 +1,102 @@
1
+ import { PdfFormField } from './pdf-form-field.js';
2
+ import { PdfButtonAppearanceStream } from '../appearance/pdf-button-appearance-stream.js';
3
+ import { PdfName } from '../../core/objects/pdf-name.js';
4
+ import { PdfString } from '../../core/objects/pdf-string.js';
5
+ import { PdfDictionary } from '../../core/objects/pdf-dictionary.js';
6
+ /**
7
+ * Button form field subtype (checkboxes, radio buttons, push buttons).
8
+ */
9
+ export class PdfButtonFormField extends PdfFormField {
10
+ static {
11
+ PdfFormField.registerFieldType('Btn', PdfButtonFormField);
12
+ }
13
+ set defaultValue(val) {
14
+ this.content.set('DV', new PdfName(val));
15
+ }
16
+ _storeValue(val, fieldParent) {
17
+ const strVal = val instanceof PdfString ? val.value : val;
18
+ if (strVal.trim() === '') {
19
+ this.content.delete('V');
20
+ fieldParent?.content.delete('V');
21
+ this.content.delete('AS');
22
+ return false;
23
+ }
24
+ this.content.set('V', new PdfName(strVal));
25
+ fieldParent?.content.set('V', new PdfName(strVal));
26
+ this.content.set('AS', new PdfName(strVal));
27
+ return true;
28
+ }
29
+ get checked() {
30
+ const v = this.content.get('V') ?? this.parent?.content.get('V');
31
+ return v instanceof PdfName && v.value === 'Yes';
32
+ }
33
+ set checked(isChecked) {
34
+ const target = this.parent ?? this;
35
+ if (isChecked) {
36
+ target.content.set('V', new PdfName('Yes'));
37
+ this.content.set('AS', new PdfName('Yes'));
38
+ }
39
+ else {
40
+ target.content.set('V', new PdfName('Off'));
41
+ this.content.set('AS', new PdfName('Off'));
42
+ }
43
+ }
44
+ getAppearanceStream() {
45
+ if (this.checked && this._appearanceStreamYes) {
46
+ return this._appearanceStreamYes.content;
47
+ }
48
+ return this._appearanceStream?.content;
49
+ }
50
+ getAppearanceStreamsForWriting() {
51
+ if (!this._appearanceStream)
52
+ return undefined;
53
+ return {
54
+ primary: this._appearanceStream,
55
+ secondary: this._appearanceStreamYes,
56
+ };
57
+ }
58
+ setAppearanceReference(appearanceStreamRef, appearanceStreamYesRef) {
59
+ let apDict = this.appearanceStreamDict;
60
+ if (!apDict) {
61
+ apDict = new PdfDictionary();
62
+ this.appearanceStreamDict = apDict;
63
+ }
64
+ if (appearanceStreamYesRef) {
65
+ const stateDict = new PdfDictionary();
66
+ stateDict.set('Off', appearanceStreamRef);
67
+ stateDict.set('Yes', appearanceStreamYesRef);
68
+ apDict.set('N', stateDict);
69
+ }
70
+ else {
71
+ apDict.set('N', appearanceStreamRef);
72
+ }
73
+ }
74
+ generateAppearance(options) {
75
+ const rect = this.rect;
76
+ if (!rect || rect.length !== 4)
77
+ return false;
78
+ const [x1, y1, x2, y2] = rect;
79
+ const width = x2 - x1;
80
+ const height = y2 - y1;
81
+ this._appearanceStream = new PdfButtonAppearanceStream({
82
+ width,
83
+ height,
84
+ contentStream: '',
85
+ });
86
+ // Merge own flags with parent flags so inherited bits (e.g. Radio) are
87
+ // not lost when a child widget has its own Ff entry (even Ff: 0).
88
+ const effectiveFlags = this.flags.flags | (this.parent?.flags?.flags ?? 0);
89
+ const yesContent = PdfButtonAppearanceStream.buildYesContent(width, height, effectiveFlags);
90
+ this._appearanceStreamYes = new PdfButtonAppearanceStream({
91
+ width,
92
+ height,
93
+ contentStream: yesContent,
94
+ });
95
+ if (options?.makeReadOnly) {
96
+ this.readOnly = true;
97
+ this.print = true;
98
+ this.noZoom = true;
99
+ }
100
+ return true;
101
+ }
102
+ }
@@ -0,0 +1,18 @@
1
+ import { PdfFormField } from './pdf-form-field.js';
2
+ /**
3
+ * Choice form field subtype (dropdowns, list boxes).
4
+ */
5
+ export declare class PdfChoiceFormField extends PdfFormField {
6
+ get selectedIndex(): number;
7
+ get options(): {
8
+ label: string;
9
+ value: string;
10
+ }[];
11
+ set options(values: {
12
+ label: string;
13
+ value: string;
14
+ }[] | string[] | undefined);
15
+ generateAppearance(options?: {
16
+ makeReadOnly?: boolean;
17
+ }): boolean;
18
+ }
@@ -0,0 +1,131 @@
1
+ import { PdfFormField } from './pdf-form-field.js';
2
+ import { PdfDefaultAppearance } from './pdf-default-appearance.js';
3
+ import { PdfChoiceAppearanceStream } from '../appearance/pdf-choice-appearance-stream.js';
4
+ import { PdfDictionary } from '../../core/objects/pdf-dictionary.js';
5
+ import { PdfObjectReference } from '../../core/objects/pdf-object-reference.js';
6
+ import { PdfArray } from '../../core/objects/pdf-array.js';
7
+ import { PdfString } from '../../core/objects/pdf-string.js';
8
+ /**
9
+ * Choice form field subtype (dropdowns, list boxes).
10
+ */
11
+ export class PdfChoiceFormField extends PdfFormField {
12
+ static {
13
+ PdfFormField.registerFieldType('Ch', PdfChoiceFormField);
14
+ }
15
+ get selectedIndex() {
16
+ return this.options.findIndex((opt) => opt.value === this.value);
17
+ }
18
+ get options() {
19
+ const opt = this.content
20
+ .get('Opt')
21
+ ?.as((PdfArray)) ??
22
+ this.parent?.content
23
+ .get('Opt')
24
+ ?.as((PdfArray));
25
+ if (!opt)
26
+ return [];
27
+ return opt.items.map((item) => {
28
+ if (item instanceof PdfArray && item.items.length >= 2) {
29
+ const label = item.items[1] instanceof PdfString
30
+ ? item.items[1].value
31
+ : '';
32
+ const value = item.items[0] instanceof PdfString
33
+ ? item.items[0].value
34
+ : '';
35
+ return { label, value };
36
+ }
37
+ else if (item instanceof PdfString) {
38
+ return { label: item.value, value: item.value };
39
+ }
40
+ else {
41
+ return { label: '', value: '' };
42
+ }
43
+ });
44
+ }
45
+ set options(values) {
46
+ if (values === undefined) {
47
+ this.content.delete('Opt');
48
+ return;
49
+ }
50
+ if (values.length === 0) {
51
+ this.content.delete('Opt');
52
+ return;
53
+ }
54
+ const optArray = new PdfArray();
55
+ for (const option of values) {
56
+ if (typeof option === 'string') {
57
+ optArray.items.push(new PdfString(option));
58
+ }
59
+ else if (option.label === option.value) {
60
+ optArray.items.push(new PdfString(option.value));
61
+ }
62
+ else {
63
+ const pair = new PdfArray();
64
+ pair.items.push(new PdfString(option.value));
65
+ pair.items.push(new PdfString(option.label));
66
+ optArray.items.push(pair);
67
+ }
68
+ }
69
+ this.content.set('Opt', optArray);
70
+ }
71
+ generateAppearance(options) {
72
+ const rect = this.rect;
73
+ if (!rect || rect.length !== 4)
74
+ return false;
75
+ const da = this.defaultAppearance;
76
+ if (!da)
77
+ return false;
78
+ const value = this.value;
79
+ if (!value)
80
+ return false;
81
+ const parsed = PdfDefaultAppearance.parse(da);
82
+ if (!parsed)
83
+ return false;
84
+ let fontResources;
85
+ const drFontValue = this.form?.defaultResources?.get('Font');
86
+ const drFonts = drFontValue instanceof PdfDictionary ? drFontValue : undefined;
87
+ const daFontRef = this.form?.fontRefs?.get(parsed.fontName);
88
+ if (drFonts || daFontRef) {
89
+ // Build a fresh font dict using clean PdfObjectReferences (no
90
+ // pre/postTokens inherited from the original parse context).
91
+ const fontDict = new PdfDictionary();
92
+ if (drFonts) {
93
+ for (const [key, val] of drFonts.entries()) {
94
+ if (val instanceof PdfObjectReference) {
95
+ fontDict.set(key, new PdfObjectReference(val.objectNumber, val.generationNumber));
96
+ }
97
+ else if (val != null) {
98
+ fontDict.set(key, val);
99
+ }
100
+ }
101
+ }
102
+ if (daFontRef && !fontDict.has(parsed.fontName)) {
103
+ fontDict.set(parsed.fontName, new PdfObjectReference(daFontRef.objectNumber, daFontRef.generationNumber));
104
+ }
105
+ fontResources = new PdfDictionary();
106
+ fontResources.set('Font', fontDict);
107
+ }
108
+ const isUnicode = this.form?.isFontUnicode(parsed.fontName) ?? false;
109
+ const encodingMap = this.form?.fontEncodingMaps?.get(parsed.fontName);
110
+ const reverseEncodingMap = encodingMap
111
+ ? new Map(Array.from(encodingMap, ([code, char]) => [char, code]))
112
+ : undefined;
113
+ this._appearanceStream = new PdfChoiceAppearanceStream({
114
+ rect: rect,
115
+ value,
116
+ da: parsed,
117
+ flags: this.flags,
118
+ fontResources,
119
+ isUnicode,
120
+ reverseEncodingMap,
121
+ displayOptions: this.options.map((opt) => opt.label),
122
+ selectedIndex: this.selectedIndex,
123
+ });
124
+ if (options?.makeReadOnly) {
125
+ this.readOnly = true;
126
+ this.print = true;
127
+ this.noZoom = true;
128
+ }
129
+ return true;
130
+ }
131
+ }
@@ -0,0 +1,23 @@
1
+ import { PdfString } from '../../core/objects/pdf-string.js';
2
+ /**
3
+ * Value object that parses and builds DA (Default Appearance) strings.
4
+ * DA format: "/FontName FontSize Tf ColorOp"
5
+ *
6
+ * Extends PdfString so it can be stored directly in dictionaries
7
+ * without additional wrapping.
8
+ */
9
+ export declare class PdfDefaultAppearance extends PdfString {
10
+ private _fontName;
11
+ private _fontSize;
12
+ private _colorOp;
13
+ constructor(fontName: string, fontSize: number, colorOp: string);
14
+ get fontName(): string;
15
+ set fontName(name: string);
16
+ get fontSize(): number;
17
+ set fontSize(size: number);
18
+ get colorOp(): string;
19
+ set colorOp(op: string);
20
+ private syncRaw;
21
+ toString(): string;
22
+ static parse(da: string): PdfDefaultAppearance | null;
23
+ }
@@ -0,0 +1,68 @@
1
+ import { PdfString } from '../../core/objects/pdf-string.js';
2
+ import { encodeToPDFDocEncoding } from '../../utils/encodeToPDFDocEncoding.js';
3
+ /**
4
+ * Value object that parses and builds DA (Default Appearance) strings.
5
+ * DA format: "/FontName FontSize Tf ColorOp"
6
+ *
7
+ * Extends PdfString so it can be stored directly in dictionaries
8
+ * without additional wrapping.
9
+ */
10
+ export class PdfDefaultAppearance extends PdfString {
11
+ _fontName;
12
+ _fontSize;
13
+ _colorOp;
14
+ constructor(fontName, fontSize, colorOp) {
15
+ super(`/${fontName} ${fontSize} Tf ${colorOp}`);
16
+ this._fontName = fontName;
17
+ this._fontSize = fontSize;
18
+ this._colorOp = colorOp;
19
+ }
20
+ get fontName() {
21
+ return this._fontName;
22
+ }
23
+ set fontName(name) {
24
+ this._fontName = name;
25
+ this.syncRaw();
26
+ }
27
+ get fontSize() {
28
+ return this._fontSize;
29
+ }
30
+ set fontSize(size) {
31
+ this._fontSize = size;
32
+ this.syncRaw();
33
+ }
34
+ get colorOp() {
35
+ return this._colorOp;
36
+ }
37
+ set colorOp(op) {
38
+ this._colorOp = op;
39
+ this.syncRaw();
40
+ }
41
+ syncRaw() {
42
+ // DA strings are always ASCII, so simple PDFDocEncoding works
43
+ this.raw = encodeToPDFDocEncoding(this.toString());
44
+ }
45
+ toString() {
46
+ return `/${this._fontName} ${this._fontSize} Tf ${this._colorOp}`;
47
+ }
48
+ static parse(da) {
49
+ const fontMatch = da.match(/\/(\w+)\s+([\d.]+)\s+Tf/);
50
+ if (!fontMatch)
51
+ return null;
52
+ const fontName = fontMatch[1];
53
+ let fontSize = parseFloat(fontMatch[2]);
54
+ if (!fontSize || fontSize <= 0) {
55
+ fontSize = 12;
56
+ }
57
+ let colorOp = '0 g';
58
+ const rgMatch = da.match(/([\d.]+\s+[\d.]+\s+[\d.]+)\s+rg/);
59
+ const gMatch = da.match(/([\d.]+)\s+g/);
60
+ if (rgMatch) {
61
+ colorOp = `${rgMatch[1]} rg`;
62
+ }
63
+ else if (gMatch) {
64
+ colorOp = `${gMatch[1]} g`;
65
+ }
66
+ return new PdfDefaultAppearance(fontName, fontSize, colorOp);
67
+ }
68
+ }
@@ -0,0 +1,45 @@
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
+ * Extends PdfNumber so it can be stored directly in a PDF dictionary.
6
+ */
7
+ export declare class PdfFormFieldFlags extends PdfNumber {
8
+ constructor(value?: number | PdfNumber | PdfFormFieldFlags);
9
+ get flags(): number;
10
+ set flags(v: number | PdfFormFieldFlags);
11
+ private getFlag;
12
+ private setFlag;
13
+ get readOnly(): boolean;
14
+ set readOnly(v: boolean);
15
+ get required(): boolean;
16
+ set required(v: boolean);
17
+ get noExport(): boolean;
18
+ set noExport(v: boolean);
19
+ get multiline(): boolean;
20
+ set multiline(v: boolean);
21
+ get password(): boolean;
22
+ set password(v: boolean);
23
+ get noToggleToOff(): boolean;
24
+ set noToggleToOff(v: boolean);
25
+ get radio(): boolean;
26
+ set radio(v: boolean);
27
+ get pushButton(): boolean;
28
+ set pushButton(v: boolean);
29
+ get combo(): boolean;
30
+ set combo(v: boolean);
31
+ get edit(): boolean;
32
+ set edit(v: boolean);
33
+ get sort(): boolean;
34
+ set sort(v: boolean);
35
+ get multiSelect(): boolean;
36
+ set multiSelect(v: boolean);
37
+ get doNotSpellCheck(): boolean;
38
+ set doNotSpellCheck(v: boolean);
39
+ get doNotScroll(): boolean;
40
+ set doNotScroll(v: boolean);
41
+ get comb(): boolean;
42
+ set comb(v: boolean);
43
+ get commitOnSelChange(): boolean;
44
+ set commitOnSelChange(v: boolean);
45
+ }
@@ -0,0 +1,122 @@
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
+ * Extends PdfNumber so it can be stored directly in a PDF dictionary.
6
+ */
7
+ export class PdfFormFieldFlags extends PdfNumber {
8
+ constructor(value = 0) {
9
+ super(value);
10
+ this.preTokens = typeof value === 'number' ? undefined : value.preTokens;
11
+ this.postTokens =
12
+ typeof value === 'number' ? undefined : value.postTokens;
13
+ }
14
+ get flags() {
15
+ return this.value;
16
+ }
17
+ set flags(v) {
18
+ this.value = v instanceof PdfFormFieldFlags ? v.value : v;
19
+ }
20
+ getFlag(bit) {
21
+ return (this.flags & bit) !== 0;
22
+ }
23
+ setFlag(bit, val) {
24
+ this.flags = val ? this.flags | bit : this.flags & ~bit;
25
+ }
26
+ get readOnly() {
27
+ return this.getFlag(1);
28
+ }
29
+ set readOnly(v) {
30
+ this.setFlag(1, v);
31
+ }
32
+ get required() {
33
+ return this.getFlag(2);
34
+ }
35
+ set required(v) {
36
+ this.setFlag(2, v);
37
+ }
38
+ get noExport() {
39
+ return this.getFlag(4);
40
+ }
41
+ set noExport(v) {
42
+ this.setFlag(4, v);
43
+ }
44
+ get multiline() {
45
+ return this.getFlag(4096);
46
+ }
47
+ set multiline(v) {
48
+ this.setFlag(4096, v);
49
+ }
50
+ get password() {
51
+ return this.getFlag(8192);
52
+ }
53
+ set password(v) {
54
+ this.setFlag(8192, v);
55
+ }
56
+ get noToggleToOff() {
57
+ return this.getFlag(16384);
58
+ }
59
+ set noToggleToOff(v) {
60
+ this.setFlag(16384, v);
61
+ }
62
+ get radio() {
63
+ return this.getFlag(32768);
64
+ }
65
+ set radio(v) {
66
+ this.setFlag(32768, v);
67
+ }
68
+ get pushButton() {
69
+ return this.getFlag(65536);
70
+ }
71
+ set pushButton(v) {
72
+ this.setFlag(65536, v);
73
+ }
74
+ get combo() {
75
+ return this.getFlag(131072);
76
+ }
77
+ set combo(v) {
78
+ this.setFlag(131072, v);
79
+ }
80
+ get edit() {
81
+ return this.getFlag(262144);
82
+ }
83
+ set edit(v) {
84
+ this.setFlag(262144, v);
85
+ }
86
+ get sort() {
87
+ return this.getFlag(524288);
88
+ }
89
+ set sort(v) {
90
+ this.setFlag(524288, v);
91
+ }
92
+ get multiSelect() {
93
+ return this.getFlag(2097152);
94
+ }
95
+ set multiSelect(v) {
96
+ this.setFlag(2097152, v);
97
+ }
98
+ get doNotSpellCheck() {
99
+ return this.getFlag(4194304);
100
+ }
101
+ set doNotSpellCheck(v) {
102
+ this.setFlag(4194304, v);
103
+ }
104
+ get doNotScroll() {
105
+ return this.getFlag(8388608);
106
+ }
107
+ set doNotScroll(v) {
108
+ this.setFlag(8388608, v);
109
+ }
110
+ get comb() {
111
+ return this.getFlag(16777216);
112
+ }
113
+ set comb(v) {
114
+ this.setFlag(16777216, v);
115
+ }
116
+ get commitOnSelChange() {
117
+ return this.getFlag(67108864);
118
+ }
119
+ set commitOnSelChange(v) {
120
+ this.setFlag(67108864, v);
121
+ }
122
+ }
@@ -0,0 +1,123 @@
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 { PdfFont } from '../../fonts/pdf-font.js';
5
+ import { PdfStream } from '../../core/objects/pdf-stream.js';
6
+ import { PdfWidgetAnnotation } from '../../annotations/pdf-widget-annotation.js';
7
+ import type { PdfAppearanceStream } from '../appearance/pdf-appearance-stream.js';
8
+ import type { FormContext, PdfFieldType } from './types.js';
9
+ import { PdfFormFieldFlags } from './pdf-form-field-flags.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 declare abstract class PdfFormField extends PdfWidgetAnnotation {
16
+ private _parent?;
17
+ defaultGenerateAppearance: boolean;
18
+ protected _appearanceStream?: PdfAppearanceStream;
19
+ protected _appearanceStreamYes?: PdfAppearanceStream;
20
+ form?: FormContext<PdfFormField>;
21
+ constructor(options?: {
22
+ other?: PdfIndirectObject;
23
+ form?: FormContext<PdfFormField>;
24
+ parent?: PdfFormField;
25
+ });
26
+ get parent(): PdfFormField | undefined;
27
+ set parent(field: PdfFormField | undefined);
28
+ get children(): PdfFormField[];
29
+ set children(fields: PdfFormField[]);
30
+ get siblings(): PdfFormField[];
31
+ get encodingMap(): Map<number, string> | undefined;
32
+ get fieldType(): PdfFieldType | null;
33
+ set fieldType(type: PdfFieldType | null);
34
+ get name(): string;
35
+ set name(name: string);
36
+ get defaultValue(): string;
37
+ set defaultValue(val: string);
38
+ get value(): string;
39
+ set value(val: string | PdfString);
40
+ /**
41
+ * Writes the value to the dictionary. Returns true if appearance generation
42
+ * should proceed, false to skip it (e.g. when value was cleared).
43
+ * Override in subclasses to change the stored representation.
44
+ */
45
+ protected _storeValue(val: string | PdfString, fieldParent: PdfFormField | undefined): boolean;
46
+ protected tryGenerateAppearance(field: PdfFormField): void;
47
+ get checked(): boolean;
48
+ set checked(_isChecked: boolean);
49
+ get fontSize(): number | null;
50
+ set fontSize(size: number);
51
+ get fontName(): string | null;
52
+ set fontName(fontName: string);
53
+ set font(font: PdfFont | null);
54
+ get flags(): PdfFormFieldFlags;
55
+ set flags(v: PdfFormFieldFlags);
56
+ get readOnly(): boolean;
57
+ set readOnly(v: boolean);
58
+ get required(): boolean;
59
+ set required(v: boolean);
60
+ get multiline(): boolean;
61
+ set multiline(v: boolean);
62
+ get password(): boolean;
63
+ set password(v: boolean);
64
+ get comb(): boolean;
65
+ get combField(): boolean;
66
+ set combField(v: boolean);
67
+ get combo(): boolean;
68
+ set combo(v: boolean);
69
+ get radio(): boolean;
70
+ set radio(v: boolean);
71
+ get noToggleToOff(): boolean;
72
+ set noToggleToOff(v: boolean);
73
+ get noExport(): boolean;
74
+ set noExport(v: boolean);
75
+ get pushButton(): boolean;
76
+ set pushButton(v: boolean);
77
+ get edit(): boolean;
78
+ set edit(v: boolean);
79
+ get sort(): boolean;
80
+ set sort(v: boolean);
81
+ get multiSelect(): boolean;
82
+ set multiSelect(v: boolean);
83
+ get doNotSpellCheck(): boolean;
84
+ set doNotSpellCheck(v: boolean);
85
+ get doNotScroll(): boolean;
86
+ set doNotScroll(v: boolean);
87
+ get commitOnSelChange(): boolean;
88
+ set commitOnSelChange(v: boolean);
89
+ get quadding(): number;
90
+ set quadding(q: number);
91
+ get defaultAppearance(): string | null;
92
+ set defaultAppearance(da: string);
93
+ get maxLen(): number | null;
94
+ set maxLen(maxLen: number | null);
95
+ get kids(): PdfObjectReference[];
96
+ set kids(kids: PdfObjectReference[]);
97
+ abstract generateAppearance(options?: {
98
+ makeReadOnly?: boolean;
99
+ textYOffset?: number;
100
+ }): boolean;
101
+ getAppearanceStream(): PdfStream | undefined;
102
+ getAppearanceStreamsForWriting(): {
103
+ primary: PdfAppearanceStream;
104
+ secondary?: PdfAppearanceStream;
105
+ } | undefined;
106
+ setAppearanceReference(appearanceStreamRef: PdfObjectReference, _appearanceStreamYesRef?: PdfObjectReference): void;
107
+ private static _fallbackCtor?;
108
+ private static _registry;
109
+ static registerFieldType(ft: 'Sig' | 'Btn' | 'Tx' | 'Ch', ctor: new (options?: {
110
+ other?: PdfIndirectObject;
111
+ form?: FormContext<PdfFormField>;
112
+ parent?: PdfFormField;
113
+ }) => PdfFormField, options?: {
114
+ fallback?: boolean;
115
+ }): void;
116
+ static create(options: {
117
+ other: PdfIndirectObject;
118
+ form: FormContext<PdfFormField>;
119
+ parent?: PdfFormField;
120
+ }): PdfFormField;
121
+ }
122
+ /** Backward compatible alias */
123
+ export { PdfFormField as PdfAcroFormField };