pdf-lite 1.3.3 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/dist/acroform/PdfAcroForm.d.ts +63 -0
  2. package/dist/acroform/PdfAcroForm.js +279 -0
  3. package/dist/acroform/PdfFontEncodingCache.d.ts +16 -0
  4. package/dist/acroform/PdfFontEncodingCache.js +75 -0
  5. package/dist/acroform/acroform.d.ts +7 -454
  6. package/dist/acroform/acroform.js +5 -1664
  7. package/dist/acroform/appearance/PdfAppearanceStream.d.ts +15 -0
  8. package/dist/acroform/appearance/PdfAppearanceStream.js +32 -0
  9. package/dist/acroform/appearance/PdfButtonAppearanceStream.d.ts +12 -0
  10. package/dist/acroform/appearance/PdfButtonAppearanceStream.js +54 -0
  11. package/dist/acroform/appearance/PdfChoiceAppearanceStream.d.ts +15 -0
  12. package/dist/acroform/appearance/PdfChoiceAppearanceStream.js +48 -0
  13. package/dist/acroform/appearance/PdfTextAppearanceStream.d.ts +17 -0
  14. package/dist/acroform/appearance/PdfTextAppearanceStream.js +75 -0
  15. package/dist/acroform/appearance/index.d.ts +4 -0
  16. package/dist/acroform/appearance/index.js +4 -0
  17. package/dist/acroform/fields/PdfButtonFormField.d.ts +9 -0
  18. package/dist/acroform/fields/PdfButtonFormField.js +35 -0
  19. package/dist/acroform/fields/PdfChoiceFormField.d.ts +9 -0
  20. package/dist/acroform/fields/PdfChoiceFormField.js +46 -0
  21. package/dist/acroform/fields/PdfDefaultAppearance.d.ts +23 -0
  22. package/dist/acroform/fields/PdfDefaultAppearance.js +68 -0
  23. package/dist/acroform/fields/PdfFormField.d.ts +119 -0
  24. package/dist/acroform/fields/PdfFormField.js +499 -0
  25. package/dist/acroform/fields/PdfFormFieldFlags.d.ts +46 -0
  26. package/dist/acroform/fields/PdfFormFieldFlags.js +128 -0
  27. package/dist/acroform/fields/PdfSignatureFormField.d.ts +7 -0
  28. package/dist/acroform/fields/PdfSignatureFormField.js +12 -0
  29. package/dist/acroform/fields/PdfTextFormField.d.ts +10 -0
  30. package/dist/acroform/fields/PdfTextFormField.js +52 -0
  31. package/dist/acroform/fields/index.d.ts +8 -0
  32. package/dist/acroform/fields/index.js +8 -0
  33. package/dist/acroform/fields/types.d.ts +21 -0
  34. package/dist/acroform/fields/types.js +9 -0
  35. package/dist/acroform/index.d.ts +5 -1
  36. package/dist/acroform/index.js +5 -1
  37. package/dist/acroform/manager.d.ts +7 -0
  38. package/dist/acroform/manager.js +12 -0
  39. package/dist/acroform/xfa/PdfXfaData.d.ts +20 -0
  40. package/dist/acroform/xfa/PdfXfaData.js +68 -0
  41. package/dist/acroform/xfa/PdfXfaForm.d.ts +12 -0
  42. package/dist/acroform/xfa/PdfXfaForm.js +64 -0
  43. package/dist/acroform/xfa/index.d.ts +3 -0
  44. package/dist/acroform/xfa/index.js +2 -0
  45. package/dist/annotations/PdfAnnotation.d.ts +40 -0
  46. package/dist/annotations/PdfAnnotation.js +105 -0
  47. package/dist/annotations/PdfAnnotationFlags.d.ts +25 -0
  48. package/dist/annotations/PdfAnnotationFlags.js +94 -0
  49. package/dist/annotations/PdfAnnotationWriter.d.ts +20 -0
  50. package/dist/annotations/PdfAnnotationWriter.js +76 -0
  51. package/dist/annotations/PdfWidgetAnnotation.d.ts +15 -0
  52. package/dist/annotations/PdfWidgetAnnotation.js +37 -0
  53. package/dist/annotations/index.d.ts +4 -0
  54. package/dist/annotations/index.js +4 -0
  55. package/dist/core/objects/pdf-array.d.ts +1 -1
  56. package/dist/core/objects/pdf-array.js +3 -2
  57. package/dist/core/objects/pdf-boolean.d.ts +1 -1
  58. package/dist/core/objects/pdf-boolean.js +3 -2
  59. package/dist/core/objects/pdf-comment.d.ts +1 -1
  60. package/dist/core/objects/pdf-comment.js +1 -1
  61. package/dist/core/objects/pdf-dictionary.d.ts +1 -1
  62. package/dist/core/objects/pdf-dictionary.js +3 -2
  63. package/dist/core/objects/pdf-hexadecimal.d.ts +1 -1
  64. package/dist/core/objects/pdf-hexadecimal.js +3 -2
  65. package/dist/core/objects/pdf-indirect-object.d.ts +1 -1
  66. package/dist/core/objects/pdf-indirect-object.js +1 -1
  67. package/dist/core/objects/pdf-name.d.ts +1 -1
  68. package/dist/core/objects/pdf-name.js +3 -2
  69. package/dist/core/objects/pdf-null.d.ts +1 -1
  70. package/dist/core/objects/pdf-null.js +3 -2
  71. package/dist/core/objects/pdf-number.d.ts +1 -1
  72. package/dist/core/objects/pdf-number.js +3 -2
  73. package/dist/core/objects/pdf-object-reference.d.ts +1 -1
  74. package/dist/core/objects/pdf-object-reference.js +3 -2
  75. package/dist/core/objects/pdf-object.d.ts +3 -1
  76. package/dist/core/objects/pdf-object.js +6 -0
  77. package/dist/core/objects/pdf-start-xref.d.ts +1 -1
  78. package/dist/core/objects/pdf-start-xref.js +3 -2
  79. package/dist/core/objects/pdf-stream.d.ts +3 -3
  80. package/dist/core/objects/pdf-stream.js +39 -14
  81. package/dist/core/objects/pdf-string.d.ts +2 -1
  82. package/dist/core/objects/pdf-string.js +17 -2
  83. package/dist/core/objects/pdf-trailer.d.ts +1 -1
  84. package/dist/core/objects/pdf-trailer.js +3 -2
  85. package/dist/core/objects/pdf-xref-table.d.ts +3 -3
  86. package/dist/core/objects/pdf-xref-table.js +3 -3
  87. package/dist/index.d.ts +1 -0
  88. package/dist/index.js +1 -0
  89. package/dist/pdf/pdf-document.d.ts +14 -11
  90. package/dist/pdf/pdf-document.js +36 -26
  91. package/dist/pdf/pdf-revision.d.ts +1 -1
  92. package/dist/pdf/pdf-revision.js +1 -1
  93. package/dist/pdf/pdf-xref-lookup.d.ts +8 -0
  94. package/dist/pdf/pdf-xref-lookup.js +12 -0
  95. package/dist/security/handlers/base.js +3 -0
  96. package/package.json +1 -1
  97. package/dist/xfa/index.d.ts +0 -1
  98. package/dist/xfa/index.js +0 -1
  99. package/dist/xfa/manager.d.ts +0 -44
  100. package/dist/xfa/manager.js +0 -136
@@ -0,0 +1,15 @@
1
+ import { PdfDictionary } from '../../core/objects/pdf-dictionary.js';
2
+ import { PdfStream } from '../../core/objects/pdf-stream.js';
3
+ import { PdfIndirectObject } from '../../core/objects/pdf-indirect-object.js';
4
+ /**
5
+ * Base class for PDF appearance streams (Form XObjects).
6
+ * Wraps a PdfStream as a PdfIndirectObject so it can be added directly to a document.
7
+ */
8
+ export declare class PdfAppearanceStream extends PdfIndirectObject<PdfStream> {
9
+ constructor(options: {
10
+ width: number;
11
+ height: number;
12
+ contentStream: string;
13
+ resources?: PdfDictionary;
14
+ });
15
+ }
@@ -0,0 +1,32 @@
1
+ import { PdfDictionary } from '../../core/objects/pdf-dictionary.js';
2
+ import { PdfArray } from '../../core/objects/pdf-array.js';
3
+ import { PdfName } from '../../core/objects/pdf-name.js';
4
+ import { PdfNumber } from '../../core/objects/pdf-number.js';
5
+ import { PdfStream } from '../../core/objects/pdf-stream.js';
6
+ import { PdfIndirectObject } from '../../core/objects/pdf-indirect-object.js';
7
+ /**
8
+ * Base class for PDF appearance streams (Form XObjects).
9
+ * Wraps a PdfStream as a PdfIndirectObject so it can be added directly to a document.
10
+ */
11
+ export class PdfAppearanceStream extends PdfIndirectObject {
12
+ constructor(options) {
13
+ const appearanceDict = new PdfDictionary();
14
+ appearanceDict.set('Type', new PdfName('XObject'));
15
+ appearanceDict.set('Subtype', new PdfName('Form'));
16
+ appearanceDict.set('FormType', new PdfNumber(1));
17
+ appearanceDict.set('BBox', new PdfArray([
18
+ new PdfNumber(0),
19
+ new PdfNumber(0),
20
+ new PdfNumber(options.width),
21
+ new PdfNumber(options.height),
22
+ ]));
23
+ if (options.resources) {
24
+ appearanceDict.set('Resources', options.resources);
25
+ }
26
+ const stream = new PdfStream({
27
+ header: appearanceDict,
28
+ original: options.contentStream,
29
+ });
30
+ super({ content: stream });
31
+ }
32
+ }
@@ -0,0 +1,12 @@
1
+ import { PdfAppearanceStream } from './PdfAppearanceStream.js';
2
+ /**
3
+ * Appearance stream for button fields (checkboxes, radio buttons).
4
+ */
5
+ export declare class PdfButtonAppearanceStream extends PdfAppearanceStream {
6
+ constructor(ctx: {
7
+ width: number;
8
+ height: number;
9
+ contentStream: string;
10
+ });
11
+ static buildYesContent(width: number, height: number, flags: number): string;
12
+ }
@@ -0,0 +1,54 @@
1
+ import { PdfDictionary } from '../../core/objects/pdf-dictionary.js';
2
+ import { PdfName } from '../../core/objects/pdf-name.js';
3
+ import { PdfAppearanceStream } from './PdfAppearanceStream.js';
4
+ /**
5
+ * Appearance stream for button fields (checkboxes, radio buttons).
6
+ */
7
+ export class PdfButtonAppearanceStream extends PdfAppearanceStream {
8
+ constructor(ctx) {
9
+ const resources = new PdfDictionary();
10
+ const fonts = new PdfDictionary();
11
+ const zapfFont = new PdfDictionary();
12
+ zapfFont.set('Type', new PdfName('Font'));
13
+ zapfFont.set('Subtype', new PdfName('Type1'));
14
+ zapfFont.set('BaseFont', new PdfName('ZapfDingbats'));
15
+ fonts.set('ZaDb', zapfFont);
16
+ resources.set('Font', fonts);
17
+ super({
18
+ width: ctx.width,
19
+ height: ctx.height,
20
+ contentStream: ctx.contentStream,
21
+ resources,
22
+ });
23
+ }
24
+ static buildYesContent(width, height, flags) {
25
+ const size = Math.min(width, height);
26
+ const isRadio = (flags & 32768) !== 0;
27
+ if (isRadio) {
28
+ const center = size / 2;
29
+ const radius = size * 0.35;
30
+ const k = 0.5522847498;
31
+ const kRadius = k * radius;
32
+ return `q
33
+ 0 0 0 rg
34
+ ${center} ${center + radius} m
35
+ ${center + kRadius} ${center + radius} ${center + radius} ${center + kRadius} ${center + radius} ${center} c
36
+ ${center + radius} ${center - kRadius} ${center + kRadius} ${center - radius} ${center} ${center - radius} c
37
+ ${center - kRadius} ${center - radius} ${center - radius} ${center - kRadius} ${center - radius} ${center} c
38
+ ${center - radius} ${center + kRadius} ${center - kRadius} ${center + radius} ${center} ${center + radius} c
39
+ f
40
+ Q
41
+ `;
42
+ }
43
+ const checkSize = size * 0.8;
44
+ const offset = (size - checkSize) / 2;
45
+ return `q
46
+ BT
47
+ /ZaDb ${checkSize} Tf
48
+ ${offset} ${offset} Td
49
+ (4) Tj
50
+ ET
51
+ Q
52
+ `;
53
+ }
54
+ }
@@ -0,0 +1,15 @@
1
+ import { PdfDefaultAppearance } from '../fields/PdfDefaultAppearance.js';
2
+ import { PdfAppearanceStream } from './PdfAppearanceStream.js';
3
+ import type { PdfDictionary } from '../../core/objects/pdf-dictionary.js';
4
+ /**
5
+ * Appearance stream for choice fields (dropdowns, list boxes).
6
+ */
7
+ export declare class PdfChoiceAppearanceStream extends PdfAppearanceStream {
8
+ constructor(ctx: {
9
+ rect: [number, number, number, number];
10
+ value: string;
11
+ da: PdfDefaultAppearance;
12
+ flags: number;
13
+ fontResources?: PdfDictionary;
14
+ });
15
+ }
@@ -0,0 +1,48 @@
1
+ import { PdfAppearanceStream } from './PdfAppearanceStream.js';
2
+ /**
3
+ * Appearance stream for choice fields (dropdowns, list boxes).
4
+ */
5
+ export class PdfChoiceAppearanceStream extends PdfAppearanceStream {
6
+ constructor(ctx) {
7
+ const [x1, y1, x2, y2] = ctx.rect;
8
+ const width = x2 - x1;
9
+ const height = y2 - y1;
10
+ const colorOp = '0 g';
11
+ const reconstructedDA = `/${ctx.da.fontName} ${ctx.da.fontSize} Tf ${colorOp}`;
12
+ const padding = 2;
13
+ const textY = (height - ctx.da.fontSize) / 2 + ctx.da.fontSize * 0.2;
14
+ const textX = padding;
15
+ const escapedValue = ctx.value
16
+ .replace(/\\/g, '\\\\')
17
+ .replace(/\(/g, '\\(')
18
+ .replace(/\)/g, '\\)');
19
+ const isCombo = (ctx.flags & 131072) !== 0;
20
+ let arrowGraphics = '';
21
+ if (isCombo) {
22
+ const arrowWidth = height * 0.8;
23
+ const arrowX = width - arrowWidth - 2;
24
+ const arrowY = height / 2;
25
+ const arrowSize = height * 0.3;
26
+ arrowGraphics = `
27
+ q
28
+ 0.5 0.5 0.5 rg
29
+ ${arrowX + arrowWidth / 2} ${arrowY - arrowSize / 3} m
30
+ ${arrowX + arrowWidth / 2 - arrowSize / 2} ${arrowY + arrowSize / 3} l
31
+ ${arrowX + arrowWidth / 2 + arrowSize / 2} ${arrowY + arrowSize / 3} l
32
+ f
33
+ Q
34
+ `;
35
+ }
36
+ const contentStream = `/Tx BMC
37
+ q
38
+ BT
39
+ ${reconstructedDA}
40
+ ${textX} ${textY} Td
41
+ (${escapedValue}) Tj
42
+ ET
43
+ ${arrowGraphics}Q
44
+ EMC
45
+ `;
46
+ super({ width, height, contentStream, resources: ctx.fontResources });
47
+ }
48
+ }
@@ -0,0 +1,17 @@
1
+ import { PdfDefaultAppearance } from '../fields/PdfDefaultAppearance.js';
2
+ import { PdfAppearanceStream } from './PdfAppearanceStream.js';
3
+ import type { PdfDictionary } from '../../core/objects/pdf-dictionary.js';
4
+ /**
5
+ * Appearance stream for text fields (single-line, multiline, comb).
6
+ */
7
+ export declare class PdfTextAppearanceStream extends PdfAppearanceStream {
8
+ constructor(ctx: {
9
+ rect: [number, number, number, number];
10
+ value: string;
11
+ da: PdfDefaultAppearance;
12
+ multiline: boolean;
13
+ comb: boolean;
14
+ maxLen: number | null;
15
+ fontResources?: PdfDictionary;
16
+ });
17
+ }
@@ -0,0 +1,75 @@
1
+ import { PdfAppearanceStream } from './PdfAppearanceStream.js';
2
+ /**
3
+ * Appearance stream for text fields (single-line, multiline, comb).
4
+ */
5
+ export class PdfTextAppearanceStream extends PdfAppearanceStream {
6
+ constructor(ctx) {
7
+ const [x1, y1, x2, y2] = ctx.rect;
8
+ const width = x2 - x1;
9
+ const height = y2 - y1;
10
+ const value = ctx.value;
11
+ const reconstructedDA = ctx.da.toString();
12
+ const fontSize = ctx.da.fontSize;
13
+ const padding = 2;
14
+ const textY = (height - fontSize) / 2 + fontSize * 0.2;
15
+ const escapedValue = value
16
+ .replace(/\\/g, '\\\\')
17
+ .replace(/\(/g, '\\(')
18
+ .replace(/\)/g, '\\)')
19
+ .replace(/\r/g, '\\r')
20
+ .replace(/\n/g, '\\n');
21
+ let textContent;
22
+ if (ctx.multiline) {
23
+ const lines = value.split('\n');
24
+ const lineHeight = fontSize * 1.2;
25
+ const startY = height - padding - fontSize;
26
+ textContent = 'BT\n';
27
+ textContent += `${reconstructedDA}\n`;
28
+ textContent += `${padding} ${startY} Td\n`;
29
+ for (let i = 0; i < lines.length; i++) {
30
+ const line = lines[i]
31
+ .replace(/\\/g, '\\\\')
32
+ .replace(/\(/g, '\\(')
33
+ .replace(/\)/g, '\\)')
34
+ .replace(/\r/g, '');
35
+ if (i > 0) {
36
+ textContent += `0 ${-lineHeight} Td\n`;
37
+ }
38
+ textContent += `(${line}) Tj\n`;
39
+ }
40
+ textContent += 'ET\n';
41
+ }
42
+ else if (ctx.comb && ctx.maxLen) {
43
+ const cellWidth = width / ctx.maxLen;
44
+ const chars = value.split('');
45
+ textContent = 'BT\n';
46
+ textContent += `${reconstructedDA}\n`;
47
+ for (let i = 0; i < chars.length && i < ctx.maxLen; i++) {
48
+ const cellX = cellWidth * i + cellWidth / 2 - fontSize * 0.3;
49
+ const escapedChar = chars[i]
50
+ .replace(/\\/g, '\\\\')
51
+ .replace(/\(/g, '\\(')
52
+ .replace(/\)/g, '\\)');
53
+ textContent += `${cellX} ${textY} Td\n`;
54
+ textContent += `(${escapedChar}) Tj\n`;
55
+ textContent += `${-cellX} ${-textY} Td\n`;
56
+ }
57
+ textContent += 'ET\n';
58
+ }
59
+ else {
60
+ const textX = padding;
61
+ textContent = `BT
62
+ ${reconstructedDA}
63
+ ${textX} ${textY} Td
64
+ (${escapedValue}) Tj
65
+ ET
66
+ `;
67
+ }
68
+ const contentStream = `/Tx BMC
69
+ q
70
+ ${textContent}Q
71
+ EMC
72
+ `;
73
+ super({ width, height, contentStream, resources: ctx.fontResources });
74
+ }
75
+ }
@@ -0,0 +1,4 @@
1
+ export { PdfAppearanceStream } from './PdfAppearanceStream.js';
2
+ export { PdfTextAppearanceStream } from './PdfTextAppearanceStream.js';
3
+ export { PdfButtonAppearanceStream } from './PdfButtonAppearanceStream.js';
4
+ export { PdfChoiceAppearanceStream } from './PdfChoiceAppearanceStream.js';
@@ -0,0 +1,4 @@
1
+ export { PdfAppearanceStream } from './PdfAppearanceStream.js';
2
+ export { PdfTextAppearanceStream } from './PdfTextAppearanceStream.js';
3
+ export { PdfButtonAppearanceStream } from './PdfButtonAppearanceStream.js';
4
+ export { PdfChoiceAppearanceStream } from './PdfChoiceAppearanceStream.js';
@@ -0,0 +1,9 @@
1
+ import { PdfFormField } from './PdfFormField.js';
2
+ /**
3
+ * Button form field subtype (checkboxes, radio buttons, push buttons).
4
+ */
5
+ export declare class PdfButtonFormField extends PdfFormField {
6
+ generateAppearance(options?: {
7
+ makeReadOnly?: boolean;
8
+ }): boolean;
9
+ }
@@ -0,0 +1,35 @@
1
+ import { PdfFormField } from './PdfFormField.js';
2
+ import { PdfButtonAppearanceStream } from '../appearance/PdfButtonAppearanceStream.js';
3
+ /**
4
+ * Button form field subtype (checkboxes, radio buttons, push buttons).
5
+ */
6
+ export class PdfButtonFormField extends PdfFormField {
7
+ static {
8
+ PdfFormField.registerFieldType('Btn', PdfButtonFormField);
9
+ }
10
+ generateAppearance(options) {
11
+ const rect = this.rect;
12
+ if (!rect || rect.length !== 4)
13
+ return false;
14
+ const [x1, y1, x2, y2] = rect;
15
+ const width = x2 - x1;
16
+ const height = y2 - y1;
17
+ this._appearanceStream = new PdfButtonAppearanceStream({
18
+ width,
19
+ height,
20
+ contentStream: '',
21
+ });
22
+ const yesContent = PdfButtonAppearanceStream.buildYesContent(width, height, this.flags);
23
+ this._appearanceStreamYes = new PdfButtonAppearanceStream({
24
+ width,
25
+ height,
26
+ contentStream: yesContent,
27
+ });
28
+ if (options?.makeReadOnly) {
29
+ this.readOnly = true;
30
+ this.print = true;
31
+ this.noZoom = true;
32
+ }
33
+ return true;
34
+ }
35
+ }
@@ -0,0 +1,9 @@
1
+ import { PdfFormField } from './PdfFormField.js';
2
+ /**
3
+ * Choice form field subtype (dropdowns, list boxes).
4
+ */
5
+ export declare class PdfChoiceFormField extends PdfFormField {
6
+ generateAppearance(options?: {
7
+ makeReadOnly?: boolean;
8
+ }): boolean;
9
+ }
@@ -0,0 +1,46 @@
1
+ import { PdfFormField } from './PdfFormField.js';
2
+ import { PdfDefaultAppearance } from './PdfDefaultAppearance.js';
3
+ import { PdfChoiceAppearanceStream } from '../appearance/PdfChoiceAppearanceStream.js';
4
+ import { PdfDictionary } from '../../core/objects/pdf-dictionary.js';
5
+ /**
6
+ * Choice form field subtype (dropdowns, list boxes).
7
+ */
8
+ export class PdfChoiceFormField extends PdfFormField {
9
+ static {
10
+ PdfFormField.registerFieldType('Ch', PdfChoiceFormField);
11
+ }
12
+ generateAppearance(options) {
13
+ const rect = this.rect;
14
+ if (!rect || rect.length !== 4)
15
+ return false;
16
+ const da = this.defaultAppearance;
17
+ if (!da)
18
+ return false;
19
+ const value = this.value;
20
+ if (!value)
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
+ if (drFonts) {
29
+ fontResources = new PdfDictionary();
30
+ fontResources.set('Font', drFonts);
31
+ }
32
+ this._appearanceStream = new PdfChoiceAppearanceStream({
33
+ rect: rect,
34
+ value,
35
+ da: parsed,
36
+ flags: this.flags,
37
+ fontResources,
38
+ });
39
+ if (options?.makeReadOnly) {
40
+ this.readOnly = true;
41
+ this.print = true;
42
+ this.noZoom = true;
43
+ }
44
+ return true;
45
+ }
46
+ }
@@ -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,119 @@
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/PdfWidgetAnnotation.js';
7
+ import type { PdfAppearanceStream } from '../appearance/PdfAppearanceStream.js';
8
+ import type { FormContext, PdfFieldType } from './types.js';
9
+ /**
10
+ * Abstract base form field class. Extends PdfWidgetAnnotation with form-specific properties:
11
+ * FT, V, DA, Ff, T (name), field hierarchy (parent/children/siblings).
12
+ * Subclasses must implement generateAppearance().
13
+ */
14
+ export declare abstract class PdfFormField extends PdfWidgetAnnotation {
15
+ private _parent?;
16
+ defaultGenerateAppearance: boolean;
17
+ protected _appearanceStream?: PdfAppearanceStream;
18
+ protected _appearanceStreamYes?: PdfAppearanceStream;
19
+ form?: FormContext<PdfFormField>;
20
+ constructor(options?: {
21
+ other?: PdfIndirectObject;
22
+ form?: FormContext<PdfFormField>;
23
+ parent?: PdfFormField;
24
+ });
25
+ get parent(): PdfFormField | undefined;
26
+ set parent(field: PdfFormField | undefined);
27
+ get children(): PdfFormField[];
28
+ set children(fields: PdfFormField[]);
29
+ get siblings(): PdfFormField[];
30
+ get encodingMap(): Map<number, string> | undefined;
31
+ get fieldType(): PdfFieldType | null;
32
+ set fieldType(type: PdfFieldType | null);
33
+ get name(): string;
34
+ set name(name: string);
35
+ get defaultValue(): string;
36
+ set defaultValue(val: string);
37
+ get value(): string;
38
+ set value(val: string | PdfString);
39
+ get checked(): boolean;
40
+ set checked(isChecked: boolean);
41
+ get fontSize(): number | null;
42
+ set fontSize(size: number);
43
+ get fontName(): string | null;
44
+ set fontName(fontName: string);
45
+ set font(font: PdfFont | null);
46
+ get flags(): number;
47
+ set flags(flags: number);
48
+ private getFlag;
49
+ private setFlag;
50
+ get readOnly(): boolean;
51
+ set readOnly(v: boolean);
52
+ get required(): boolean;
53
+ set required(v: boolean);
54
+ get multiline(): boolean;
55
+ set multiline(v: boolean);
56
+ get password(): boolean;
57
+ set password(v: boolean);
58
+ get comb(): boolean;
59
+ get combField(): boolean;
60
+ set combField(v: boolean);
61
+ get combo(): boolean;
62
+ set combo(v: boolean);
63
+ get radio(): boolean;
64
+ set radio(v: boolean);
65
+ get noToggleToOff(): boolean;
66
+ set noToggleToOff(v: boolean);
67
+ get noExport(): boolean;
68
+ set noExport(v: boolean);
69
+ get pushButton(): boolean;
70
+ set pushButton(v: boolean);
71
+ get edit(): boolean;
72
+ set edit(v: boolean);
73
+ get sort(): boolean;
74
+ set sort(v: boolean);
75
+ get multiSelect(): boolean;
76
+ set multiSelect(v: boolean);
77
+ get doNotSpellCheck(): boolean;
78
+ set doNotSpellCheck(v: boolean);
79
+ get doNotScroll(): boolean;
80
+ set doNotScroll(v: boolean);
81
+ get commitOnSelChange(): boolean;
82
+ set commitOnSelChange(v: boolean);
83
+ get quadding(): number;
84
+ set quadding(q: number);
85
+ get options(): string[];
86
+ set options(options: string[]);
87
+ get defaultAppearance(): string | null;
88
+ set defaultAppearance(da: string);
89
+ get maxLen(): number | null;
90
+ set maxLen(maxLen: number | null);
91
+ get kids(): PdfObjectReference[];
92
+ set kids(kids: PdfObjectReference[]);
93
+ abstract generateAppearance(options?: {
94
+ makeReadOnly?: boolean;
95
+ textYOffset?: number;
96
+ }): boolean;
97
+ getAppearanceStream(): PdfStream | undefined;
98
+ getAppearanceStreamsForWriting(): {
99
+ primary: PdfAppearanceStream;
100
+ secondary?: PdfAppearanceStream;
101
+ } | undefined;
102
+ setAppearanceReference(appearanceStreamRef: PdfObjectReference, appearanceStreamYesRef?: PdfObjectReference): void;
103
+ private static _fallbackCtor?;
104
+ private static _registry;
105
+ static registerFieldType(ft: string, ctor: new (options?: {
106
+ other?: PdfIndirectObject;
107
+ form?: FormContext<PdfFormField>;
108
+ parent?: PdfFormField;
109
+ }) => PdfFormField, options?: {
110
+ fallback?: boolean;
111
+ }): void;
112
+ static create(options: {
113
+ other: PdfIndirectObject;
114
+ form: FormContext<PdfFormField>;
115
+ parent?: PdfFormField;
116
+ }): PdfFormField;
117
+ }
118
+ /** Backward compatible alias */
119
+ export { PdfFormField as PdfAcroFormField };