@cj-tech-master/excelts 9.1.0 → 9.2.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 (147) hide show
  1. package/README.md +16 -1
  2. package/dist/browser/modules/archive/compression/crc32.js +1 -1
  3. package/dist/browser/modules/archive/crypto/aes.d.ts +0 -8
  4. package/dist/browser/modules/archive/crypto/aes.js +1 -20
  5. package/dist/browser/modules/archive/crypto/index.d.ts +2 -1
  6. package/dist/browser/modules/archive/crypto/index.js +3 -1
  7. package/dist/browser/modules/csv/parse/row-processor.d.ts +1 -1
  8. package/dist/browser/modules/csv/worker/worker-script.generated.js +1 -1
  9. package/dist/browser/modules/excel/utils/cell-matrix.js +1 -0
  10. package/dist/browser/modules/excel/utils/encryptor.browser.d.ts +4 -5
  11. package/dist/browser/modules/excel/utils/encryptor.browser.js +7 -12
  12. package/dist/browser/modules/excel/utils/encryptor.d.ts +1 -1
  13. package/dist/browser/modules/excel/utils/encryptor.js +4 -7
  14. package/dist/browser/modules/pdf/builder/document-builder.d.ts +517 -0
  15. package/dist/browser/modules/pdf/builder/document-builder.js +1493 -0
  16. package/dist/browser/modules/pdf/builder/form-appearance.d.ts +56 -0
  17. package/dist/browser/modules/pdf/builder/form-appearance.js +140 -0
  18. package/dist/browser/modules/pdf/builder/image-utils.d.ts +39 -0
  19. package/dist/browser/modules/pdf/builder/image-utils.js +129 -0
  20. package/dist/browser/modules/pdf/builder/pdf-editor.d.ts +230 -0
  21. package/dist/browser/modules/pdf/builder/pdf-editor.js +1574 -0
  22. package/dist/browser/modules/pdf/builder/resource-merger.d.ts +41 -0
  23. package/dist/browser/modules/pdf/builder/resource-merger.js +258 -0
  24. package/dist/browser/modules/pdf/core/digital-signature.d.ts +109 -0
  25. package/dist/browser/modules/pdf/core/digital-signature.js +659 -0
  26. package/dist/browser/modules/pdf/core/encryption.js +8 -7
  27. package/dist/browser/modules/pdf/core/pdf-object.d.ts +11 -0
  28. package/dist/browser/modules/pdf/core/pdf-object.js +38 -0
  29. package/dist/browser/modules/pdf/core/pdf-stream.d.ts +32 -0
  30. package/dist/browser/modules/pdf/core/pdf-stream.js +66 -0
  31. package/dist/browser/modules/pdf/core/pdf-writer.d.ts +55 -1
  32. package/dist/browser/modules/pdf/core/pdf-writer.js +271 -6
  33. package/dist/browser/modules/pdf/core/pdfa.d.ts +62 -0
  34. package/dist/browser/modules/pdf/core/pdfa.js +261 -0
  35. package/dist/browser/modules/pdf/index.d.ts +11 -0
  36. package/dist/browser/modules/pdf/index.js +9 -0
  37. package/dist/browser/modules/pdf/reader/bookmark-extractor.d.ts +35 -0
  38. package/dist/browser/modules/pdf/reader/bookmark-extractor.js +324 -0
  39. package/dist/browser/modules/pdf/reader/pdf-decrypt.js +6 -5
  40. package/dist/browser/modules/pdf/reader/pdf-reader.d.ts +17 -0
  41. package/dist/browser/modules/pdf/reader/pdf-reader.js +26 -2
  42. package/dist/browser/modules/pdf/reader/table-extractor.d.ts +69 -0
  43. package/dist/browser/modules/pdf/reader/table-extractor.js +365 -0
  44. package/dist/browser/modules/pdf/render/layout-engine.d.ts +21 -1
  45. package/dist/browser/modules/pdf/render/layout-engine.js +112 -5
  46. package/dist/browser/modules/pdf/render/page-renderer.d.ts +2 -9
  47. package/dist/browser/modules/pdf/render/page-renderer.js +62 -103
  48. package/dist/browser/modules/pdf/render/pdf-exporter.js +2 -61
  49. package/dist/browser/modules/pdf/render/style-converter.d.ts +4 -0
  50. package/dist/browser/modules/pdf/render/style-converter.js +1 -1
  51. package/dist/browser/modules/pdf/types.d.ts +14 -1
  52. package/dist/browser/modules/stream/browser/readable.js +8 -2
  53. package/dist/browser/utils/crypto.browser.d.ts +64 -0
  54. package/dist/browser/{modules/pdf/core/crypto.js → utils/crypto.browser.js} +91 -101
  55. package/dist/browser/utils/crypto.d.ts +97 -0
  56. package/dist/browser/utils/crypto.js +209 -0
  57. package/dist/cjs/modules/archive/compression/crc32.js +1 -1
  58. package/dist/cjs/modules/archive/crypto/aes.js +2 -23
  59. package/dist/cjs/modules/archive/crypto/index.js +3 -1
  60. package/dist/cjs/modules/csv/worker/worker-script.generated.js +1 -1
  61. package/dist/cjs/modules/excel/utils/cell-matrix.js +1 -0
  62. package/dist/cjs/modules/excel/utils/encryptor.browser.js +7 -12
  63. package/dist/cjs/modules/excel/utils/encryptor.js +4 -10
  64. package/dist/cjs/modules/pdf/builder/document-builder.js +1532 -0
  65. package/dist/cjs/modules/pdf/builder/form-appearance.js +145 -0
  66. package/dist/cjs/modules/pdf/builder/image-utils.js +135 -0
  67. package/dist/cjs/modules/pdf/builder/pdf-editor.js +1612 -0
  68. package/dist/cjs/modules/pdf/builder/resource-merger.js +263 -0
  69. package/dist/cjs/modules/pdf/core/digital-signature.js +667 -0
  70. package/dist/cjs/modules/pdf/core/encryption.js +8 -7
  71. package/dist/cjs/modules/pdf/core/pdf-object.js +38 -0
  72. package/dist/cjs/modules/pdf/core/pdf-stream.js +66 -0
  73. package/dist/cjs/modules/pdf/core/pdf-writer.js +272 -6
  74. package/dist/cjs/modules/pdf/core/pdfa.js +266 -0
  75. package/dist/cjs/modules/pdf/index.js +19 -1
  76. package/dist/cjs/modules/pdf/reader/bookmark-extractor.js +327 -0
  77. package/dist/cjs/modules/pdf/reader/pdf-decrypt.js +6 -5
  78. package/dist/cjs/modules/pdf/reader/pdf-reader.js +26 -2
  79. package/dist/cjs/modules/pdf/reader/table-extractor.js +368 -0
  80. package/dist/cjs/modules/pdf/render/layout-engine.js +113 -4
  81. package/dist/cjs/modules/pdf/render/page-renderer.js +63 -105
  82. package/dist/cjs/modules/pdf/render/pdf-exporter.js +3 -62
  83. package/dist/cjs/modules/pdf/render/style-converter.js +1 -0
  84. package/dist/cjs/modules/stream/browser/readable.js +8 -2
  85. package/dist/cjs/{modules/pdf/core/crypto.js → utils/crypto.browser.js} +95 -102
  86. package/dist/cjs/utils/crypto.js +228 -0
  87. package/dist/esm/modules/archive/compression/crc32.js +1 -1
  88. package/dist/esm/modules/archive/crypto/aes.js +1 -20
  89. package/dist/esm/modules/archive/crypto/index.js +3 -1
  90. package/dist/esm/modules/csv/worker/worker-script.generated.js +1 -1
  91. package/dist/esm/modules/excel/utils/cell-matrix.js +1 -0
  92. package/dist/esm/modules/excel/utils/encryptor.browser.js +7 -12
  93. package/dist/esm/modules/excel/utils/encryptor.js +4 -7
  94. package/dist/esm/modules/pdf/builder/document-builder.js +1493 -0
  95. package/dist/esm/modules/pdf/builder/form-appearance.js +140 -0
  96. package/dist/esm/modules/pdf/builder/image-utils.js +129 -0
  97. package/dist/esm/modules/pdf/builder/pdf-editor.js +1574 -0
  98. package/dist/esm/modules/pdf/builder/resource-merger.js +258 -0
  99. package/dist/esm/modules/pdf/core/digital-signature.js +659 -0
  100. package/dist/esm/modules/pdf/core/encryption.js +8 -7
  101. package/dist/esm/modules/pdf/core/pdf-object.js +38 -0
  102. package/dist/esm/modules/pdf/core/pdf-stream.js +66 -0
  103. package/dist/esm/modules/pdf/core/pdf-writer.js +271 -6
  104. package/dist/esm/modules/pdf/core/pdfa.js +261 -0
  105. package/dist/esm/modules/pdf/index.js +9 -0
  106. package/dist/esm/modules/pdf/reader/bookmark-extractor.js +324 -0
  107. package/dist/esm/modules/pdf/reader/pdf-decrypt.js +6 -5
  108. package/dist/esm/modules/pdf/reader/pdf-reader.js +26 -2
  109. package/dist/esm/modules/pdf/reader/table-extractor.js +365 -0
  110. package/dist/esm/modules/pdf/render/layout-engine.js +112 -5
  111. package/dist/esm/modules/pdf/render/page-renderer.js +62 -103
  112. package/dist/esm/modules/pdf/render/pdf-exporter.js +2 -61
  113. package/dist/esm/modules/pdf/render/style-converter.js +1 -1
  114. package/dist/esm/modules/stream/browser/readable.js +8 -2
  115. package/dist/esm/{modules/pdf/core/crypto.js → utils/crypto.browser.js} +91 -101
  116. package/dist/esm/utils/crypto.js +209 -0
  117. package/dist/iife/excelts.iife.js +1248 -1074
  118. package/dist/iife/excelts.iife.js.map +1 -1
  119. package/dist/iife/excelts.iife.min.js +53 -54
  120. package/dist/types/modules/archive/crypto/aes.d.ts +0 -8
  121. package/dist/types/modules/archive/crypto/index.d.ts +2 -1
  122. package/dist/types/modules/csv/parse/row-processor.d.ts +1 -1
  123. package/dist/types/modules/excel/utils/encryptor.browser.d.ts +4 -5
  124. package/dist/types/modules/excel/utils/encryptor.d.ts +1 -1
  125. package/dist/types/modules/pdf/builder/document-builder.d.ts +517 -0
  126. package/dist/types/modules/pdf/builder/form-appearance.d.ts +56 -0
  127. package/dist/types/modules/pdf/builder/image-utils.d.ts +39 -0
  128. package/dist/types/modules/pdf/builder/pdf-editor.d.ts +230 -0
  129. package/dist/types/modules/pdf/builder/resource-merger.d.ts +41 -0
  130. package/dist/types/modules/pdf/core/digital-signature.d.ts +109 -0
  131. package/dist/types/modules/pdf/core/pdf-object.d.ts +11 -0
  132. package/dist/types/modules/pdf/core/pdf-stream.d.ts +32 -0
  133. package/dist/types/modules/pdf/core/pdf-writer.d.ts +55 -1
  134. package/dist/types/modules/pdf/core/pdfa.d.ts +62 -0
  135. package/dist/types/modules/pdf/index.d.ts +11 -0
  136. package/dist/types/modules/pdf/reader/bookmark-extractor.d.ts +35 -0
  137. package/dist/types/modules/pdf/reader/pdf-reader.d.ts +17 -0
  138. package/dist/types/modules/pdf/reader/table-extractor.d.ts +69 -0
  139. package/dist/types/modules/pdf/render/layout-engine.d.ts +21 -1
  140. package/dist/types/modules/pdf/render/page-renderer.d.ts +2 -9
  141. package/dist/types/modules/pdf/render/style-converter.d.ts +4 -0
  142. package/dist/types/modules/pdf/types.d.ts +14 -1
  143. package/dist/types/utils/crypto.browser.d.ts +64 -0
  144. package/dist/types/utils/crypto.d.ts +97 -0
  145. package/package.json +110 -111
  146. package/dist/browser/modules/pdf/core/crypto.d.ts +0 -65
  147. package/dist/types/modules/pdf/core/crypto.d.ts +0 -65
@@ -1,10 +1,9 @@
1
1
  /**
2
- * Browser-only Encryptor
3
- * Uses Web Crypto API (hardware accelerated)
2
+ * Browser-only Encryptor — uses shared crypto primitives from `@utils/crypto`.
4
3
  */
4
+ import { hashAsync, randomBytes } from "../../../utils/crypto.browser.js";
5
5
  import { base64ToUint8Array, uint8ArrayToBase64, stringToUtf16Le } from "../../../utils/utils.base.js";
6
6
  import { concatUint8Arrays } from "../../../utils/binary.js";
7
- // Helper to convert number to little-endian Uint8Array
8
7
  function uint32ToLe(num) {
9
8
  const arr = new Uint8Array(4);
10
9
  arr[0] = num & 0xff;
@@ -15,15 +14,13 @@ function uint32ToLe(num) {
15
14
  }
16
15
  const Encryptor = {
17
16
  /**
18
- * Calculate hash using Web Crypto API
17
+ * Calculate hash using shared crypto (Web Crypto API in browser).
19
18
  */
20
19
  async hash(algorithm, ...buffers) {
21
- const data = concatUint8Arrays(buffers);
22
- const hashBuffer = await crypto.subtle.digest(algorithm, new Uint8Array(data));
23
- return new Uint8Array(hashBuffer);
20
+ return hashAsync(algorithm, concatUint8Arrays(buffers));
24
21
  },
25
22
  /**
26
- * Convert password to hash
23
+ * Convert password to hash.
27
24
  */
28
25
  async convertPasswordToHash(password, hashAlgorithm, saltValue, spinCount) {
29
26
  const passwordBuffer = stringToUtf16Le(password);
@@ -35,12 +32,10 @@ const Encryptor = {
35
32
  return uint8ArrayToBase64(key);
36
33
  },
37
34
  /**
38
- * Generate cryptographically strong random bytes
35
+ * Generate cryptographically strong random bytes.
39
36
  */
40
37
  randomBytes(size) {
41
- const bytes = new Uint8Array(size);
42
- crypto.getRandomValues(bytes);
43
- return bytes;
38
+ return randomBytes(size);
44
39
  }
45
40
  };
46
41
  export { Encryptor };
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Node.js Encryptor - uses native crypto module
2
+ * Node.js Encryptor uses shared crypto primitives from `@utils/crypto`.
3
3
  */
4
4
  declare const Encryptor: {
5
5
  hash(algorithm: string, ...buffers: Uint8Array[]): Uint8Array;
@@ -1,7 +1,7 @@
1
1
  /**
2
- * Node.js Encryptor - uses native crypto module
2
+ * Node.js Encryptor uses shared crypto primitives from `@utils/crypto`.
3
3
  */
4
- import crypto from "crypto";
4
+ import { hash, randomBytes } from "../../../utils/crypto.browser.js";
5
5
  import { base64ToUint8Array, uint8ArrayToBase64, stringToUtf16Le } from "../../../utils/utils.base.js";
6
6
  import { concatUint8Arrays } from "../../../utils/binary.js";
7
7
  function uint32ToLe(num) {
@@ -14,10 +14,7 @@ function uint32ToLe(num) {
14
14
  }
15
15
  const Encryptor = {
16
16
  hash(algorithm, ...buffers) {
17
- const algo = algorithm.toLowerCase().replace(/-/g, "");
18
- const hash = crypto.createHash(algo);
19
- hash.update(concatUint8Arrays(buffers));
20
- return new Uint8Array(hash.digest());
17
+ return hash(algorithm, concatUint8Arrays(buffers));
21
18
  },
22
19
  async convertPasswordToHash(password, hashAlgorithm, saltValue, spinCount) {
23
20
  const passwordBuffer = stringToUtf16Le(password);
@@ -29,7 +26,7 @@ const Encryptor = {
29
26
  return uint8ArrayToBase64(key);
30
27
  },
31
28
  randomBytes(size) {
32
- return new Uint8Array(crypto.randomBytes(size));
29
+ return randomBytes(size);
33
30
  }
34
31
  };
35
32
  export { Encryptor };
@@ -0,0 +1,517 @@
1
+ /**
2
+ * PDF document builder — high-level API for creating PDFs with free-form content.
3
+ *
4
+ * Unlike the table-oriented `pdf()` function, this builder gives direct control
5
+ * over text positioning, vector drawing, images, and page management.
6
+ *
7
+ * @example Basic usage:
8
+ * ```typescript
9
+ * import { PdfDocumentBuilder } from "@cj-tech-master/excelts/pdf";
10
+ *
11
+ * const doc = new PdfDocumentBuilder();
12
+ * const page = doc.addPage({ width: 595, height: 842 }); // A4
13
+ *
14
+ * page.drawText("Hello, World!", { x: 72, y: 750, fontSize: 24 });
15
+ * page.drawRect({ x: 72, y: 700, width: 200, height: 30 });
16
+ * page.drawCircle({ cx: 300, cy: 400, r: 50, fill: { r: 1, g: 0, b: 0 } });
17
+ *
18
+ * const bytes = await doc.build();
19
+ * ```
20
+ */
21
+ import { PdfContentStream } from "../core/pdf-stream.js";
22
+ import type { PdfColor, PdfExportOptions } from "../types.js";
23
+ /** Page size configuration. */
24
+ export interface PageOptions {
25
+ /** Page width in points (72pt = 1 inch). Default: 595.28 (A4). */
26
+ width?: number;
27
+ /** Page height in points (72pt = 1 inch). Default: 841.89 (A4). */
28
+ height?: number;
29
+ }
30
+ /** Text drawing options. */
31
+ export interface DrawTextOptions {
32
+ /** X position in points (from left edge). */
33
+ x: number;
34
+ /** Y position in points (from bottom edge — PDF coordinate system). */
35
+ y: number;
36
+ /** Font size in points. Default: 12. */
37
+ fontSize?: number;
38
+ /** Font family name. Default: "Helvetica". */
39
+ fontFamily?: string;
40
+ /** Bold. Default: false. */
41
+ bold?: boolean;
42
+ /** Italic. Default: false. */
43
+ italic?: boolean;
44
+ /** Text color. Default: black. */
45
+ color?: PdfColor;
46
+ /** Maximum width before word-wrap. Omit for no wrap. */
47
+ maxWidth?: number;
48
+ /** Line height multiplier. Default: 1.2. */
49
+ lineHeight?: number;
50
+ }
51
+ /** Rectangle drawing options. */
52
+ export interface DrawRectOptions {
53
+ x: number;
54
+ y: number;
55
+ width: number;
56
+ height: number;
57
+ /** Fill color. Omit for no fill. */
58
+ fill?: PdfColor;
59
+ /** Stroke color. Omit for no stroke. */
60
+ stroke?: PdfColor;
61
+ /** Line width for stroke. Default: 1. */
62
+ lineWidth?: number;
63
+ /** Corner radius for rounded rectangles. Default: 0. */
64
+ borderRadius?: number;
65
+ }
66
+ /** Circle drawing options. */
67
+ export interface DrawCircleOptions {
68
+ /** Center X. */
69
+ cx: number;
70
+ /** Center Y. */
71
+ cy: number;
72
+ /** Radius. */
73
+ r: number;
74
+ /** Fill color. Omit for no fill. */
75
+ fill?: PdfColor;
76
+ /** Stroke color. Omit for no stroke. */
77
+ stroke?: PdfColor;
78
+ /** Line width for stroke. Default: 1. */
79
+ lineWidth?: number;
80
+ }
81
+ /** Ellipse drawing options. */
82
+ export interface DrawEllipseOptions {
83
+ /** Center X. */
84
+ cx: number;
85
+ /** Center Y. */
86
+ cy: number;
87
+ /** Horizontal radius. */
88
+ rx: number;
89
+ /** Vertical radius. */
90
+ ry: number;
91
+ /** Fill color. Omit for no fill. */
92
+ fill?: PdfColor;
93
+ /** Stroke color. Omit for no stroke. */
94
+ stroke?: PdfColor;
95
+ /** Line width for stroke. Default: 1. */
96
+ lineWidth?: number;
97
+ }
98
+ /** Line drawing options. */
99
+ export interface DrawLineOptions {
100
+ /** Start X. */
101
+ x1: number;
102
+ /** Start Y. */
103
+ y1: number;
104
+ /** End X. */
105
+ x2: number;
106
+ /** End Y. */
107
+ y2: number;
108
+ /** Stroke color. Default: black. */
109
+ color?: PdfColor;
110
+ /** Line width. Default: 1. */
111
+ lineWidth?: number;
112
+ /** Dash pattern. Default: solid. */
113
+ dashPattern?: number[];
114
+ }
115
+ /** Path drawing options. */
116
+ export interface DrawPathOptions {
117
+ /** Fill color. Omit for no fill. */
118
+ fill?: PdfColor;
119
+ /** Stroke color. Omit for no stroke. */
120
+ stroke?: PdfColor;
121
+ /** Line width. Default: 1. */
122
+ lineWidth?: number;
123
+ /** Close the path before painting. Default: false. */
124
+ closePath?: boolean;
125
+ }
126
+ /** A point in a path. */
127
+ export type PathOp = {
128
+ op: "move";
129
+ x: number;
130
+ y: number;
131
+ } | {
132
+ op: "line";
133
+ x: number;
134
+ y: number;
135
+ } | {
136
+ op: "curve";
137
+ x1: number;
138
+ y1: number;
139
+ x2: number;
140
+ y2: number;
141
+ x3: number;
142
+ y3: number;
143
+ } | {
144
+ op: "close";
145
+ };
146
+ /** Image drawing options. */
147
+ export interface DrawImageOptions {
148
+ /** Raw image bytes. */
149
+ data: Uint8Array;
150
+ /** Image format. */
151
+ format: "jpeg" | "png";
152
+ /** X position. */
153
+ x: number;
154
+ /** Y position (bottom edge of image in PDF coordinates). */
155
+ y: number;
156
+ /** Display width in points. */
157
+ width: number;
158
+ /** Display height in points. */
159
+ height: number;
160
+ }
161
+ /** Document metadata. */
162
+ export interface DocumentMetadata {
163
+ title?: string;
164
+ author?: string;
165
+ subject?: string;
166
+ creator?: string;
167
+ }
168
+ /** Options for table of contents generation. */
169
+ export interface TocOptions {
170
+ /** Title displayed at the top of the TOC page. Default: "Table of Contents". */
171
+ title?: string;
172
+ /** Font size for TOC entries in points. Default: 12. */
173
+ fontSize?: number;
174
+ /** Indentation in points per nesting level. Default: 20. */
175
+ indent?: number;
176
+ }
177
+ /** Annotation types that can be created via the builder API. */
178
+ export type AnnotationType = "Highlight" | "Underline" | "StrikeOut" | "Squiggly" | "Text" | "FreeText" | "Stamp";
179
+ /** Options for text markup annotations (Highlight, Underline, StrikeOut, Squiggly). */
180
+ export interface TextMarkupAnnotationOptions {
181
+ /** Annotation subtype. */
182
+ type: "Highlight" | "Underline" | "StrikeOut" | "Squiggly";
183
+ /** Bounding rectangle [x1, y1, x2, y2]. */
184
+ rect: [number, number, number, number];
185
+ /**
186
+ * QuadPoints — four pairs of (x,y) defining the marked text region.
187
+ * Must be groups of 8 numbers (4 corners per quad). Order per PDF spec:
188
+ * bottom-left, bottom-right, top-left, top-right (some viewers use
189
+ * top-left, top-right, bottom-left, bottom-right — the spec is ambiguous).
190
+ * If omitted, defaults to the corners of `rect`.
191
+ */
192
+ quadPoints?: number[];
193
+ /** Annotation color (RGB, 0–1). Default: yellow for highlight, red for others. */
194
+ color?: PdfColor;
195
+ /** Text contents (e.g., comment text). */
196
+ contents?: string;
197
+ /** Author / title. */
198
+ author?: string;
199
+ }
200
+ /** Options for a sticky note (Text) annotation. */
201
+ export interface TextAnnotationOptions {
202
+ type: "Text";
203
+ /** Position — the icon appears at this point. */
204
+ rect: [number, number, number, number];
205
+ /** Comment text. */
206
+ contents?: string;
207
+ /** Author. */
208
+ author?: string;
209
+ /** Icon name. Default: "Note". */
210
+ iconName?: "Comment" | "Key" | "Note" | "Help" | "NewParagraph" | "Paragraph" | "Insert";
211
+ /** Annotation color. Default: yellow. */
212
+ color?: PdfColor;
213
+ /** Whether the popup is initially open. Default: false. */
214
+ open?: boolean;
215
+ }
216
+ /** Options for a free-text annotation (in-line text). */
217
+ export interface FreeTextAnnotationOptions {
218
+ type: "FreeText";
219
+ /** Bounding rectangle [x1, y1, x2, y2]. */
220
+ rect: [number, number, number, number];
221
+ /** The displayed text. */
222
+ contents: string;
223
+ /** Font size. Default: 12. */
224
+ fontSize?: number;
225
+ /** Text color. Default: black. */
226
+ color?: PdfColor;
227
+ /** Border color. Omit for no border. */
228
+ borderColor?: PdfColor;
229
+ /** Author. */
230
+ author?: string;
231
+ }
232
+ /** Options for a rubber stamp annotation. */
233
+ export interface StampAnnotationOptions {
234
+ type: "Stamp";
235
+ /** Bounding rectangle [x1, y1, x2, y2]. */
236
+ rect: [number, number, number, number];
237
+ /** Standard stamp name. */
238
+ stampName?: "Approved" | "Experimental" | "NotApproved" | "AsIs" | "Expired" | "NotForPublicRelease" | "Confidential" | "Final" | "Sold" | "Departmental" | "ForComment" | "TopSecret" | "Draft" | "ForPublicRelease";
239
+ /** Annotation color. */
240
+ color?: PdfColor;
241
+ /** Comment text. */
242
+ contents?: string;
243
+ /** Author. */
244
+ author?: string;
245
+ }
246
+ /** Union of all annotation option types. */
247
+ export type AnnotationOptions = TextMarkupAnnotationOptions | TextAnnotationOptions | FreeTextAnnotationOptions | StampAnnotationOptions;
248
+ /** Common options shared by all form field types. */
249
+ interface FormFieldBaseOptions {
250
+ /** Fully qualified field name (e.g., "form.name"). */
251
+ name: string;
252
+ /** Bounding rectangle [x1, y1, x2, y2]. */
253
+ rect: [number, number, number, number];
254
+ /** Default value. */
255
+ value?: string;
256
+ /** Read-only. Default: false. */
257
+ readOnly?: boolean;
258
+ /** Required. Default: false. */
259
+ required?: boolean;
260
+ }
261
+ /** Options for creating a text input field. */
262
+ export interface TextFieldOptions extends FormFieldBaseOptions {
263
+ type: "text";
264
+ /** Maximum character count. Omit for unlimited. */
265
+ maxLength?: number;
266
+ /** Multiline. Default: false. */
267
+ multiline?: boolean;
268
+ /** Password field (masked input). Default: false. */
269
+ password?: boolean;
270
+ }
271
+ /** Options for creating a checkbox. */
272
+ export interface CheckboxOptions extends FormFieldBaseOptions {
273
+ type: "checkbox";
274
+ /** Whether initially checked. Default: false. */
275
+ checked?: boolean;
276
+ }
277
+ /** Options for creating a dropdown (combo box). */
278
+ export interface DropdownOptions extends FormFieldBaseOptions {
279
+ type: "dropdown";
280
+ /** Available options. */
281
+ options: string[];
282
+ /** Allow typing a custom value. Default: false. */
283
+ editable?: boolean;
284
+ }
285
+ /** Options for creating a radio button group. */
286
+ export interface RadioGroupOptions {
287
+ type: "radio";
288
+ /** Fully qualified field name for the group. */
289
+ name: string;
290
+ /** Individual radio buttons. */
291
+ buttons: Array<{
292
+ /** Bounding rectangle. */
293
+ rect: [number, number, number, number];
294
+ /** Export value for this button. */
295
+ value: string;
296
+ }>;
297
+ /** Initially selected value. */
298
+ selected?: string;
299
+ /** Read-only. Default: false. */
300
+ readOnly?: boolean;
301
+ /** Required. Default: false. */
302
+ required?: boolean;
303
+ }
304
+ /** Union of all form field creation options. */
305
+ export type FormFieldOptions = TextFieldOptions | CheckboxOptions | DropdownOptions | RadioGroupOptions;
306
+ /** Options for digitally signing a PDF. */
307
+ export interface PdfSignatureOptions {
308
+ /** DER-encoded X.509 certificate. */
309
+ certificate: Uint8Array;
310
+ /** DER-encoded PKCS#8 private key. */
311
+ privateKey: Uint8Array;
312
+ /** Signer name (displayed in PDF viewers). */
313
+ name?: string;
314
+ /** Reason for signing. */
315
+ reason?: string;
316
+ /** Location of signing. */
317
+ location?: string;
318
+ /** Contact info. */
319
+ contactInfo?: string;
320
+ }
321
+ /**
322
+ * Builder for a single PDF page.
323
+ *
324
+ * Provides methods for drawing text, shapes, and images at arbitrary positions.
325
+ * All coordinates use PDF's coordinate system: origin at bottom-left, Y increases upward.
326
+ */
327
+ export declare class PdfPageBuilder {
328
+ /** Page width in points. */
329
+ get width(): number;
330
+ /** Page height in points. */
331
+ get height(): number;
332
+ /**
333
+ * Draw text at a specific position.
334
+ *
335
+ * @param text - The text string to draw
336
+ * @param options - Position, font, color, etc.
337
+ */
338
+ drawText(text: string, options: DrawTextOptions): this;
339
+ /**
340
+ * Measure text width in points.
341
+ */
342
+ measureText(text: string, options?: {
343
+ fontSize?: number;
344
+ fontFamily?: string;
345
+ bold?: boolean;
346
+ italic?: boolean;
347
+ }): number;
348
+ /**
349
+ * Draw a rectangle (filled and/or stroked).
350
+ */
351
+ drawRect(options: DrawRectOptions): this;
352
+ /**
353
+ * Draw a circle (filled and/or stroked).
354
+ */
355
+ drawCircle(options: DrawCircleOptions): this;
356
+ /**
357
+ * Draw an ellipse (filled and/or stroked).
358
+ */
359
+ drawEllipse(options: DrawEllipseOptions): this;
360
+ /**
361
+ * Draw a straight line.
362
+ */
363
+ drawLine(options: DrawLineOptions): this;
364
+ /**
365
+ * Draw a complex path from a list of path operations.
366
+ */
367
+ drawPath(ops: PathOp[], options?: DrawPathOptions): this;
368
+ /**
369
+ * Draw an image at a specific position.
370
+ */
371
+ drawImage(options: DrawImageOptions): this;
372
+ /**
373
+ * Add an annotation to this page.
374
+ *
375
+ * Supports: Highlight, Underline, StrikeOut, Squiggly, Text (sticky note),
376
+ * FreeText (inline text), and Stamp.
377
+ */
378
+ addAnnotation(options: AnnotationOptions): this;
379
+ /**
380
+ * Add a form field to this page.
381
+ *
382
+ * Supports: text input, checkbox, dropdown (combo box), and radio button groups.
383
+ */
384
+ addFormField(options: FormFieldOptions): this;
385
+ /**
386
+ * Draw an SVG path from a `d` attribute string.
387
+ *
388
+ * Supports all SVG path commands: M, L, H, V, C, S, Q, T, A, Z
389
+ * (both absolute and relative).
390
+ *
391
+ * @param d - The SVG path data string (e.g., "M10 10 L90 90 Z")
392
+ * @param options - Fill/stroke options
393
+ */
394
+ drawSvgPath(d: string, options?: DrawPathOptions): this;
395
+ /**
396
+ * Get the raw content stream for advanced operations.
397
+ * Use this when the high-level API doesn't cover your use case.
398
+ */
399
+ getContentStream(): PdfContentStream;
400
+ }
401
+ /**
402
+ * Builder for constructing multi-page PDF documents with free-form content.
403
+ *
404
+ * Provides fine-grained control over text positioning, vector graphics,
405
+ * and page management — complementing the table-oriented `pdf()` function.
406
+ */
407
+ export declare class PdfDocumentBuilder {
408
+ private _pages;
409
+ private _bookmarks;
410
+ private _fontManager;
411
+ private _metadata;
412
+ private _encryption;
413
+ private _embeddedFont;
414
+ private _pdfA;
415
+ private _signatureOptions;
416
+ /**
417
+ * Add a new blank page to the document.
418
+ *
419
+ * @param options - Page dimensions. Default: A4 (595.28 x 841.89 points).
420
+ * @returns A PdfPageBuilder for the new page.
421
+ */
422
+ addPage(options?: PageOptions): PdfPageBuilder;
423
+ /**
424
+ * Set document metadata (title, author, etc.).
425
+ */
426
+ setMetadata(metadata: DocumentMetadata): this;
427
+ /**
428
+ * Set encryption options (AES-256).
429
+ */
430
+ setEncryption(encryption: PdfExportOptions["encryption"]): this;
431
+ /**
432
+ * Embed a TrueType font for Unicode/CJK support.
433
+ *
434
+ * @param fontBytes - Raw .ttf file bytes
435
+ */
436
+ embedFont(fontBytes: Uint8Array): this;
437
+ /**
438
+ * Enable PDF/A compliance output.
439
+ *
440
+ * Currently supports PDF/A-1b (ISO 19005-1, Level B — visual appearance
441
+ * preservation). When enabled, `build()` will:
442
+ *
443
+ * - Set PDF version to 1.4
444
+ * - Write XMP metadata with `pdfaid:part=1` and `pdfaid:conformance=B`
445
+ * - Write OutputIntents with an embedded sRGB ICC profile
446
+ * - Add `/MarkInfo << /Marked true >>` to the catalog
447
+ *
448
+ * **Limitation:** Type1 base fonts (Helvetica, Times-Roman, Courier, etc.)
449
+ * are not embedded. For strict PDF/A-1b font compliance, use `embedFont()`
450
+ * to embed a TrueType font.
451
+ *
452
+ * @param _level - Conformance level. Currently only "1b" is supported.
453
+ */
454
+ setPdfACompliance(_level?: "1b"): this;
455
+ /**
456
+ * Digitally sign the PDF during `build()`.
457
+ *
458
+ * When set, `build()` will:
459
+ * 1. Embed a signature dictionary with placeholder in the PDF
460
+ * 2. Compute the byte ranges and sign with RSA PKCS#1 v1.5 + SHA-256
461
+ * 3. Return the fully signed PDF bytes
462
+ *
463
+ * @param options - Certificate, private key, and optional signer metadata
464
+ *
465
+ * @example
466
+ * ```typescript
467
+ * doc.sign({
468
+ * certificate: certDerBytes,
469
+ * privateKey: pkcs8DerBytes,
470
+ * name: "John Doe",
471
+ * reason: "Document approval"
472
+ * });
473
+ * const signedPdf = await doc.build();
474
+ * ```
475
+ */
476
+ sign(options: PdfSignatureOptions): this;
477
+ /**
478
+ * Add a bookmark (PDF outline entry) pointing to a specific page.
479
+ *
480
+ * @param title - Bookmark display title
481
+ * @param pageIndex - Zero-based page index
482
+ * @param parent - Index of a previously added top-level bookmark to nest under (zero-based in insertion order). Omit for top-level.
483
+ * @returns this for chaining
484
+ */
485
+ addBookmark(title: string, pageIndex: number, parent?: number): this;
486
+ /**
487
+ * Generate a table of contents page with clickable entries.
488
+ *
489
+ * Each entry displays the bookmark title and a right-aligned page number,
490
+ * connected by a dotted leader. Entries link to their target pages.
491
+ *
492
+ * @param options - TOC formatting options
493
+ * @returns The created PdfPageBuilder for further customization
494
+ */
495
+ generateTableOfContents(options?: TocOptions): PdfPageBuilder;
496
+ /** Get all pages. */
497
+ get pages(): readonly PdfPageBuilder[];
498
+ /**
499
+ * Build the final PDF document.
500
+ *
501
+ * @returns The PDF file as Uint8Array.
502
+ */
503
+ build(): Promise<Uint8Array>;
504
+ }
505
+ /**
506
+ * Parse an SVG path `d` attribute into PathOp array.
507
+ *
508
+ * Supports all SVG path commands:
509
+ * - M/m (moveTo), L/l (lineTo), H/h (horizontal), V/v (vertical)
510
+ * - C/c (cubic Bézier), S/s (smooth cubic)
511
+ * - Q/q (quadratic Bézier), T/t (smooth quadratic)
512
+ * - A/a (elliptical arc), Z/z (close)
513
+ *
514
+ * Arc commands are approximated with cubic Bézier curves.
515
+ */
516
+ export declare function parseSvgPath(d: string): PathOp[];
517
+ export {};