modern-pdf-lib 0.25.0 → 0.28.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.
- package/README.md +16 -3
- package/dist/{batchOptimize-Ba_pWw71.cjs → batchOptimize-CXC9gNqD.cjs} +55 -55
- package/dist/{batchOptimize-DtRwBOqR.mjs → batchOptimize-CjLGD5ie.mjs} +25 -25
- package/dist/{bridge-DYCQzxF7.cjs → bridge-ByvzPu5h.cjs} +29 -31
- package/dist/{bridge-CcivG_Sm.mjs → bridge-ZD6O6QQa.mjs} +4 -5
- package/dist/browser.cjs +263 -151
- package/dist/browser.d.cts +166 -166
- package/dist/browser.d.cts.map +1 -1
- package/dist/browser.d.mts +166 -166
- package/dist/browser.d.mts.map +1 -1
- package/dist/browser.mjs +15 -19
- package/dist/cli/index.cjs +7 -7
- package/dist/cli/index.mjs +8 -8
- package/dist/{compressionAnalysis-odbHC7Uk.mjs → compressionAnalysis-BgKy45pA.mjs} +60 -74
- package/dist/{compressionAnalysis-DGs-MqTe.d.mts → compressionAnalysis-CDOp_vPr.d.mts} +136 -136
- package/dist/compressionAnalysis-CDOp_vPr.d.mts.map +1 -0
- package/dist/{compressionAnalysis-B84FPXaQ.cjs → compressionAnalysis-Djv-Zvcd.cjs} +90 -104
- package/dist/{compressionAnalysis-VtYV9Zmq.d.cts → compressionAnalysis-UfmonqbM.d.cts} +136 -136
- package/dist/compressionAnalysis-UfmonqbM.d.cts.map +1 -0
- package/dist/create.cjs +21 -23
- package/dist/create.d.cts +2 -2
- package/dist/create.d.mts +2 -2
- package/dist/create.mjs +3 -5
- package/dist/{deduplicateImages-MfUDPxQz.mjs → deduplicateImages-BTCyAPfJ.mjs} +4 -5
- package/dist/{deduplicateImages-cKsnD6Ep.cjs → deduplicateImages-CaGgaqyS.cjs} +14 -15
- package/dist/{fieldAppearance-C8PoLFSc.d.mts → fieldAppearance-Df1262CT.d.cts} +44 -44
- package/dist/fieldAppearance-Df1262CT.d.cts.map +1 -0
- package/dist/{fieldAppearance-CdiGFG5e.d.cts → fieldAppearance-_CZdoUCD.d.mts} +44 -44
- package/dist/fieldAppearance-_CZdoUCD.d.mts.map +1 -0
- package/dist/fontEmbed-DGiZS0h2.d.cts +677 -0
- package/dist/fontEmbed-DGiZS0h2.d.cts.map +1 -0
- package/dist/fontEmbed-DtA_riGC.d.mts +677 -0
- package/dist/fontEmbed-DtA_riGC.d.mts.map +1 -0
- package/dist/forms.cjs +3 -4
- package/dist/forms.d.cts +2 -2
- package/dist/forms.d.mts +2 -2
- package/dist/forms.mjs +2 -3
- package/dist/{grayscaleDetect-C6kFF3dk.mjs → grayscaleDetect-6GJrgBRT.mjs} +3 -3
- package/dist/{grayscaleDetect-C2m-eEXR.cjs → grayscaleDetect-DAUqxjgR.cjs} +13 -14
- package/dist/{imageExtract-zEb1gnkb.cjs → imageExtract-DT50Hp_g.cjs} +13 -14
- package/dist/{imageExtract-Dnk_Ssv7.mjs → imageExtract-Dapir-ux.mjs} +3 -4
- package/dist/index-C1lZe66f.d.mts +8682 -0
- package/dist/index-C1lZe66f.d.mts.map +1 -0
- package/dist/index-D1SvXWSI.d.cts +8682 -0
- package/dist/index-D1SvXWSI.d.cts.map +1 -0
- package/dist/index.cjs +263 -150
- package/dist/index.d.cts +7 -7
- package/dist/index.d.mts +7 -7
- package/dist/index.mjs +14 -17
- package/dist/{layout-DH61a1iR.cjs → layout-C4vbTlBW.cjs} +184 -134
- package/dist/{layout-D6EUKSP8.mjs → layout-lO4x64kY.mjs} +50 -12
- package/dist/{loader-C7B5dVCI.mjs → loader-B1Ix7ozU.mjs} +259 -13
- package/dist/{loader-I4zdkoWc.cjs → loader-DR7H0XOf.cjs} +343 -67
- package/dist/parse.cjs +7 -8
- package/dist/parse.d.cts +3 -3
- package/dist/parse.d.mts +3 -3
- package/dist/parse.mjs +6 -7
- package/dist/pdfDocument-CH2E4UCc.d.mts +5160 -0
- package/dist/pdfDocument-CH2E4UCc.d.mts.map +1 -0
- package/dist/{pdfDocument-CEbbUP9i.cjs → pdfDocument-C_7mrBCL.cjs} +20493 -9511
- package/dist/pdfDocument-CzOipXnw.d.cts +5160 -0
- package/dist/pdfDocument-CzOipXnw.d.cts.map +1 -0
- package/dist/{pdfDocument-B0_XwS4X.mjs → pdfDocument-DRbT6HZw.mjs} +11017 -863
- package/dist/{pdfForm-9gd40uz9.cjs → pdfForm-BVS_do95.cjs} +113 -102
- package/dist/pdfForm-Ca86NDWn.d.cts +897 -0
- package/dist/pdfForm-Ca86NDWn.d.cts.map +1 -0
- package/dist/pdfForm-Ca86NDWn.d.mts +897 -0
- package/dist/pdfForm-Ca86NDWn.d.mts.map +1 -0
- package/dist/{pdfForm-Cn-cVicP.mjs → pdfForm-CfLnlsj-.mjs} +23 -18
- package/dist/{pdfObjects-1veop1_d.cjs → pdfObjects-BcPlSI0a.cjs} +62 -53
- package/dist/{pdfObjects-uEsWlfzU.mjs → pdfObjects-CB7TEdbW.mjs} +12 -2
- package/dist/rolldown-runtime-ak5kbic3.cjs +18 -0
- package/dist/{src-B1iDGLCL.cjs → src-C-IDXuvi.cjs} +9886 -1421
- package/dist/{src-Db6Qknoz.mjs → src-DJaD-bJ2.mjs} +8392 -515
- package/dist/{streamDecode-Bj568Nc9.mjs → streamDecode-BamENT3k.mjs} +129 -150
- package/dist/{streamDecode-CvgErkFu.cjs → streamDecode-DcaZz309.cjs} +139 -160
- package/package.json +26 -22
- package/dist/compressionAnalysis-DGs-MqTe.d.mts.map +0 -1
- package/dist/compressionAnalysis-VtYV9Zmq.d.cts.map +0 -1
- package/dist/fflateAdapter-LTAeAhaD.cjs +0 -207
- package/dist/fflateAdapter-PSiW_ML7.mjs +0 -196
- package/dist/fieldAppearance-C8PoLFSc.d.mts.map +0 -1
- package/dist/fieldAppearance-CdiGFG5e.d.cts.map +0 -1
- package/dist/fontEmbed-BN842wlb.d.cts +0 -659
- package/dist/fontEmbed-BN842wlb.d.cts.map +0 -1
- package/dist/fontEmbed-Dgq5K89o.d.mts +0 -659
- package/dist/fontEmbed-Dgq5K89o.d.mts.map +0 -1
- package/dist/fontSubset-5SLWMmEw.cjs +0 -518
- package/dist/fontSubset-D-vQQems.mjs +0 -495
- package/dist/index-DCSbmXWh.d.mts +0 -5939
- package/dist/index-DCSbmXWh.d.mts.map +0 -1
- package/dist/index-J1W3FdL8.d.cts +0 -5939
- package/dist/index-J1W3FdL8.d.cts.map +0 -1
- package/dist/libdeflateWasm-8b91Vmia.mjs +0 -220
- package/dist/libdeflateWasm-BdiDEJOj.cjs +0 -237
- package/dist/pdfCatalog-3yMIhJtt.mjs +0 -138
- package/dist/pdfCatalog-CYy4NXEY.cjs +0 -173
- package/dist/pdfDocument-BgvEP5Po.d.mts +0 -4673
- package/dist/pdfDocument-BgvEP5Po.d.mts.map +0 -1
- package/dist/pdfDocument-CbU-2TjT.d.cts +0 -4673
- package/dist/pdfDocument-CbU-2TjT.d.cts.map +0 -1
- package/dist/pdfForm-BiyNtYem.d.mts +0 -905
- package/dist/pdfForm-BiyNtYem.d.mts.map +0 -1
- package/dist/pdfForm-SOXJ72LW.d.cts +0 -905
- package/dist/pdfForm-SOXJ72LW.d.cts.map +0 -1
- package/dist/pdfPage-B_d9HmkG.mjs +0 -8015
- package/dist/pdfPage-Cd8jOJp6.cjs +0 -8728
- package/dist/pngEmbed-BWAbEUKF.mjs +0 -552
- package/dist/pngEmbed-D4X4ZN-3.cjs +0 -563
- package/dist/rolldown-runtime-CKhH4XqG.cjs +0 -24
|
@@ -1,4673 +0,0 @@
|
|
|
1
|
-
import { C as PdfRef, S as PdfObjectRegistry, T as PdfString, _ as PdfDict, t as PdfForm, w as PdfStream, x as PdfObject } from "./pdfForm-BiyNtYem.mjs";
|
|
2
|
-
|
|
3
|
-
//#region src/core/operators/color.d.ts
|
|
4
|
-
/**
|
|
5
|
-
* @module core/operators/color
|
|
6
|
-
*
|
|
7
|
-
* PDF colour operators and convenience constructors for typed colour
|
|
8
|
-
* values.
|
|
9
|
-
*
|
|
10
|
-
* Reference: PDF 1.7 spec, §8.6 (Colour Spaces).
|
|
11
|
-
*/
|
|
12
|
-
/** An RGB colour with components in the range `[0, 1]`. */
|
|
13
|
-
interface RgbColor {
|
|
14
|
-
readonly type: 'rgb';
|
|
15
|
-
readonly r: number;
|
|
16
|
-
readonly g: number;
|
|
17
|
-
readonly b: number;
|
|
18
|
-
}
|
|
19
|
-
/** A CMYK colour with components in the range `[0, 1]`. */
|
|
20
|
-
interface CmykColor {
|
|
21
|
-
readonly type: 'cmyk';
|
|
22
|
-
readonly c: number;
|
|
23
|
-
readonly m: number;
|
|
24
|
-
readonly y: number;
|
|
25
|
-
readonly k: number;
|
|
26
|
-
}
|
|
27
|
-
/** A grayscale colour with the component in the range `[0, 1]`. */
|
|
28
|
-
interface GrayscaleColor {
|
|
29
|
-
readonly type: 'grayscale';
|
|
30
|
-
readonly gray: number;
|
|
31
|
-
}
|
|
32
|
-
/** Union of all supported colour value types. */
|
|
33
|
-
type Color = RgbColor | CmykColor | GrayscaleColor;
|
|
34
|
-
/**
|
|
35
|
-
* Create an RGB colour.
|
|
36
|
-
*
|
|
37
|
-
* @param r Red component `[0, 1]`.
|
|
38
|
-
* @param g Green component `[0, 1]`.
|
|
39
|
-
* @param b Blue component `[0, 1]`.
|
|
40
|
-
*/
|
|
41
|
-
declare function rgb(r: number, g: number, b: number): RgbColor;
|
|
42
|
-
/**
|
|
43
|
-
* Create a CMYK colour.
|
|
44
|
-
*
|
|
45
|
-
* @param c Cyan component `[0, 1]`.
|
|
46
|
-
* @param m Magenta component `[0, 1]`.
|
|
47
|
-
* @param y Yellow component `[0, 1]`.
|
|
48
|
-
* @param k Black component `[0, 1]`.
|
|
49
|
-
*/
|
|
50
|
-
declare function cmyk(c: number, m: number, y: number, k: number): CmykColor;
|
|
51
|
-
/**
|
|
52
|
-
* Create a grayscale colour.
|
|
53
|
-
*
|
|
54
|
-
* @param gray Gray level `[0, 1]` where 0 = black, 1 = white.
|
|
55
|
-
*/
|
|
56
|
-
declare function grayscale(gray: number): GrayscaleColor;
|
|
57
|
-
/**
|
|
58
|
-
* Set the fill colour in the DeviceRGB colour space (`rg`).
|
|
59
|
-
*
|
|
60
|
-
* @param r Red `[0, 1]`.
|
|
61
|
-
* @param g Green `[0, 1]`.
|
|
62
|
-
* @param b Blue `[0, 1]`.
|
|
63
|
-
*/
|
|
64
|
-
declare function setFillColorRgb(r: number, g: number, b: number): string;
|
|
65
|
-
/**
|
|
66
|
-
* Set the fill colour in the DeviceCMYK colour space (`k`).
|
|
67
|
-
*/
|
|
68
|
-
declare function setFillColorCmyk(c: number, m: number, y: number, k: number): string;
|
|
69
|
-
/**
|
|
70
|
-
* Set the fill colour in the DeviceGray colour space (`g`).
|
|
71
|
-
*/
|
|
72
|
-
declare function setFillColorGray(gray: number): string;
|
|
73
|
-
/**
|
|
74
|
-
* Set the stroke colour in the DeviceRGB colour space (`RG`).
|
|
75
|
-
*/
|
|
76
|
-
declare function setStrokeColorRgb(r: number, g: number, b: number): string;
|
|
77
|
-
/**
|
|
78
|
-
* Set the stroke colour in the DeviceCMYK colour space (`K`).
|
|
79
|
-
*/
|
|
80
|
-
declare function setStrokeColorCmyk(c: number, m: number, y: number, k: number): string;
|
|
81
|
-
/**
|
|
82
|
-
* Set the stroke colour in the DeviceGray colour space (`G`).
|
|
83
|
-
*/
|
|
84
|
-
declare function setStrokeColorGray(gray: number): string;
|
|
85
|
-
/**
|
|
86
|
-
* Set the current non-stroking colour space (`cs`).
|
|
87
|
-
*
|
|
88
|
-
* @param name Colour space name (e.g. `DeviceRGB`, `DeviceCMYK`,
|
|
89
|
-
* `DeviceGray`, or a named resource).
|
|
90
|
-
*/
|
|
91
|
-
declare function setColorSpace(name: string): string;
|
|
92
|
-
/**
|
|
93
|
-
* Set the current stroking colour space (`CS`).
|
|
94
|
-
*/
|
|
95
|
-
declare function setStrokeColorSpace(name: string): string;
|
|
96
|
-
/**
|
|
97
|
-
* Set the non-stroking colour in the current colour space (`scn`).
|
|
98
|
-
*
|
|
99
|
-
* @param components One or more colour components.
|
|
100
|
-
*/
|
|
101
|
-
declare function setFillColor(...components: number[]): string;
|
|
102
|
-
/**
|
|
103
|
-
* Set the stroking colour in the current colour space (`SCN`).
|
|
104
|
-
*
|
|
105
|
-
* @param components One or more colour components.
|
|
106
|
-
*/
|
|
107
|
-
declare function setStrokeColor(...components: number[]): string;
|
|
108
|
-
/**
|
|
109
|
-
* Emit the appropriate fill-colour operator for a {@link Color} value.
|
|
110
|
-
*/
|
|
111
|
-
declare function applyFillColor(color: Color): string;
|
|
112
|
-
/**
|
|
113
|
-
* Emit the appropriate stroke-colour operator for a {@link Color} value.
|
|
114
|
-
*/
|
|
115
|
-
declare function applyStrokeColor(color: Color): string;
|
|
116
|
-
/**
|
|
117
|
-
* Convert a numeric component array to a typed {@link Color}.
|
|
118
|
-
*
|
|
119
|
-
* - 1 component → grayscale
|
|
120
|
-
* - 3 components → RGB
|
|
121
|
-
* - 4 components → CMYK
|
|
122
|
-
*
|
|
123
|
-
* @param components Array of color component values `[0, 1]`.
|
|
124
|
-
* @throws If the array length is not 1, 3, or 4.
|
|
125
|
-
*/
|
|
126
|
-
declare function componentsToColor(components: number[]): Color;
|
|
127
|
-
/**
|
|
128
|
-
* Convert a typed {@link Color} to a numeric component array.
|
|
129
|
-
*
|
|
130
|
-
* - Grayscale → `[gray]`
|
|
131
|
-
* - RGB → `[r, g, b]`
|
|
132
|
-
* - CMYK → `[c, m, y, k]`
|
|
133
|
-
*/
|
|
134
|
-
declare function colorToComponents(color: Color): number[];
|
|
135
|
-
/**
|
|
136
|
-
* Emit the appropriate fill-colour operator for a {@link Color} value.
|
|
137
|
-
*
|
|
138
|
-
* Alias for {@link applyFillColor} for pdf-lib API compatibility.
|
|
139
|
-
*/
|
|
140
|
-
declare const setFillingColor: typeof applyFillColor;
|
|
141
|
-
/**
|
|
142
|
-
* Emit the appropriate stroke-colour operator for a {@link Color} value.
|
|
143
|
-
*
|
|
144
|
-
* Alias for {@link applyStrokeColor} for pdf-lib API compatibility.
|
|
145
|
-
*/
|
|
146
|
-
declare const setStrokingColor: typeof applyStrokeColor;
|
|
147
|
-
//#endregion
|
|
148
|
-
//#region src/core/operators/state.d.ts
|
|
149
|
-
/**
|
|
150
|
-
* @module core/operators/state
|
|
151
|
-
*
|
|
152
|
-
* PDF graphics-state operators (`q`, `Q`, `cm`) and rotation helpers.
|
|
153
|
-
*
|
|
154
|
-
* Reference: PDF 1.7 spec, §8.4.2 (Graphics State Operators) and
|
|
155
|
-
* §8.3.3 (Common Transformations).
|
|
156
|
-
*/
|
|
157
|
-
/** A rotation / angle value in radians. */
|
|
158
|
-
interface Radians {
|
|
159
|
-
readonly type: 'radians';
|
|
160
|
-
readonly value: number;
|
|
161
|
-
}
|
|
162
|
-
/** A rotation / angle value in degrees. */
|
|
163
|
-
interface Degrees {
|
|
164
|
-
readonly type: 'degrees';
|
|
165
|
-
readonly value: number;
|
|
166
|
-
}
|
|
167
|
-
/** Union of angle representations. */
|
|
168
|
-
type Angle = Radians | Degrees;
|
|
169
|
-
/**
|
|
170
|
-
* Create an angle in degrees.
|
|
171
|
-
*
|
|
172
|
-
* @param deg Angle in degrees (positive = counter-clockwise).
|
|
173
|
-
*/
|
|
174
|
-
declare function degrees(deg: number): Degrees;
|
|
175
|
-
/**
|
|
176
|
-
* Create an angle in radians.
|
|
177
|
-
*
|
|
178
|
-
* @param rad Angle in radians (positive = counter-clockwise).
|
|
179
|
-
*/
|
|
180
|
-
declare function radians(rad: number): Radians;
|
|
181
|
-
/**
|
|
182
|
-
* Save the current graphics state on the graphics state stack (`q`).
|
|
183
|
-
*/
|
|
184
|
-
declare function saveState(): string;
|
|
185
|
-
/**
|
|
186
|
-
* Restore the most recently saved graphics state (`Q`).
|
|
187
|
-
*/
|
|
188
|
-
declare function restoreState(): string;
|
|
189
|
-
/**
|
|
190
|
-
* Concatenate the given matrix with the current transformation matrix
|
|
191
|
-
* (`cm`).
|
|
192
|
-
*
|
|
193
|
-
* The six operands define the matrix:
|
|
194
|
-
*
|
|
195
|
-
* ```
|
|
196
|
-
* [ a b 0 ]
|
|
197
|
-
* [ c d 0 ]
|
|
198
|
-
* [ tx ty 1 ]
|
|
199
|
-
* ```
|
|
200
|
-
*
|
|
201
|
-
* @param a Horizontal scaling / rotation.
|
|
202
|
-
* @param b Rotation / skew.
|
|
203
|
-
* @param c Rotation / skew.
|
|
204
|
-
* @param d Vertical scaling / rotation.
|
|
205
|
-
* @param tx Horizontal translation.
|
|
206
|
-
* @param ty Vertical translation.
|
|
207
|
-
*/
|
|
208
|
-
declare function concatMatrix(a: number, b: number, c: number, d: number, tx: number, ty: number): string;
|
|
209
|
-
/**
|
|
210
|
-
* Produce a `cm` operator that applies a **translation**.
|
|
211
|
-
*
|
|
212
|
-
* @param tx Horizontal distance.
|
|
213
|
-
* @param ty Vertical distance.
|
|
214
|
-
*/
|
|
215
|
-
declare function translate(tx: number, ty: number): string;
|
|
216
|
-
/**
|
|
217
|
-
* Produce a `cm` operator that applies a **uniform scale** about the
|
|
218
|
-
* origin.
|
|
219
|
-
*
|
|
220
|
-
* @param sx Horizontal scale factor.
|
|
221
|
-
* @param sy Vertical scale factor.
|
|
222
|
-
*/
|
|
223
|
-
declare function scale(sx: number, sy: number): string;
|
|
224
|
-
/**
|
|
225
|
-
* Produce a `cm` operator that applies a **rotation** about the origin.
|
|
226
|
-
*
|
|
227
|
-
* @param angle Rotation angle.
|
|
228
|
-
*/
|
|
229
|
-
declare function rotate(angle: Angle): string;
|
|
230
|
-
/**
|
|
231
|
-
* Produce a `cm` operator that applies a **skew** (shear).
|
|
232
|
-
*
|
|
233
|
-
* @param xAngle Skew angle for the x axis.
|
|
234
|
-
* @param yAngle Skew angle for the y axis.
|
|
235
|
-
*/
|
|
236
|
-
declare function skew(xAngle: Angle, yAngle: Angle): string;
|
|
237
|
-
/**
|
|
238
|
-
* Build the six-component matrix array for a rotation about an
|
|
239
|
-
* arbitrary centre point `(cx, cy)`.
|
|
240
|
-
*
|
|
241
|
-
* Useful when you need to compose this with other transformations
|
|
242
|
-
* before emitting operators.
|
|
243
|
-
*
|
|
244
|
-
* @returns `[a, b, c, d, tx, ty]`
|
|
245
|
-
*/
|
|
246
|
-
declare function rotationMatrix(angle: Angle, cx: number, cy: number): [number, number, number, number, number, number];
|
|
247
|
-
/**
|
|
248
|
-
* Set the graphics state dictionary (`gs`).
|
|
249
|
-
*
|
|
250
|
-
* The `name` must refer to an entry in the page's `/Resources /ExtGState`
|
|
251
|
-
* dictionary.
|
|
252
|
-
*
|
|
253
|
-
* @param name Graphics-state resource name (e.g. `GS1`).
|
|
254
|
-
*/
|
|
255
|
-
declare function setGraphicsState(name: string): string;
|
|
256
|
-
/**
|
|
257
|
-
* Convert degrees to radians.
|
|
258
|
-
*
|
|
259
|
-
* @param deg Angle in degrees.
|
|
260
|
-
* @returns Angle in radians.
|
|
261
|
-
*/
|
|
262
|
-
declare function degreesToRadians(deg: number): number;
|
|
263
|
-
/**
|
|
264
|
-
* Convert radians to degrees.
|
|
265
|
-
*
|
|
266
|
-
* @param rad Angle in radians.
|
|
267
|
-
* @returns Angle in degrees.
|
|
268
|
-
*/
|
|
269
|
-
declare function radiansToDegrees(rad: number): number;
|
|
270
|
-
//#endregion
|
|
271
|
-
//#region src/core/enums.d.ts
|
|
272
|
-
/**
|
|
273
|
-
* PDF blend modes (PDF 1.4+, Table 136).
|
|
274
|
-
* Applied via ExtGState /BM key.
|
|
275
|
-
*/
|
|
276
|
-
declare const BlendMode: {
|
|
277
|
-
readonly Normal: "Normal";
|
|
278
|
-
readonly Multiply: "Multiply";
|
|
279
|
-
readonly Screen: "Screen";
|
|
280
|
-
readonly Overlay: "Overlay";
|
|
281
|
-
readonly Darken: "Darken";
|
|
282
|
-
readonly Lighten: "Lighten";
|
|
283
|
-
readonly ColorDodge: "ColorDodge";
|
|
284
|
-
readonly ColorBurn: "ColorBurn";
|
|
285
|
-
readonly HardLight: "HardLight";
|
|
286
|
-
readonly SoftLight: "SoftLight";
|
|
287
|
-
readonly Difference: "Difference";
|
|
288
|
-
readonly Exclusion: "Exclusion";
|
|
289
|
-
};
|
|
290
|
-
/** A PDF blend mode name. */
|
|
291
|
-
type BlendMode = (typeof BlendMode)[keyof typeof BlendMode];
|
|
292
|
-
/**
|
|
293
|
-
* PDF text rendering modes (Table 106).
|
|
294
|
-
* Applied via the Tr operator inside a text object.
|
|
295
|
-
*/
|
|
296
|
-
declare const TextRenderingMode: {
|
|
297
|
-
readonly Fill: 0;
|
|
298
|
-
readonly Outline: 1;
|
|
299
|
-
readonly FillAndOutline: 2;
|
|
300
|
-
readonly Invisible: 3;
|
|
301
|
-
readonly FillAndClip: 4;
|
|
302
|
-
readonly OutlineAndClip: 5;
|
|
303
|
-
readonly FillAndOutlineAndClip: 6;
|
|
304
|
-
readonly Clip: 7;
|
|
305
|
-
};
|
|
306
|
-
/** A PDF text rendering mode integer (0-7). */
|
|
307
|
-
type TextRenderingMode = (typeof TextRenderingMode)[keyof typeof TextRenderingMode];
|
|
308
|
-
/**
|
|
309
|
-
* PDF line cap styles (Table 54).
|
|
310
|
-
* Applied via the J operator.
|
|
311
|
-
*/
|
|
312
|
-
declare const LineCapStyle: {
|
|
313
|
-
readonly Butt: 0;
|
|
314
|
-
readonly Round: 1;
|
|
315
|
-
readonly Projecting: 2;
|
|
316
|
-
};
|
|
317
|
-
type LineCapStyle = (typeof LineCapStyle)[keyof typeof LineCapStyle];
|
|
318
|
-
/**
|
|
319
|
-
* PDF line join styles (Table 55).
|
|
320
|
-
* Applied via the j operator.
|
|
321
|
-
*/
|
|
322
|
-
declare const LineJoinStyle: {
|
|
323
|
-
readonly Miter: 0;
|
|
324
|
-
readonly Round: 1;
|
|
325
|
-
readonly Bevel: 2;
|
|
326
|
-
};
|
|
327
|
-
type LineJoinStyle = (typeof LineJoinStyle)[keyof typeof LineJoinStyle];
|
|
328
|
-
/**
|
|
329
|
-
* Text alignment for form fields and layout operations.
|
|
330
|
-
*/
|
|
331
|
-
declare const TextAlignment: {
|
|
332
|
-
readonly Left: 0;
|
|
333
|
-
readonly Center: 1;
|
|
334
|
-
readonly Right: 2;
|
|
335
|
-
};
|
|
336
|
-
type TextAlignment = (typeof TextAlignment)[keyof typeof TextAlignment];
|
|
337
|
-
/**
|
|
338
|
-
* Image alignment for layout operations.
|
|
339
|
-
*/
|
|
340
|
-
declare const ImageAlignment: {
|
|
341
|
-
readonly Left: 0;
|
|
342
|
-
readonly Center: 1;
|
|
343
|
-
readonly Right: 2;
|
|
344
|
-
};
|
|
345
|
-
type ImageAlignment = (typeof ImageAlignment)[keyof typeof ImageAlignment];
|
|
346
|
-
/**
|
|
347
|
-
* Preset parsing speeds — maps to objectsPerTick values in LoadPdfOptions.
|
|
348
|
-
*
|
|
349
|
-
* Lower values keep the main thread more responsive but parse more slowly.
|
|
350
|
-
*/
|
|
351
|
-
declare const ParseSpeeds: {
|
|
352
|
-
readonly Fastest: number;
|
|
353
|
-
readonly Fast: 500;
|
|
354
|
-
readonly Medium: 100;
|
|
355
|
-
readonly Slow: 10;
|
|
356
|
-
};
|
|
357
|
-
type ParseSpeeds = (typeof ParseSpeeds)[keyof typeof ParseSpeeds];
|
|
358
|
-
//#endregion
|
|
359
|
-
//#region src/accessibility/structureTree.d.ts
|
|
360
|
-
/**
|
|
361
|
-
* Standard structure types defined by the PDF specification (ISO 32000-1,
|
|
362
|
-
* Table 333 through Table 340), plus a `string` catch-all for custom
|
|
363
|
-
* structure types.
|
|
364
|
-
*
|
|
365
|
-
* Groups:
|
|
366
|
-
* - **Grouping**: Document, Part, Art, Sect, Div, BlockQuote, Caption,
|
|
367
|
-
* TOC, TOCI, Index, NonStruct, Private
|
|
368
|
-
* - **Block-level**: P, H, H1..H6
|
|
369
|
-
* - **List**: L, LI, Lbl, LBody
|
|
370
|
-
* - **Table**: Table, TR, TH, TD, THead, TBody, TFoot
|
|
371
|
-
* - **Inline-level**: Span, Quote, Note, Reference, BibEntry, Code,
|
|
372
|
-
* Link, Annot
|
|
373
|
-
* - **Ruby / Warichu**: Ruby, RB, RT, RP, Warichu, WT, WP
|
|
374
|
-
* - **Illustration**: Figure, Formula, Form
|
|
375
|
-
*/
|
|
376
|
-
type StructureType = 'Document' | 'Part' | 'Art' | 'Sect' | 'Div' | 'BlockQuote' | 'Caption' | 'TOC' | 'TOCI' | 'Index' | 'NonStruct' | 'Private' | 'P' | 'H' | 'H1' | 'H2' | 'H3' | 'H4' | 'H5' | 'H6' | 'L' | 'LI' | 'Lbl' | 'LBody' | 'Table' | 'TR' | 'TH' | 'TD' | 'THead' | 'TBody' | 'TFoot' | 'Span' | 'Quote' | 'Note' | 'Reference' | 'BibEntry' | 'Code' | 'Link' | 'Annot' | 'Ruby' | 'RB' | 'RT' | 'RP' | 'Warichu' | 'WT' | 'WP' | 'Figure' | 'Formula' | 'Form' | (string & {});
|
|
377
|
-
/**
|
|
378
|
-
* Optional attributes for a structure element.
|
|
379
|
-
*/
|
|
380
|
-
interface StructureElementOptions {
|
|
381
|
-
/** The element title (a human-readable label). */
|
|
382
|
-
title?: string | undefined;
|
|
383
|
-
/** Alternative text for the element (required for images by PDF/UA). */
|
|
384
|
-
altText?: string | undefined;
|
|
385
|
-
/** Replacement text that may be used instead of the element's content. */
|
|
386
|
-
actualText?: string | undefined;
|
|
387
|
-
/** The natural language for this element (BCP 47, e.g. `"en-US"`). */
|
|
388
|
-
language?: string | undefined;
|
|
389
|
-
/** An optional unique identifier for the element. */
|
|
390
|
-
id?: string | undefined;
|
|
391
|
-
}
|
|
392
|
-
/**
|
|
393
|
-
* Describes a single accessibility issue found during validation.
|
|
394
|
-
*/
|
|
395
|
-
interface AccessibilityIssue {
|
|
396
|
-
/** Severity of the issue. */
|
|
397
|
-
severity: 'error' | 'warning' | 'info';
|
|
398
|
-
/** Machine-readable issue code. */
|
|
399
|
-
code: string;
|
|
400
|
-
/** Human-readable description of the issue. */
|
|
401
|
-
message: string;
|
|
402
|
-
/** The structure element related to the issue, if any. */
|
|
403
|
-
element?: PdfStructureElement | undefined;
|
|
404
|
-
/** The zero-based page index related to the issue, if any. */
|
|
405
|
-
pageIndex?: number | undefined;
|
|
406
|
-
}
|
|
407
|
-
/**
|
|
408
|
-
* A single node in the structure tree.
|
|
409
|
-
*
|
|
410
|
-
* Structure elements form a tree that mirrors the logical reading order
|
|
411
|
-
* of the document. Each element has a type (e.g. `"P"`, `"H1"`,
|
|
412
|
-
* `"Table"`), optional attributes, and may contain child elements or
|
|
413
|
-
* marked-content references (MCIDs) that link to the actual page
|
|
414
|
-
* content.
|
|
415
|
-
*/
|
|
416
|
-
declare class PdfStructureElement {
|
|
417
|
-
/** The structure type of this element. */
|
|
418
|
-
readonly type: StructureType;
|
|
419
|
-
/** Child structure elements. */
|
|
420
|
-
readonly children: PdfStructureElement[];
|
|
421
|
-
/** Optional attributes (alt text, language, title, etc.). */
|
|
422
|
-
readonly options: StructureElementOptions;
|
|
423
|
-
/** Marked content ID linking this element to page content. */
|
|
424
|
-
mcid?: number | undefined;
|
|
425
|
-
/** Zero-based page index this element's content appears on. */
|
|
426
|
-
pageIndex?: number | undefined;
|
|
427
|
-
/** The parent element (undefined for the root). */
|
|
428
|
-
parent?: PdfStructureElement | undefined;
|
|
429
|
-
/**
|
|
430
|
-
* @param type The structure type (e.g. `"P"`, `"H1"`, `"Figure"`).
|
|
431
|
-
* @param options Optional attributes for the element.
|
|
432
|
-
*/
|
|
433
|
-
constructor(type: StructureType, options?: StructureElementOptions);
|
|
434
|
-
/**
|
|
435
|
-
* Add a child element to this node.
|
|
436
|
-
*
|
|
437
|
-
* @param type The child's structure type.
|
|
438
|
-
* @param options Optional attributes for the child.
|
|
439
|
-
* @returns The newly created child element.
|
|
440
|
-
*/
|
|
441
|
-
addChild(type: StructureType, options?: StructureElementOptions): PdfStructureElement;
|
|
442
|
-
/**
|
|
443
|
-
* Remove a direct child element.
|
|
444
|
-
*
|
|
445
|
-
* @param element The child to remove.
|
|
446
|
-
* @throws If the element is not a direct child.
|
|
447
|
-
*/
|
|
448
|
-
removeChild(element: PdfStructureElement): void;
|
|
449
|
-
/**
|
|
450
|
-
* Recursively collect all elements in the subtree (depth-first,
|
|
451
|
-
* including this element).
|
|
452
|
-
*/
|
|
453
|
-
walk(): PdfStructureElement[];
|
|
454
|
-
/**
|
|
455
|
-
* Find the first descendant (or self) matching the given type.
|
|
456
|
-
*/
|
|
457
|
-
find(type: StructureType): PdfStructureElement | undefined;
|
|
458
|
-
/**
|
|
459
|
-
* Find all descendants (and self) matching the given type.
|
|
460
|
-
*/
|
|
461
|
-
findAll(type: StructureType): PdfStructureElement[];
|
|
462
|
-
/**
|
|
463
|
-
* Return the depth of this element in the tree (root = 0).
|
|
464
|
-
*/
|
|
465
|
-
depth(): number;
|
|
466
|
-
/**
|
|
467
|
-
* Serialize this element to a PDF dictionary.
|
|
468
|
-
*
|
|
469
|
-
* @param registry Object registry for allocating indirect references.
|
|
470
|
-
* @param parentRef Reference to the parent element (or StructTreeRoot).
|
|
471
|
-
* @param pageRefs Array of page references indexed by page number.
|
|
472
|
-
* @returns An object containing the element's dict and its ref.
|
|
473
|
-
*/
|
|
474
|
-
toDict(registry: PdfObjectRegistry, parentRef: PdfRef, pageRefs: readonly PdfRef[]): {
|
|
475
|
-
ref: PdfRef;
|
|
476
|
-
dict: PdfDict;
|
|
477
|
-
};
|
|
478
|
-
}
|
|
479
|
-
/**
|
|
480
|
-
* The structure tree for a tagged PDF document.
|
|
481
|
-
*
|
|
482
|
-
* Manages the root `Document` element, assigns marked-content IDs
|
|
483
|
-
* (MCIDs), and provides serialization to/from PDF dictionaries.
|
|
484
|
-
*
|
|
485
|
-
* Usage:
|
|
486
|
-
* ```ts
|
|
487
|
-
* const tree = doc.createStructureTree();
|
|
488
|
-
* const heading = tree.addElement(null, 'H1', { altText: 'Main heading' });
|
|
489
|
-
* tree.assignMcid(heading, 0);
|
|
490
|
-
*
|
|
491
|
-
* const para = tree.addElement(null, 'P');
|
|
492
|
-
* tree.assignMcid(para, 0);
|
|
493
|
-
* ```
|
|
494
|
-
*/
|
|
495
|
-
declare class PdfStructureTree {
|
|
496
|
-
/** The root `Document` structure element. */
|
|
497
|
-
readonly root: PdfStructureElement;
|
|
498
|
-
/** Next available marked-content ID. */
|
|
499
|
-
private nextMcid;
|
|
500
|
-
constructor();
|
|
501
|
-
/**
|
|
502
|
-
* Add an element to the structure tree.
|
|
503
|
-
*
|
|
504
|
-
* @param parent The parent element, or `null` to add directly under
|
|
505
|
-
* the root `Document` element.
|
|
506
|
-
* @param type The structure type of the new element.
|
|
507
|
-
* @param options Optional attributes for the element.
|
|
508
|
-
* @returns The newly created element.
|
|
509
|
-
*/
|
|
510
|
-
addElement(parent: PdfStructureElement | null, type: StructureType, options?: StructureElementOptions): PdfStructureElement;
|
|
511
|
-
/**
|
|
512
|
-
* Remove an element from the tree.
|
|
513
|
-
*
|
|
514
|
-
* @param element The element to remove (must not be the root).
|
|
515
|
-
* @throws If the element is the root or has no parent.
|
|
516
|
-
*/
|
|
517
|
-
removeElement(element: PdfStructureElement): void;
|
|
518
|
-
/**
|
|
519
|
-
* Assign a marked-content ID to an element and associate it with a
|
|
520
|
-
* page. The MCID links the structure element to the actual content
|
|
521
|
-
* on the page (via BMC/BDC operators in the content stream).
|
|
522
|
-
*
|
|
523
|
-
* @param element The element to assign an MCID to.
|
|
524
|
-
* @param pageIndex The zero-based page index the content appears on.
|
|
525
|
-
* @returns The assigned MCID.
|
|
526
|
-
*/
|
|
527
|
-
assignMcid(element: PdfStructureElement, pageIndex: number): number;
|
|
528
|
-
/**
|
|
529
|
-
* Return all elements in the tree (depth-first traversal from root).
|
|
530
|
-
*/
|
|
531
|
-
getAllElements(): PdfStructureElement[];
|
|
532
|
-
/**
|
|
533
|
-
* Return the current MCID counter value (useful for testing).
|
|
534
|
-
*/
|
|
535
|
-
getNextMcid(): number;
|
|
536
|
-
/**
|
|
537
|
-
* Serialize the structure tree to a `/StructTreeRoot` dictionary.
|
|
538
|
-
*
|
|
539
|
-
* The resulting dict is suitable for embedding in the PDF catalog
|
|
540
|
-
* as `/StructTreeRoot`.
|
|
541
|
-
*
|
|
542
|
-
* @param registry Object registry for allocating indirect references.
|
|
543
|
-
* @param pageRefs Array of page references indexed by page number.
|
|
544
|
-
* @returns An object containing the StructTreeRoot ref and dict.
|
|
545
|
-
*/
|
|
546
|
-
toDict(registry: PdfObjectRegistry, pageRefs: readonly PdfRef[]): {
|
|
547
|
-
ref: PdfRef;
|
|
548
|
-
dict: PdfDict;
|
|
549
|
-
};
|
|
550
|
-
/**
|
|
551
|
-
* Build the /ParentTree number tree.
|
|
552
|
-
*
|
|
553
|
-
* The parent tree maps each MCID to the structure element that
|
|
554
|
-
* "owns" it. This is implemented as a number tree (a sorted
|
|
555
|
-
* array of [key, value] pairs stored in /Nums).
|
|
556
|
-
*
|
|
557
|
-
* @internal
|
|
558
|
-
*/
|
|
559
|
-
private buildParentTree;
|
|
560
|
-
/**
|
|
561
|
-
* Build the /IDTree name tree.
|
|
562
|
-
*
|
|
563
|
-
* Maps element IDs (strings) to their structure element references.
|
|
564
|
-
*
|
|
565
|
-
* @internal
|
|
566
|
-
*/
|
|
567
|
-
private buildIdTree;
|
|
568
|
-
/**
|
|
569
|
-
* Reconstruct a structure tree from a `/StructTreeRoot` dictionary.
|
|
570
|
-
*
|
|
571
|
-
* @param dict The `/StructTreeRoot` dictionary.
|
|
572
|
-
* @param resolver A function that resolves indirect references to
|
|
573
|
-
* their underlying PDF objects.
|
|
574
|
-
* @returns A new {@link PdfStructureTree}.
|
|
575
|
-
*/
|
|
576
|
-
static fromDict(dict: PdfDict, resolver: (ref: PdfRef) => PdfObject | undefined): PdfStructureTree;
|
|
577
|
-
/**
|
|
578
|
-
* Validate the structure tree for common accessibility issues.
|
|
579
|
-
*
|
|
580
|
-
* Checks:
|
|
581
|
-
* - Heading hierarchy (no skipped levels)
|
|
582
|
-
* - Table structure completeness
|
|
583
|
-
* - Illustration elements have alt text
|
|
584
|
-
* - List structure completeness
|
|
585
|
-
*
|
|
586
|
-
* @returns An array of {@link AccessibilityIssue} objects.
|
|
587
|
-
*/
|
|
588
|
-
validate(): AccessibilityIssue[];
|
|
589
|
-
/**
|
|
590
|
-
* Validate heading hierarchy: headings should not skip levels
|
|
591
|
-
* (e.g. H1 then H3 without H2).
|
|
592
|
-
*
|
|
593
|
-
* @internal
|
|
594
|
-
*/
|
|
595
|
-
private validateHeadingHierarchy;
|
|
596
|
-
/**
|
|
597
|
-
* Validate table structure: Table should contain TR, TR should
|
|
598
|
-
* contain TH or TD.
|
|
599
|
-
*
|
|
600
|
-
* @internal
|
|
601
|
-
*/
|
|
602
|
-
private validateTableStructure;
|
|
603
|
-
/**
|
|
604
|
-
* Validate that illustration elements (Figure, Formula, Form) have
|
|
605
|
-
* alt text.
|
|
606
|
-
*
|
|
607
|
-
* @internal
|
|
608
|
-
*/
|
|
609
|
-
private validateIllustrationAltText;
|
|
610
|
-
/**
|
|
611
|
-
* Validate list structure: L should contain LI, LI should contain
|
|
612
|
-
* Lbl and/or LBody.
|
|
613
|
-
*
|
|
614
|
-
* @internal
|
|
615
|
-
*/
|
|
616
|
-
private validateListStructure;
|
|
617
|
-
}
|
|
618
|
-
//#endregion
|
|
619
|
-
//#region src/annotation/pdfAnnotation.d.ts
|
|
620
|
-
/**
|
|
621
|
-
* All annotation subtypes defined in the PDF specification.
|
|
622
|
-
*/
|
|
623
|
-
type AnnotationType = 'Text' | 'Link' | 'FreeText' | 'Line' | 'Square' | 'Circle' | 'Polygon' | 'PolyLine' | 'Highlight' | 'Underline' | 'Squiggly' | 'StrikeOut' | 'Stamp' | 'Caret' | 'Ink' | 'Popup' | 'FileAttachment' | 'Sound' | 'Movie' | 'Widget' | 'Screen' | 'PrinterMark' | 'TrapNet' | 'Watermark' | 'Redact' | '3D';
|
|
624
|
-
/**
|
|
625
|
-
* Options for creating a new annotation.
|
|
626
|
-
*/
|
|
627
|
-
interface AnnotationOptions {
|
|
628
|
-
/** Annotation rectangle [x1, y1, x2, y2] in default user space. */
|
|
629
|
-
rect: [number, number, number, number];
|
|
630
|
-
/** Text contents (displayed as tooltip or popup). */
|
|
631
|
-
contents?: string | undefined;
|
|
632
|
-
/** Author / title of the annotation. */
|
|
633
|
-
author?: string | undefined;
|
|
634
|
-
/** Last modification date. */
|
|
635
|
-
modificationDate?: Date | undefined;
|
|
636
|
-
/** Colour in RGB (each component 0-1). */
|
|
637
|
-
color?: {
|
|
638
|
-
r: number;
|
|
639
|
-
g: number;
|
|
640
|
-
b: number;
|
|
641
|
-
} | undefined;
|
|
642
|
-
/** Opacity (0 = transparent, 1 = opaque). */
|
|
643
|
-
opacity?: number | undefined;
|
|
644
|
-
/** Annotation flags bitmask (PDF spec Table 165). */
|
|
645
|
-
flags?: number | undefined;
|
|
646
|
-
/** Border specification. */
|
|
647
|
-
border?: {
|
|
648
|
-
width: number;
|
|
649
|
-
style?: 'solid' | 'dashed' | 'beveled' | 'inset' | 'underline' | undefined;
|
|
650
|
-
} | undefined;
|
|
651
|
-
}
|
|
652
|
-
/** Annotation flag bit positions. */
|
|
653
|
-
declare const AnnotationFlags: {
|
|
654
|
-
readonly Invisible: number;
|
|
655
|
-
readonly Hidden: number;
|
|
656
|
-
readonly Print: number;
|
|
657
|
-
readonly NoZoom: number;
|
|
658
|
-
readonly NoRotate: number;
|
|
659
|
-
readonly NoView: number;
|
|
660
|
-
readonly ReadOnly: number;
|
|
661
|
-
readonly Locked: number;
|
|
662
|
-
readonly ToggleNoView: number;
|
|
663
|
-
readonly LockedContents: number;
|
|
664
|
-
};
|
|
665
|
-
/**
|
|
666
|
-
* Create a PdfAnnotation from an existing dictionary.
|
|
667
|
-
*
|
|
668
|
-
* @param dict The annotation dictionary.
|
|
669
|
-
* @param resolver Optional function to resolve indirect references.
|
|
670
|
-
* @returns A PdfAnnotation instance.
|
|
671
|
-
*/
|
|
672
|
-
declare function annotationFromDict(dict: PdfDict, resolver?: (ref: PdfRef) => PdfObject | undefined): PdfAnnotation;
|
|
673
|
-
/**
|
|
674
|
-
* Build an annotation dictionary from options.
|
|
675
|
-
*
|
|
676
|
-
* Used internally by subclass factory methods to populate common
|
|
677
|
-
* annotation dictionary entries.
|
|
678
|
-
*
|
|
679
|
-
* @param type The annotation subtype.
|
|
680
|
-
* @param options Creation options.
|
|
681
|
-
* @returns A populated PdfDict.
|
|
682
|
-
*/
|
|
683
|
-
declare function buildAnnotationDict(type: AnnotationType, options: AnnotationOptions): PdfDict;
|
|
684
|
-
/**
|
|
685
|
-
* Create a new annotation with the given type and options.
|
|
686
|
-
*
|
|
687
|
-
* This is a convenience function that creates a generic PdfAnnotation.
|
|
688
|
-
* For type-specific annotations, use the subclass `create()` methods.
|
|
689
|
-
*
|
|
690
|
-
* @param type The annotation subtype.
|
|
691
|
-
* @param options Creation options (rect, contents, etc.).
|
|
692
|
-
* @returns A new PdfAnnotation instance.
|
|
693
|
-
*/
|
|
694
|
-
declare function createAnnotation(type: AnnotationType, options: AnnotationOptions): PdfAnnotation;
|
|
695
|
-
/**
|
|
696
|
-
* Base class for all PDF annotations.
|
|
697
|
-
*
|
|
698
|
-
* Wraps a PdfDict representing the annotation dictionary. Subclasses
|
|
699
|
-
* add type-specific getters/setters.
|
|
700
|
-
*/
|
|
701
|
-
declare class PdfAnnotation {
|
|
702
|
-
/** The annotation subtype. */
|
|
703
|
-
readonly annotationType: AnnotationType;
|
|
704
|
-
/** The underlying annotation dictionary. */
|
|
705
|
-
protected dict: PdfDict;
|
|
706
|
-
constructor(type: AnnotationType, dict: PdfDict);
|
|
707
|
-
/** Get the annotation subtype. */
|
|
708
|
-
getType(): AnnotationType;
|
|
709
|
-
/** Get the annotation rectangle [x1, y1, x2, y2]. */
|
|
710
|
-
getRect(): [number, number, number, number];
|
|
711
|
-
/** Set the annotation rectangle. */
|
|
712
|
-
setRect(rect: [number, number, number, number]): void;
|
|
713
|
-
/** Get the text contents (tooltip / popup text). */
|
|
714
|
-
getContents(): string | undefined;
|
|
715
|
-
/** Set the text contents. */
|
|
716
|
-
setContents(contents: string): void;
|
|
717
|
-
/** Get the author (PDF /T entry). */
|
|
718
|
-
getAuthor(): string | undefined;
|
|
719
|
-
/** Set the author. */
|
|
720
|
-
setAuthor(author: string): void;
|
|
721
|
-
/** Get the annotation colour. */
|
|
722
|
-
getColor(): {
|
|
723
|
-
r: number;
|
|
724
|
-
g: number;
|
|
725
|
-
b: number;
|
|
726
|
-
} | undefined;
|
|
727
|
-
/** Set the annotation colour. */
|
|
728
|
-
setColor(color: {
|
|
729
|
-
r: number;
|
|
730
|
-
g: number;
|
|
731
|
-
b: number;
|
|
732
|
-
}): void;
|
|
733
|
-
/** Get the annotation opacity (0-1). Defaults to 1. */
|
|
734
|
-
getOpacity(): number;
|
|
735
|
-
/** Set the annotation opacity. */
|
|
736
|
-
setOpacity(opacity: number): void;
|
|
737
|
-
/** Get the raw flags bitmask. */
|
|
738
|
-
private getFlags;
|
|
739
|
-
/** Set the raw flags bitmask. */
|
|
740
|
-
private setFlags;
|
|
741
|
-
/** Check if a specific flag bit is set. */
|
|
742
|
-
private hasFlag;
|
|
743
|
-
/** Set or clear a specific flag bit. */
|
|
744
|
-
private setFlag;
|
|
745
|
-
/** Whether the annotation is hidden. */
|
|
746
|
-
isHidden(): boolean;
|
|
747
|
-
/** Set the hidden flag. */
|
|
748
|
-
setHidden(hidden: boolean): void;
|
|
749
|
-
/** Whether the annotation should be printed. */
|
|
750
|
-
isPrintable(): boolean;
|
|
751
|
-
/** Set the print flag. */
|
|
752
|
-
setPrintable(printable: boolean): void;
|
|
753
|
-
/** Whether the annotation is locked (cannot be moved/resized). */
|
|
754
|
-
isLocked(): boolean;
|
|
755
|
-
/** Set the locked flag. */
|
|
756
|
-
setLocked(locked: boolean): void;
|
|
757
|
-
/**
|
|
758
|
-
* Convert this annotation to a PdfDict suitable for embedding in a PDF.
|
|
759
|
-
*
|
|
760
|
-
* @param registry The object registry (used to register sub-objects).
|
|
761
|
-
* @returns The annotation dictionary.
|
|
762
|
-
*/
|
|
763
|
-
toDict(registry: PdfObjectRegistry): PdfDict;
|
|
764
|
-
/**
|
|
765
|
-
* Generate an appearance stream for this annotation.
|
|
766
|
-
*
|
|
767
|
-
* The base implementation returns `undefined`. Subclasses override
|
|
768
|
-
* to produce proper visual appearance.
|
|
769
|
-
*
|
|
770
|
-
* @returns A PdfStream for the /AP /N entry, or undefined.
|
|
771
|
-
*/
|
|
772
|
-
generateAppearance(): PdfStream | undefined;
|
|
773
|
-
/**
|
|
774
|
-
* Get the underlying dictionary (for internal use).
|
|
775
|
-
* @internal
|
|
776
|
-
*/
|
|
777
|
-
getDict(): PdfDict;
|
|
778
|
-
}
|
|
779
|
-
//#endregion
|
|
780
|
-
//#region src/assets/svg/svgParser.d.ts
|
|
781
|
-
/**
|
|
782
|
-
* @module assets/svg/svgParser
|
|
783
|
-
*
|
|
784
|
-
* Parse SVG XML into an intermediate representation of drawing commands.
|
|
785
|
-
*
|
|
786
|
-
* This parser uses a simple regex / state-machine approach (no DOMParser)
|
|
787
|
-
* so that it works in every JavaScript runtime (Node, Deno, Bun,
|
|
788
|
-
* Cloudflare Workers, browsers).
|
|
789
|
-
*
|
|
790
|
-
* Supported SVG elements:
|
|
791
|
-
* `<svg>`, `<g>`, `<path>`, `<rect>`, `<circle>`, `<ellipse>`,
|
|
792
|
-
* `<line>`, `<polyline>`, `<polygon>`, `<text>` (basic).
|
|
793
|
-
*
|
|
794
|
-
* Supported path commands:
|
|
795
|
-
* M, m, L, l, H, h, V, v, C, c, S, s, Q, q, T, t, A, a, Z, z.
|
|
796
|
-
*/
|
|
797
|
-
/** A single drawing command produced from an SVG element. */
|
|
798
|
-
interface SvgDrawCommand {
|
|
799
|
-
type: 'moveTo' | 'lineTo' | 'curveTo' | 'quadCurveTo' | 'closePath' | 'rect' | 'circle' | 'ellipse' | 'arc';
|
|
800
|
-
params: number[];
|
|
801
|
-
}
|
|
802
|
-
/** Parsed representation of an SVG element. */
|
|
803
|
-
interface SvgElement {
|
|
804
|
-
tag: string;
|
|
805
|
-
attributes: Record<string, string>;
|
|
806
|
-
children: SvgElement[];
|
|
807
|
-
commands?: SvgDrawCommand[] | undefined;
|
|
808
|
-
fill?: {
|
|
809
|
-
r: number;
|
|
810
|
-
g: number;
|
|
811
|
-
b: number;
|
|
812
|
-
a?: number | undefined;
|
|
813
|
-
} | undefined;
|
|
814
|
-
stroke?: {
|
|
815
|
-
r: number;
|
|
816
|
-
g: number;
|
|
817
|
-
b: number;
|
|
818
|
-
a?: number | undefined;
|
|
819
|
-
} | undefined;
|
|
820
|
-
strokeWidth?: number | undefined;
|
|
821
|
-
transform?: [number, number, number, number, number, number] | undefined;
|
|
822
|
-
opacity?: number | undefined;
|
|
823
|
-
}
|
|
824
|
-
declare function parseSvgColor(colorStr: string): {
|
|
825
|
-
r: number;
|
|
826
|
-
g: number;
|
|
827
|
-
b: number;
|
|
828
|
-
a?: number | undefined;
|
|
829
|
-
} | undefined;
|
|
830
|
-
/**
|
|
831
|
-
* Parse an SVG `transform` attribute into a 2D affine matrix.
|
|
832
|
-
*
|
|
833
|
-
* Returns `[a, b, c, d, e, f]` representing:
|
|
834
|
-
* ```
|
|
835
|
-
* [ a c e ]
|
|
836
|
-
* [ b d f ]
|
|
837
|
-
* [ 0 0 1 ]
|
|
838
|
-
* ```
|
|
839
|
-
*
|
|
840
|
-
* Supports: `matrix`, `translate`, `scale`, `rotate`, `skewX`, `skewY`.
|
|
841
|
-
* Multiple transforms are composed left-to-right.
|
|
842
|
-
*/
|
|
843
|
-
declare function parseSvgTransform(transformStr: string): [number, number, number, number, number, number];
|
|
844
|
-
/**
|
|
845
|
-
* Parse an SVG path `d` attribute string into an array of drawing commands.
|
|
846
|
-
*
|
|
847
|
-
* Supports all SVG path commands (absolute and relative):
|
|
848
|
-
* M, L, H, V, C, S, Q, T, A, Z.
|
|
849
|
-
*/
|
|
850
|
-
declare function parseSvgPath(d: string): SvgDrawCommand[];
|
|
851
|
-
/**
|
|
852
|
-
* Parse an SVG string into an {@link SvgElement} tree.
|
|
853
|
-
*
|
|
854
|
-
* The returned element represents the root `<svg>` element (or a
|
|
855
|
-
* synthetic root if the input contains multiple top-level elements).
|
|
856
|
-
*/
|
|
857
|
-
declare function parseSvg(svgString: string): SvgElement;
|
|
858
|
-
//#endregion
|
|
859
|
-
//#region src/assets/svg/svgToPdf.d.ts
|
|
860
|
-
/** Options for rendering an SVG onto a PDF page. */
|
|
861
|
-
interface SvgRenderOptions {
|
|
862
|
-
/** Rendered width in PDF points. */
|
|
863
|
-
width?: number | undefined;
|
|
864
|
-
/** Rendered height in PDF points. */
|
|
865
|
-
height?: number | undefined;
|
|
866
|
-
/** X offset in PDF points. */
|
|
867
|
-
x?: number | undefined;
|
|
868
|
-
/** Y offset in PDF points (bottom of the SVG). */
|
|
869
|
-
y?: number | undefined;
|
|
870
|
-
/** Whether to preserve the aspect ratio of the SVG. */
|
|
871
|
-
preserveAspectRatio?: boolean | undefined;
|
|
872
|
-
}
|
|
873
|
-
/**
|
|
874
|
-
* Convert an SVG element tree into PDF content stream operators.
|
|
875
|
-
*
|
|
876
|
-
* The returned string can be injected directly into a PDF page's
|
|
877
|
-
* content stream.
|
|
878
|
-
*/
|
|
879
|
-
declare function svgToPdfOperators(element: SvgElement, options?: SvgRenderOptions): string;
|
|
880
|
-
/**
|
|
881
|
-
* Draw an SVG string onto a PDF page.
|
|
882
|
-
*
|
|
883
|
-
* Parses the SVG, converts it to PDF operators, and appends them
|
|
884
|
-
* to the page's content stream.
|
|
885
|
-
*/
|
|
886
|
-
declare function drawSvgOnPage(page: PdfPage, svgString: string, options?: SvgRenderOptions): void;
|
|
887
|
-
//#endregion
|
|
888
|
-
//#region src/layers/optionalContent.d.ts
|
|
889
|
-
/**
|
|
890
|
-
* Represents a single optional content group (layer) in a PDF.
|
|
891
|
-
*
|
|
892
|
-
* Each layer has a name and a default visibility state. Content
|
|
893
|
-
* can be associated with a layer using the `BDC`/`EMC` marked-content
|
|
894
|
-
* operators in the content stream.
|
|
895
|
-
*/
|
|
896
|
-
declare class PdfLayer {
|
|
897
|
-
readonly name: string;
|
|
898
|
-
private visible;
|
|
899
|
-
private ref;
|
|
900
|
-
constructor(name: string, visible?: boolean);
|
|
901
|
-
/** Check whether this layer is visible by default. */
|
|
902
|
-
isVisible(): boolean;
|
|
903
|
-
/** Set the default visibility of this layer. */
|
|
904
|
-
setVisible(visible: boolean): void;
|
|
905
|
-
/** Get the layer name. */
|
|
906
|
-
getName(): string;
|
|
907
|
-
/**
|
|
908
|
-
* Get the indirect reference for this layer's OCG dictionary.
|
|
909
|
-
* Only available after `toDict()` has been called.
|
|
910
|
-
*/
|
|
911
|
-
getRef(): PdfRef | undefined;
|
|
912
|
-
/**
|
|
913
|
-
* Serialize this layer as an OCG dictionary and register it in the
|
|
914
|
-
* object registry.
|
|
915
|
-
*
|
|
916
|
-
* @param registry The PDF object registry.
|
|
917
|
-
* @returns The indirect reference to the OCG dictionary.
|
|
918
|
-
*/
|
|
919
|
-
toDict(registry: PdfObjectRegistry): PdfRef;
|
|
920
|
-
/**
|
|
921
|
-
* Parse a PdfLayer from an OCG dictionary.
|
|
922
|
-
*
|
|
923
|
-
* @param dict The OCG dictionary.
|
|
924
|
-
* @returns A PdfLayer instance.
|
|
925
|
-
*/
|
|
926
|
-
static fromDict(dict: PdfDict): PdfLayer;
|
|
927
|
-
}
|
|
928
|
-
/**
|
|
929
|
-
* Manages a collection of optional content groups (layers) for a PDF
|
|
930
|
-
* document.
|
|
931
|
-
*
|
|
932
|
-
* Provides methods to add, remove, and query layers, and to serialize
|
|
933
|
-
* the `/OCProperties` dictionary that goes into the catalog.
|
|
934
|
-
*/
|
|
935
|
-
declare class PdfLayerManager {
|
|
936
|
-
private layers;
|
|
937
|
-
/**
|
|
938
|
-
* Add a new layer.
|
|
939
|
-
*
|
|
940
|
-
* @param name The display name for the layer.
|
|
941
|
-
* @param visible Whether the layer is visible by default.
|
|
942
|
-
* @returns The newly created layer.
|
|
943
|
-
*/
|
|
944
|
-
addLayer(name: string, visible?: boolean): PdfLayer;
|
|
945
|
-
/**
|
|
946
|
-
* Get a layer by name.
|
|
947
|
-
*
|
|
948
|
-
* @param name The layer name.
|
|
949
|
-
* @returns The layer, or `undefined` if not found.
|
|
950
|
-
*/
|
|
951
|
-
getLayer(name: string): PdfLayer | undefined;
|
|
952
|
-
/**
|
|
953
|
-
* Get all layers.
|
|
954
|
-
*
|
|
955
|
-
* @returns A copy of the layers array.
|
|
956
|
-
*/
|
|
957
|
-
getLayers(): PdfLayer[];
|
|
958
|
-
/**
|
|
959
|
-
* Remove a layer by name.
|
|
960
|
-
*
|
|
961
|
-
* @param name The layer name.
|
|
962
|
-
*/
|
|
963
|
-
removeLayer(name: string): void;
|
|
964
|
-
/**
|
|
965
|
-
* Build the `/OCProperties` dictionary for the document catalog.
|
|
966
|
-
*
|
|
967
|
-
* This dictionary describes all optional content groups and their
|
|
968
|
-
* default configurations.
|
|
969
|
-
*
|
|
970
|
-
* @param registry The PDF object registry.
|
|
971
|
-
* @returns The `/OCProperties` dictionary (not indirect).
|
|
972
|
-
*/
|
|
973
|
-
toOCProperties(registry: PdfObjectRegistry): PdfDict;
|
|
974
|
-
/**
|
|
975
|
-
* Parse a PdfLayerManager from an `/OCProperties` dictionary.
|
|
976
|
-
*
|
|
977
|
-
* @param dict The `/OCProperties` dictionary from the catalog.
|
|
978
|
-
* @param resolver A function that resolves indirect references.
|
|
979
|
-
* @returns A PdfLayerManager instance.
|
|
980
|
-
*/
|
|
981
|
-
static fromDict(dict: PdfDict, resolver: (ref: PdfRef) => PdfObject): PdfLayerManager;
|
|
982
|
-
}
|
|
983
|
-
/**
|
|
984
|
-
* Generate the PDF operator to begin optional content for a layer.
|
|
985
|
-
*
|
|
986
|
-
* This produces a `BDC` (begin marked-content with properties)
|
|
987
|
-
* operator that activates the given layer.
|
|
988
|
-
*
|
|
989
|
-
* @param layer The layer to activate.
|
|
990
|
-
* @returns The PDF operator string: `/OC /LayerName BDC\n`
|
|
991
|
-
*/
|
|
992
|
-
declare function beginLayerContent(layer: PdfLayer): string;
|
|
993
|
-
/**
|
|
994
|
-
* Generate the PDF operator to end optional content.
|
|
995
|
-
*
|
|
996
|
-
* @returns The PDF operator string: `EMC\n`
|
|
997
|
-
*/
|
|
998
|
-
declare function endLayerContent(): string;
|
|
999
|
-
//#endregion
|
|
1000
|
-
//#region src/core/redaction.d.ts
|
|
1001
|
-
/** Options for marking a region for redaction. */
|
|
1002
|
-
interface RedactionOptions {
|
|
1003
|
-
/** The rectangle to redact: [x, y, width, height]. */
|
|
1004
|
-
rect: [number, number, number, number];
|
|
1005
|
-
/** Optional text to overlay on the redacted area. */
|
|
1006
|
-
overlayText?: string | undefined;
|
|
1007
|
-
/** Colour for the redaction rectangle (default: black). */
|
|
1008
|
-
color?: {
|
|
1009
|
-
r: number;
|
|
1010
|
-
g: number;
|
|
1011
|
-
b: number;
|
|
1012
|
-
} | undefined;
|
|
1013
|
-
}
|
|
1014
|
-
/** Redaction mark stored on a page. */
|
|
1015
|
-
interface RedactionMark {
|
|
1016
|
-
rect: [number, number, number, number];
|
|
1017
|
-
overlayText?: string | undefined;
|
|
1018
|
-
color: {
|
|
1019
|
-
r: number;
|
|
1020
|
-
g: number;
|
|
1021
|
-
b: number;
|
|
1022
|
-
};
|
|
1023
|
-
}
|
|
1024
|
-
/**
|
|
1025
|
-
* Mark a rectangular region on a page for redaction.
|
|
1026
|
-
*
|
|
1027
|
-
* This does not immediately modify the page. Call
|
|
1028
|
-
* {@link applyRedactions} to draw the redaction rectangles.
|
|
1029
|
-
*
|
|
1030
|
-
* @param page The page to mark.
|
|
1031
|
-
* @param options The redaction options.
|
|
1032
|
-
*/
|
|
1033
|
-
declare function markForRedaction(page: PdfPage, options: RedactionOptions): void;
|
|
1034
|
-
/**
|
|
1035
|
-
* Apply all pending redactions across all pages in a document.
|
|
1036
|
-
*
|
|
1037
|
-
* For each redaction mark, this draws an opaque filled rectangle
|
|
1038
|
-
* over the marked region. If overlay text is specified, it is
|
|
1039
|
-
* drawn on top of the rectangle in a contrasting colour.
|
|
1040
|
-
*
|
|
1041
|
-
* @param doc The PDF document.
|
|
1042
|
-
*/
|
|
1043
|
-
declare function applyRedactions(doc: PdfDocument): void;
|
|
1044
|
-
/**
|
|
1045
|
-
* Get the pending redaction marks for a page.
|
|
1046
|
-
*
|
|
1047
|
-
* @param page The page to query.
|
|
1048
|
-
* @returns An array of redaction marks, or an empty array.
|
|
1049
|
-
*/
|
|
1050
|
-
declare function getRedactionMarks(page: PdfPage): readonly RedactionMark[];
|
|
1051
|
-
//#endregion
|
|
1052
|
-
//#region src/core/pdfEmbed.d.ts
|
|
1053
|
-
/**
|
|
1054
|
-
* Handle for a page that has been embedded as a Form XObject.
|
|
1055
|
-
*
|
|
1056
|
-
* Returned by `PdfDocument.embedPdf()` and `PdfDocument.embedPage()`.
|
|
1057
|
-
* Pass it to `PdfPage.drawPage()` to paint the embedded page.
|
|
1058
|
-
*/
|
|
1059
|
-
interface EmbeddedPdfPage {
|
|
1060
|
-
/** XObject resource name (e.g. `'XF1'`). */
|
|
1061
|
-
readonly name: string;
|
|
1062
|
-
/** Indirect reference to the Form XObject in the target registry. */
|
|
1063
|
-
readonly ref: PdfRef;
|
|
1064
|
-
/** Original page width in points. */
|
|
1065
|
-
readonly width: number;
|
|
1066
|
-
/** Original page height in points. */
|
|
1067
|
-
readonly height: number;
|
|
1068
|
-
/**
|
|
1069
|
-
* Return the dimensions after applying a uniform scale factor.
|
|
1070
|
-
*
|
|
1071
|
-
* @param factor Scale factor (e.g. `0.5` for half size).
|
|
1072
|
-
*/
|
|
1073
|
-
scale(factor: number): {
|
|
1074
|
-
width: number;
|
|
1075
|
-
height: number;
|
|
1076
|
-
};
|
|
1077
|
-
/**
|
|
1078
|
-
* Compute dimensions that fit within the given maximum size while
|
|
1079
|
-
* preserving the original aspect ratio.
|
|
1080
|
-
*
|
|
1081
|
-
* @param maxW Maximum width.
|
|
1082
|
-
* @param maxH Maximum height.
|
|
1083
|
-
*/
|
|
1084
|
-
scaleToFit(maxW: number, maxH: number): {
|
|
1085
|
-
width: number;
|
|
1086
|
-
height: number;
|
|
1087
|
-
};
|
|
1088
|
-
}
|
|
1089
|
-
/**
|
|
1090
|
-
* Options for {@link PdfPage.drawPage}.
|
|
1091
|
-
*/
|
|
1092
|
-
interface DrawPageOptions {
|
|
1093
|
-
/** X coordinate of the lower-left corner. */
|
|
1094
|
-
x?: number | undefined;
|
|
1095
|
-
/** Y coordinate of the lower-left corner. */
|
|
1096
|
-
y?: number | undefined;
|
|
1097
|
-
/** Rendered width (defaults to the embedded page's original width). */
|
|
1098
|
-
width?: number | undefined;
|
|
1099
|
-
/** Rendered height (defaults to the embedded page's original height). */
|
|
1100
|
-
height?: number | undefined;
|
|
1101
|
-
/** Rotation angle. */
|
|
1102
|
-
rotate?: {
|
|
1103
|
-
type: 'degrees' | 'radians';
|
|
1104
|
-
value: number;
|
|
1105
|
-
} | undefined;
|
|
1106
|
-
/** Opacity `[0, 1]`. */
|
|
1107
|
-
opacity?: number | undefined;
|
|
1108
|
-
/** Blend mode for compositing. */
|
|
1109
|
-
blendMode?: BlendMode | undefined;
|
|
1110
|
-
/** Horizontal skew angle. */
|
|
1111
|
-
xSkew?: {
|
|
1112
|
-
type: 'degrees' | 'radians';
|
|
1113
|
-
value: number;
|
|
1114
|
-
} | undefined;
|
|
1115
|
-
/** Vertical skew angle. */
|
|
1116
|
-
ySkew?: {
|
|
1117
|
-
type: 'degrees' | 'radians';
|
|
1118
|
-
value: number;
|
|
1119
|
-
} | undefined;
|
|
1120
|
-
}
|
|
1121
|
-
/**
|
|
1122
|
-
* Options for embedding a page as a Form XObject.
|
|
1123
|
-
*/
|
|
1124
|
-
interface EmbedPageOptions {
|
|
1125
|
-
/**
|
|
1126
|
-
* Clip the embedded page to a sub-region (bounding box).
|
|
1127
|
-
* Coordinates are in the source page's coordinate system.
|
|
1128
|
-
*/
|
|
1129
|
-
boundingBox?: {
|
|
1130
|
-
x: number;
|
|
1131
|
-
y: number;
|
|
1132
|
-
width: number;
|
|
1133
|
-
height: number;
|
|
1134
|
-
} | undefined;
|
|
1135
|
-
/**
|
|
1136
|
-
* Apply an affine transformation matrix to the Form XObject.
|
|
1137
|
-
* The six values correspond to `[a, b, c, d, tx, ty]` in the
|
|
1138
|
-
* standard 3x3 PDF transformation matrix.
|
|
1139
|
-
*/
|
|
1140
|
-
transformationMatrix?: [number, number, number, number, number, number] | undefined;
|
|
1141
|
-
}
|
|
1142
|
-
/**
|
|
1143
|
-
* Embed a single page as a Form XObject in the target registry.
|
|
1144
|
-
*
|
|
1145
|
-
* The page's content stream(s) are decoded and concatenated. The
|
|
1146
|
-
* page's resources are deep-cloned into the target registry. The
|
|
1147
|
-
* result is a PdfStream of Subtype /Form registered in the target.
|
|
1148
|
-
*
|
|
1149
|
-
* @param page The source PdfPage to embed.
|
|
1150
|
-
* @param sourceRegistry The source document's object registry.
|
|
1151
|
-
* @param targetRegistry The target document's object registry.
|
|
1152
|
-
* @param xObjectName The resource name to assign (e.g. `'XF1'`).
|
|
1153
|
-
* @returns An EmbeddedPdfPage handle.
|
|
1154
|
-
*/
|
|
1155
|
-
declare function embedPageAsFormXObject(page: PdfPage, sourceRegistry: PdfObjectRegistry, targetRegistry: PdfObjectRegistry, xObjectName: string, options?: EmbedPageOptions): EmbeddedPdfPage;
|
|
1156
|
-
//#endregion
|
|
1157
|
-
//#region src/core/patterns.d.ts
|
|
1158
|
-
/**
|
|
1159
|
-
* A colour stop in a gradient, specifying the position (0..1) and colour.
|
|
1160
|
-
*/
|
|
1161
|
-
interface ColorStop {
|
|
1162
|
-
readonly offset: number;
|
|
1163
|
-
readonly color: Color;
|
|
1164
|
-
}
|
|
1165
|
-
/**
|
|
1166
|
-
* Options for creating a linear gradient (axial shading, ShadingType 2).
|
|
1167
|
-
*/
|
|
1168
|
-
interface LinearGradientOptions {
|
|
1169
|
-
/** Start X coordinate. */
|
|
1170
|
-
readonly x1: number;
|
|
1171
|
-
/** Start Y coordinate. */
|
|
1172
|
-
readonly y1: number;
|
|
1173
|
-
/** End X coordinate. */
|
|
1174
|
-
readonly x2: number;
|
|
1175
|
-
/** End Y coordinate. */
|
|
1176
|
-
readonly y2: number;
|
|
1177
|
-
/**
|
|
1178
|
-
* Colour stops. Each element is either a bare {@link Color} (positions
|
|
1179
|
-
* are distributed evenly) or a {@link ColorStop} with an explicit offset.
|
|
1180
|
-
*/
|
|
1181
|
-
readonly stops: readonly (Color | ColorStop)[];
|
|
1182
|
-
/**
|
|
1183
|
-
* Whether to extend the gradient beyond the start and end points.
|
|
1184
|
-
* Default: `true`.
|
|
1185
|
-
*/
|
|
1186
|
-
readonly extend?: boolean;
|
|
1187
|
-
}
|
|
1188
|
-
/**
|
|
1189
|
-
* Options for creating a radial gradient (radial shading, ShadingType 3).
|
|
1190
|
-
*/
|
|
1191
|
-
interface RadialGradientOptions {
|
|
1192
|
-
/** Centre X of the start circle. */
|
|
1193
|
-
readonly x0: number;
|
|
1194
|
-
/** Centre Y of the start circle. */
|
|
1195
|
-
readonly y0: number;
|
|
1196
|
-
/** Radius of the start circle. */
|
|
1197
|
-
readonly r0: number;
|
|
1198
|
-
/** Centre X of the end circle. */
|
|
1199
|
-
readonly x1: number;
|
|
1200
|
-
/** Centre Y of the end circle. */
|
|
1201
|
-
readonly y1: number;
|
|
1202
|
-
/** Radius of the end circle. */
|
|
1203
|
-
readonly r1: number;
|
|
1204
|
-
/**
|
|
1205
|
-
* Colour stops (same semantics as {@link LinearGradientOptions.stops}).
|
|
1206
|
-
*/
|
|
1207
|
-
readonly stops: readonly (Color | ColorStop)[];
|
|
1208
|
-
/**
|
|
1209
|
-
* Whether to extend the gradient beyond the start and end circles.
|
|
1210
|
-
* Default: `true`.
|
|
1211
|
-
*/
|
|
1212
|
-
readonly extend?: boolean;
|
|
1213
|
-
}
|
|
1214
|
-
/**
|
|
1215
|
-
* Options for creating a tiling pattern (PatternType 1).
|
|
1216
|
-
*/
|
|
1217
|
-
interface TilingPatternOptions {
|
|
1218
|
-
/** Width of one tile in user-space units. */
|
|
1219
|
-
readonly width: number;
|
|
1220
|
-
/** Height of one tile in user-space units. */
|
|
1221
|
-
readonly height: number;
|
|
1222
|
-
/**
|
|
1223
|
-
* Paint type.
|
|
1224
|
-
* - `1` (default) — coloured: the pattern's content stream specifies
|
|
1225
|
-
* its own colours.
|
|
1226
|
-
* - `2` — uncoloured: colours are supplied when the pattern is painted.
|
|
1227
|
-
*/
|
|
1228
|
-
readonly paintType?: 1 | 2;
|
|
1229
|
-
/**
|
|
1230
|
-
* Tiling type.
|
|
1231
|
-
* - `1` (default) — constant spacing.
|
|
1232
|
-
* - `2` — no distortion.
|
|
1233
|
-
* - `3` — constant spacing and faster tiling.
|
|
1234
|
-
*/
|
|
1235
|
-
readonly tilingType?: 1 | 2 | 3;
|
|
1236
|
-
/** Raw PDF content-stream operators that paint one tile. */
|
|
1237
|
-
readonly ops: string;
|
|
1238
|
-
}
|
|
1239
|
-
/**
|
|
1240
|
-
* Descriptor for a gradient fill (linear or radial).
|
|
1241
|
-
* This is a lightweight value object — actual PDF objects are created
|
|
1242
|
-
* when {@link buildGradientObjects} is called.
|
|
1243
|
-
*/
|
|
1244
|
-
interface GradientFill {
|
|
1245
|
-
readonly kind: 'gradient';
|
|
1246
|
-
readonly shadingType: 2 | 3;
|
|
1247
|
-
readonly coords: readonly number[];
|
|
1248
|
-
readonly normalizedStops: readonly NormalizedStop[];
|
|
1249
|
-
readonly extend: boolean;
|
|
1250
|
-
}
|
|
1251
|
-
/**
|
|
1252
|
-
* Descriptor for a radial gradient fill.
|
|
1253
|
-
* Structurally identical to {@link GradientFill} but with `shadingType: 3`.
|
|
1254
|
-
*/
|
|
1255
|
-
type RadialGradientFill = GradientFill & {
|
|
1256
|
-
readonly shadingType: 3;
|
|
1257
|
-
};
|
|
1258
|
-
/**
|
|
1259
|
-
* Descriptor for a tiling pattern fill.
|
|
1260
|
-
* This is a lightweight value object — actual PDF objects are created
|
|
1261
|
-
* when {@link buildPatternObjects} is called.
|
|
1262
|
-
*/
|
|
1263
|
-
interface PatternFill {
|
|
1264
|
-
readonly kind: 'pattern';
|
|
1265
|
-
readonly width: number;
|
|
1266
|
-
readonly height: number;
|
|
1267
|
-
readonly paintType: 1 | 2;
|
|
1268
|
-
readonly tilingType: 1 | 2 | 3;
|
|
1269
|
-
readonly ops: string;
|
|
1270
|
-
}
|
|
1271
|
-
/** A normalised colour stop with explicit offset and RGB values. */
|
|
1272
|
-
interface NormalizedStop {
|
|
1273
|
-
readonly offset: number;
|
|
1274
|
-
readonly r: number;
|
|
1275
|
-
readonly g: number;
|
|
1276
|
-
readonly b: number;
|
|
1277
|
-
}
|
|
1278
|
-
/**
|
|
1279
|
-
* Create a linear (axial) gradient descriptor.
|
|
1280
|
-
*
|
|
1281
|
-
* The gradient runs from `(x1, y1)` to `(x2, y2)` through the given
|
|
1282
|
-
* colour stops. By default the gradient extends beyond its endpoints.
|
|
1283
|
-
*
|
|
1284
|
-
* @param options Gradient parameters.
|
|
1285
|
-
* @returns A {@link GradientFill} descriptor.
|
|
1286
|
-
*/
|
|
1287
|
-
declare function linearGradient(options: LinearGradientOptions): GradientFill;
|
|
1288
|
-
/**
|
|
1289
|
-
* Create a radial gradient descriptor.
|
|
1290
|
-
*
|
|
1291
|
-
* The gradient interpolates between two circles: the start circle at
|
|
1292
|
-
* `(x0, y0)` with radius `r0` and the end circle at `(x1, y1)` with
|
|
1293
|
-
* radius `r1`.
|
|
1294
|
-
*
|
|
1295
|
-
* @param options Gradient parameters.
|
|
1296
|
-
* @returns A {@link GradientFill} descriptor (with `shadingType: 3`).
|
|
1297
|
-
*/
|
|
1298
|
-
declare function radialGradient(options: RadialGradientOptions): GradientFill;
|
|
1299
|
-
/**
|
|
1300
|
-
* Create a tiling pattern descriptor.
|
|
1301
|
-
*
|
|
1302
|
-
* @param options Pattern parameters including the tile content stream.
|
|
1303
|
-
* @returns A {@link PatternFill} descriptor.
|
|
1304
|
-
*/
|
|
1305
|
-
declare function tilingPattern(options: TilingPatternOptions): PatternFill;
|
|
1306
|
-
/**
|
|
1307
|
-
* Materialise a {@link GradientFill} descriptor into actual PDF objects
|
|
1308
|
-
* in the given registry.
|
|
1309
|
-
*
|
|
1310
|
-
* @param gradient The gradient descriptor.
|
|
1311
|
-
* @param registry The document's object registry.
|
|
1312
|
-
* @returns An object with the pattern's indirect reference and a unique
|
|
1313
|
-
* resource name.
|
|
1314
|
-
*/
|
|
1315
|
-
declare function buildGradientObjects(gradient: GradientFill, registry: PdfObjectRegistry): {
|
|
1316
|
-
patternRef: PdfRef;
|
|
1317
|
-
patternName: string;
|
|
1318
|
-
};
|
|
1319
|
-
/**
|
|
1320
|
-
* Materialise a {@link PatternFill} descriptor into actual PDF objects
|
|
1321
|
-
* in the given registry.
|
|
1322
|
-
*
|
|
1323
|
-
* @param pattern The tiling pattern descriptor.
|
|
1324
|
-
* @param registry The document's object registry.
|
|
1325
|
-
* @returns An object with the pattern's indirect reference and a unique
|
|
1326
|
-
* resource name.
|
|
1327
|
-
*/
|
|
1328
|
-
declare function buildPatternObjects(pattern: PatternFill, registry: PdfObjectRegistry): {
|
|
1329
|
-
patternRef: PdfRef;
|
|
1330
|
-
patternName: string;
|
|
1331
|
-
};
|
|
1332
|
-
//#endregion
|
|
1333
|
-
//#region src/barcode/qr.d.ts
|
|
1334
|
-
/** Error correction level. */
|
|
1335
|
-
type ErrorCorrectionLevel = 'L' | 'M' | 'Q' | 'H';
|
|
1336
|
-
/** Options for rendering a QR code to PDF operators. */
|
|
1337
|
-
interface QrCodeOptions {
|
|
1338
|
-
/** Error correction level. Default: `'M'`. */
|
|
1339
|
-
readonly errorCorrection?: ErrorCorrectionLevel;
|
|
1340
|
-
/** Size of each module in PDF points. Default: `2`. */
|
|
1341
|
-
readonly moduleSize?: number;
|
|
1342
|
-
/** Number of quiet-zone modules around the code. Default: `4`. */
|
|
1343
|
-
readonly quietZone?: number;
|
|
1344
|
-
/** Foreground (dark module) colour. Default: black. */
|
|
1345
|
-
readonly color?: Color;
|
|
1346
|
-
/** Background colour. Default: white. */
|
|
1347
|
-
readonly backgroundColor?: Color;
|
|
1348
|
-
}
|
|
1349
|
-
/** The result of QR code encoding — a boolean matrix. */
|
|
1350
|
-
interface QrCodeMatrix {
|
|
1351
|
-
/** Number of modules per side. */
|
|
1352
|
-
readonly size: number;
|
|
1353
|
-
/** Row-major boolean array. `true` = dark module. */
|
|
1354
|
-
readonly modules: readonly boolean[];
|
|
1355
|
-
/** QR version (1-40). */
|
|
1356
|
-
readonly version: number;
|
|
1357
|
-
}
|
|
1358
|
-
/**
|
|
1359
|
-
* Encode a string as a QR code matrix.
|
|
1360
|
-
*
|
|
1361
|
-
* @param data The string to encode.
|
|
1362
|
-
* @param errorCorrection Error correction level (default: `'M'`).
|
|
1363
|
-
* @returns A {@link QrCodeMatrix} with the encoded data.
|
|
1364
|
-
*/
|
|
1365
|
-
declare function encodeQrCode(data: string, errorCorrection?: ErrorCorrectionLevel): QrCodeMatrix;
|
|
1366
|
-
/**
|
|
1367
|
-
* Convert a {@link QrCodeMatrix} to PDF content-stream operators.
|
|
1368
|
-
*
|
|
1369
|
-
* The QR code is rendered as filled rectangles (one per dark module),
|
|
1370
|
-
* positioned at `(x, y)` in PDF user-space coordinates. The `y`
|
|
1371
|
-
* coordinate refers to the **bottom-left** corner of the QR code.
|
|
1372
|
-
*
|
|
1373
|
-
* @param matrix The QR code matrix from {@link encodeQrCode}.
|
|
1374
|
-
* @param x X position in PDF points.
|
|
1375
|
-
* @param y Y position in PDF points.
|
|
1376
|
-
* @param options Rendering options (module size, quiet zone, colours).
|
|
1377
|
-
* @returns A string of PDF content-stream operators.
|
|
1378
|
-
*/
|
|
1379
|
-
declare function qrCodeToOperators(matrix: QrCodeMatrix, x: number, y: number, options?: QrCodeOptions): string;
|
|
1380
|
-
//#endregion
|
|
1381
|
-
//#region src/layout/table.d.ts
|
|
1382
|
-
/** A styled text run within a cell -- allows inline style variation. */
|
|
1383
|
-
interface TextRun {
|
|
1384
|
-
readonly text: string;
|
|
1385
|
-
readonly fontSize?: number;
|
|
1386
|
-
readonly color?: Color;
|
|
1387
|
-
readonly fontName?: string;
|
|
1388
|
-
}
|
|
1389
|
-
/** Content that can appear in a cell: plain text, styled text runs, or a nested table. */
|
|
1390
|
-
type CellContent = string | TextRun[] | NestedTableContent;
|
|
1391
|
-
/** A nested table definition used as cell content. */
|
|
1392
|
-
interface NestedTableContent {
|
|
1393
|
-
readonly type: 'table';
|
|
1394
|
-
readonly table: Omit<DrawTableOptions, 'x' | 'y'>;
|
|
1395
|
-
}
|
|
1396
|
-
/** Single table cell. */
|
|
1397
|
-
interface TableCell {
|
|
1398
|
-
readonly content: CellContent;
|
|
1399
|
-
readonly colSpan?: number;
|
|
1400
|
-
readonly rowSpan?: number;
|
|
1401
|
-
readonly backgroundColor?: Color;
|
|
1402
|
-
readonly textColor?: Color;
|
|
1403
|
-
readonly fontSize?: number;
|
|
1404
|
-
readonly align?: 'left' | 'center' | 'right';
|
|
1405
|
-
readonly verticalAlign?: 'top' | 'middle' | 'bottom';
|
|
1406
|
-
readonly padding?: number | {
|
|
1407
|
-
top?: number;
|
|
1408
|
-
right?: number;
|
|
1409
|
-
bottom?: number;
|
|
1410
|
-
left?: number;
|
|
1411
|
-
};
|
|
1412
|
-
/** Text overflow mode. Default: 'truncate'. */
|
|
1413
|
-
readonly overflow?: 'wrap' | 'truncate' | 'ellipsis' | 'shrink';
|
|
1414
|
-
}
|
|
1415
|
-
/** Table row. */
|
|
1416
|
-
interface TableRow {
|
|
1417
|
-
readonly cells: readonly (TableCell | string)[];
|
|
1418
|
-
readonly height?: number;
|
|
1419
|
-
readonly backgroundColor?: Color;
|
|
1420
|
-
}
|
|
1421
|
-
/** Column definition. */
|
|
1422
|
-
interface TableColumn {
|
|
1423
|
-
/** Fixed width in points. */
|
|
1424
|
-
readonly width?: number;
|
|
1425
|
-
/** Percentage of table width (e.g., '30%'). */
|
|
1426
|
-
readonly percentage?: string;
|
|
1427
|
-
/** Flex weight (like CSS flex-grow). Default: 1 when no width/percentage. */
|
|
1428
|
-
readonly flex?: number;
|
|
1429
|
-
/** Auto-fit: measure content and use minimum needed width. */
|
|
1430
|
-
readonly autoFit?: boolean;
|
|
1431
|
-
readonly minWidth?: number;
|
|
1432
|
-
readonly maxWidth?: number;
|
|
1433
|
-
readonly align?: 'left' | 'center' | 'right';
|
|
1434
|
-
}
|
|
1435
|
-
/** Full table configuration. */
|
|
1436
|
-
interface DrawTableOptions {
|
|
1437
|
-
readonly x: number;
|
|
1438
|
-
readonly y: number;
|
|
1439
|
-
readonly width: number;
|
|
1440
|
-
readonly rows: readonly TableRow[];
|
|
1441
|
-
readonly columns?: readonly TableColumn[];
|
|
1442
|
-
/** PDF font resource name, default 'Helvetica'. */
|
|
1443
|
-
readonly fontName?: string;
|
|
1444
|
-
/** Default font size in points, default 12. */
|
|
1445
|
-
readonly fontSize?: number;
|
|
1446
|
-
readonly textColor?: Color;
|
|
1447
|
-
readonly borderColor?: Color;
|
|
1448
|
-
/** Border line width in points, default 0.5. */
|
|
1449
|
-
readonly borderWidth?: number;
|
|
1450
|
-
/** Number of header rows (reserved for future page-break support). */
|
|
1451
|
-
readonly headerRows?: number;
|
|
1452
|
-
/** Default cell padding in points, default 4. */
|
|
1453
|
-
readonly padding?: number;
|
|
1454
|
-
/** Alternating row background colors [even, odd]. */
|
|
1455
|
-
readonly alternateRowColors?: readonly [Color, Color];
|
|
1456
|
-
/** Header background color (overrides alternateRowColors for header rows). */
|
|
1457
|
-
readonly headerBackgroundColor?: Color;
|
|
1458
|
-
/** Header text color. */
|
|
1459
|
-
readonly headerTextColor?: Color;
|
|
1460
|
-
}
|
|
1461
|
-
/** Result of table rendering. */
|
|
1462
|
-
interface TableRenderResult {
|
|
1463
|
-
readonly width: number;
|
|
1464
|
-
readonly height: number;
|
|
1465
|
-
readonly rowHeights: readonly number[];
|
|
1466
|
-
readonly columnWidths: readonly number[];
|
|
1467
|
-
readonly pagesUsed: number;
|
|
1468
|
-
}
|
|
1469
|
-
/** Content for a single page in a multi-page table render. */
|
|
1470
|
-
interface PageContent {
|
|
1471
|
-
readonly ops: string;
|
|
1472
|
-
readonly pageIndex: number;
|
|
1473
|
-
}
|
|
1474
|
-
/** Result of multi-page table rendering. */
|
|
1475
|
-
interface MultiPageTableResult {
|
|
1476
|
-
readonly pages: readonly PageContent[];
|
|
1477
|
-
readonly result: TableRenderResult;
|
|
1478
|
-
}
|
|
1479
|
-
declare function renderTable(options: DrawTableOptions): {
|
|
1480
|
-
ops: string;
|
|
1481
|
-
result: TableRenderResult;
|
|
1482
|
-
};
|
|
1483
|
-
/**
|
|
1484
|
-
* Render a table across multiple pages, breaking rows when content
|
|
1485
|
-
* would exceed the available vertical space.
|
|
1486
|
-
*
|
|
1487
|
-
* Header rows (specified by `options.headerRows`) are repeated at the
|
|
1488
|
-
* top of each new page. Rows are never split across pages.
|
|
1489
|
-
*/
|
|
1490
|
-
declare function renderMultiPageTable(options: DrawTableOptions, bottomMargin?: number): MultiPageTableResult;
|
|
1491
|
-
//#endregion
|
|
1492
|
-
//#region src/core/pdfPage.d.ts
|
|
1493
|
-
/** Pre-defined page sizes as `[width, height]` tuples in PDF points. */
|
|
1494
|
-
declare const PageSizes: {
|
|
1495
|
-
readonly '4A0': readonly [4767.87, 6740.79];
|
|
1496
|
-
readonly '2A0': readonly [3370.39, 4767.87];
|
|
1497
|
-
readonly A0: readonly [2383.94, 3370.39];
|
|
1498
|
-
readonly A1: readonly [1683.78, 2383.94];
|
|
1499
|
-
readonly A2: readonly [1190.55, 1683.78];
|
|
1500
|
-
readonly A3: readonly [841.89, 1190.55];
|
|
1501
|
-
readonly A4: readonly [595.28, 841.89];
|
|
1502
|
-
readonly A5: readonly [419.53, 595.28];
|
|
1503
|
-
readonly A6: readonly [297.64, 419.53];
|
|
1504
|
-
readonly A7: readonly [209.76, 297.64];
|
|
1505
|
-
readonly A8: readonly [147.4, 209.76];
|
|
1506
|
-
readonly A9: readonly [104.88, 147.4];
|
|
1507
|
-
readonly A10: readonly [73.7, 104.88];
|
|
1508
|
-
readonly B0: readonly [2834.65, 4008.19];
|
|
1509
|
-
readonly B1: readonly [2004.09, 2834.65];
|
|
1510
|
-
readonly B2: readonly [1417.32, 2004.09];
|
|
1511
|
-
readonly B3: readonly [1000.63, 1417.32];
|
|
1512
|
-
readonly B4: readonly [708.66, 1000.63];
|
|
1513
|
-
readonly B5: readonly [498.9, 708.66];
|
|
1514
|
-
readonly B6: readonly [354.33, 498.9];
|
|
1515
|
-
readonly B7: readonly [249.45, 354.33];
|
|
1516
|
-
readonly B8: readonly [175.75, 249.45];
|
|
1517
|
-
readonly B9: readonly [124.72, 175.75];
|
|
1518
|
-
readonly B10: readonly [87.87, 124.72];
|
|
1519
|
-
readonly Letter: readonly [612, 792];
|
|
1520
|
-
readonly Legal: readonly [612, 1008];
|
|
1521
|
-
readonly Tabloid: readonly [792, 1224];
|
|
1522
|
-
readonly Ledger: readonly [1224, 792];
|
|
1523
|
-
readonly Executive: readonly [521.86, 756];
|
|
1524
|
-
readonly Folio: readonly [612, 936];
|
|
1525
|
-
readonly C0: readonly [2599.37, 3676.54];
|
|
1526
|
-
readonly C1: readonly [1836.85, 2599.37];
|
|
1527
|
-
readonly C2: readonly [1298.27, 1836.85];
|
|
1528
|
-
readonly C3: readonly [918.43, 1298.27];
|
|
1529
|
-
readonly C4: readonly [649.13, 918.43];
|
|
1530
|
-
readonly C5: readonly [459.21, 649.13];
|
|
1531
|
-
readonly C6: readonly [323.15, 459.21];
|
|
1532
|
-
readonly C7: readonly [229.61, 323.15];
|
|
1533
|
-
readonly C8: readonly [161.57, 229.61];
|
|
1534
|
-
readonly C9: readonly [113.39, 161.57];
|
|
1535
|
-
readonly C10: readonly [79.37, 113.39];
|
|
1536
|
-
readonly RA0: readonly [2437.8, 3458.27];
|
|
1537
|
-
readonly RA1: readonly [1729.13, 2437.8];
|
|
1538
|
-
readonly RA2: readonly [1218.9, 1729.13];
|
|
1539
|
-
readonly RA3: readonly [864.57, 1218.9];
|
|
1540
|
-
readonly RA4: readonly [609.45, 864.57];
|
|
1541
|
-
readonly SRA0: readonly [2551.18, 3628.35];
|
|
1542
|
-
readonly SRA1: readonly [1814.17, 2551.18];
|
|
1543
|
-
readonly SRA2: readonly [1275.59, 1814.17];
|
|
1544
|
-
readonly SRA3: readonly [907.09, 1275.59];
|
|
1545
|
-
readonly SRA4: readonly [637.8, 907.09];
|
|
1546
|
-
};
|
|
1547
|
-
/** Type for a page-size input: a `[width, height]` tuple or `{ width, height }` object. */
|
|
1548
|
-
type PageSize = readonly [width: number, height: number] | {
|
|
1549
|
-
readonly width: number;
|
|
1550
|
-
readonly height: number;
|
|
1551
|
-
};
|
|
1552
|
-
/** Options for {@link PdfPage.drawText}. */
|
|
1553
|
-
interface DrawTextOptions {
|
|
1554
|
-
/** X coordinate. */
|
|
1555
|
-
x?: number | undefined;
|
|
1556
|
-
/** Y coordinate. */
|
|
1557
|
-
y?: number | undefined;
|
|
1558
|
-
/**
|
|
1559
|
-
* Font to use for rendering.
|
|
1560
|
-
*
|
|
1561
|
-
* Accepts either a {@link FontRef} object (returned by `doc.embedFont()`)
|
|
1562
|
-
* or a font resource name string (e.g. `'F1'`).
|
|
1563
|
-
*
|
|
1564
|
-
* When a `FontRef` is provided, its `name` property is used as the
|
|
1565
|
-
* resource name and its CID encoder (if any) is used automatically.
|
|
1566
|
-
*/
|
|
1567
|
-
font?: FontRef | string | undefined;
|
|
1568
|
-
/** Font size in points. */
|
|
1569
|
-
size?: number | undefined;
|
|
1570
|
-
/** Text colour. Defaults to black. */
|
|
1571
|
-
color?: Color | undefined;
|
|
1572
|
-
/** Rotation angle. */
|
|
1573
|
-
rotate?: Angle | undefined;
|
|
1574
|
-
/** Line height for multi-line text. */
|
|
1575
|
-
lineHeight?: number | undefined;
|
|
1576
|
-
/** Opacity `[0, 1]`. */
|
|
1577
|
-
opacity?: number | undefined;
|
|
1578
|
-
/** Blend mode for compositing. */
|
|
1579
|
-
blendMode?: BlendMode | undefined;
|
|
1580
|
-
/** Text rendering mode (fill, stroke, invisible, clip, etc.). */
|
|
1581
|
-
renderingMode?: TextRenderingMode | undefined;
|
|
1582
|
-
/** Horizontal skew angle (italic-like effect). */
|
|
1583
|
-
xSkew?: Angle | undefined;
|
|
1584
|
-
/** Vertical skew angle. */
|
|
1585
|
-
ySkew?: Angle | undefined;
|
|
1586
|
-
/**
|
|
1587
|
-
* Maximum width in points before text is automatically wrapped.
|
|
1588
|
-
*
|
|
1589
|
-
* When provided with a {@link FontRef} font (which has `widthOfTextAtSize`),
|
|
1590
|
-
* the text is broken at word boundaries to fit within this width.
|
|
1591
|
-
* If a single word exceeds `maxWidth`, it is broken at character level.
|
|
1592
|
-
*
|
|
1593
|
-
* When the font is a plain string (no measurement available), this
|
|
1594
|
-
* option is ignored.
|
|
1595
|
-
*/
|
|
1596
|
-
maxWidth?: number | undefined;
|
|
1597
|
-
/**
|
|
1598
|
-
* Characters at which text may be broken when wrapping.
|
|
1599
|
-
*
|
|
1600
|
-
* Defaults to `[' ']` (space only). Pass additional characters such as
|
|
1601
|
-
* `[' ', '-', '/']` to allow breaks at hyphens, slashes, etc.
|
|
1602
|
-
*
|
|
1603
|
-
* The break character is kept at the **end** of the preceding line
|
|
1604
|
-
* (e.g. `'hello-'` / `'world'`), except for space which is consumed
|
|
1605
|
-
* as in the default behaviour.
|
|
1606
|
-
*/
|
|
1607
|
-
wordBreaks?: string[] | undefined;
|
|
1608
|
-
}
|
|
1609
|
-
/** Options for {@link PdfPage.drawImage}. */
|
|
1610
|
-
interface DrawImageOptions {
|
|
1611
|
-
/** X coordinate of the lower-left corner. */
|
|
1612
|
-
x?: number | undefined;
|
|
1613
|
-
/** Y coordinate of the lower-left corner. */
|
|
1614
|
-
y?: number | undefined;
|
|
1615
|
-
/** Rendered width. */
|
|
1616
|
-
width?: number | undefined;
|
|
1617
|
-
/** Rendered height. */
|
|
1618
|
-
height?: number | undefined;
|
|
1619
|
-
/** Rotation angle. */
|
|
1620
|
-
rotate?: Angle | undefined;
|
|
1621
|
-
/** Opacity `[0, 1]`. */
|
|
1622
|
-
opacity?: number | undefined;
|
|
1623
|
-
/** Blend mode for compositing. */
|
|
1624
|
-
blendMode?: BlendMode | undefined;
|
|
1625
|
-
/** Horizontal skew angle. */
|
|
1626
|
-
xSkew?: Angle | undefined;
|
|
1627
|
-
/** Vertical skew angle. */
|
|
1628
|
-
ySkew?: Angle | undefined;
|
|
1629
|
-
}
|
|
1630
|
-
/** Options for {@link PdfPage.drawRectangle}. */
|
|
1631
|
-
interface DrawRectangleOptions {
|
|
1632
|
-
/** X coordinate. */
|
|
1633
|
-
x?: number | undefined;
|
|
1634
|
-
/** Y coordinate. */
|
|
1635
|
-
y?: number | undefined;
|
|
1636
|
-
/** Rectangle width. */
|
|
1637
|
-
width?: number | undefined;
|
|
1638
|
-
/** Rectangle height. */
|
|
1639
|
-
height?: number | undefined;
|
|
1640
|
-
/** Fill colour. Set to `undefined` for no fill. */
|
|
1641
|
-
color?: Color | undefined;
|
|
1642
|
-
/** Border (stroke) colour. Set to `undefined` for no stroke. */
|
|
1643
|
-
borderColor?: Color | undefined;
|
|
1644
|
-
/** Border width in points. */
|
|
1645
|
-
borderWidth?: number | undefined;
|
|
1646
|
-
/** Rotation angle. */
|
|
1647
|
-
rotate?: Angle | undefined;
|
|
1648
|
-
/** Opacity `[0, 1]`. */
|
|
1649
|
-
opacity?: number | undefined;
|
|
1650
|
-
/** Blend mode for compositing. */
|
|
1651
|
-
blendMode?: BlendMode | undefined;
|
|
1652
|
-
/** Horizontal skew angle. */
|
|
1653
|
-
xSkew?: Angle | undefined;
|
|
1654
|
-
/** Vertical skew angle. */
|
|
1655
|
-
ySkew?: Angle | undefined;
|
|
1656
|
-
/** Dash pattern for border `[dashLen, gapLen, ...]`. */
|
|
1657
|
-
borderDashArray?: number[] | undefined;
|
|
1658
|
-
/** Dash phase offset for border. */
|
|
1659
|
-
borderDashPhase?: number | undefined;
|
|
1660
|
-
/** Line cap style for border (0 = butt, 1 = round, 2 = projecting square). */
|
|
1661
|
-
borderLineCap?: 0 | 1 | 2 | undefined;
|
|
1662
|
-
/** Border stroke opacity `[0, 1]`, separate from fill opacity. */
|
|
1663
|
-
borderOpacity?: number | undefined;
|
|
1664
|
-
}
|
|
1665
|
-
/** Options for {@link PdfPage.drawLine}. */
|
|
1666
|
-
interface DrawLineOptions {
|
|
1667
|
-
/** Start point. */
|
|
1668
|
-
start: {
|
|
1669
|
-
x: number;
|
|
1670
|
-
y: number;
|
|
1671
|
-
};
|
|
1672
|
-
/** End point. */
|
|
1673
|
-
end: {
|
|
1674
|
-
x: number;
|
|
1675
|
-
y: number;
|
|
1676
|
-
};
|
|
1677
|
-
/** Line colour. */
|
|
1678
|
-
color?: Color | undefined;
|
|
1679
|
-
/** Line width. */
|
|
1680
|
-
thickness?: number | undefined;
|
|
1681
|
-
/** Dash pattern `[dashLength, gapLength]`. */
|
|
1682
|
-
dashArray?: number[] | undefined;
|
|
1683
|
-
/** Dash phase. */
|
|
1684
|
-
dashPhase?: number | undefined;
|
|
1685
|
-
/** Opacity `[0, 1]`. */
|
|
1686
|
-
opacity?: number | undefined;
|
|
1687
|
-
/** Blend mode for compositing. */
|
|
1688
|
-
blendMode?: BlendMode | undefined;
|
|
1689
|
-
}
|
|
1690
|
-
/** Options for {@link PdfPage.drawCircle}. */
|
|
1691
|
-
interface DrawCircleOptions {
|
|
1692
|
-
/** Centre x. */
|
|
1693
|
-
x?: number | undefined;
|
|
1694
|
-
/** Centre y. */
|
|
1695
|
-
y?: number | undefined;
|
|
1696
|
-
/** Radius of the circle. */
|
|
1697
|
-
radius?: number | undefined;
|
|
1698
|
-
/**
|
|
1699
|
-
* Radius of the circle.
|
|
1700
|
-
* @deprecated Use `radius` instead.
|
|
1701
|
-
*/
|
|
1702
|
-
size?: number | undefined;
|
|
1703
|
-
/** Fill colour. */
|
|
1704
|
-
color?: Color | undefined;
|
|
1705
|
-
/** Border colour. */
|
|
1706
|
-
borderColor?: Color | undefined;
|
|
1707
|
-
/** Border width. */
|
|
1708
|
-
borderWidth?: number | undefined;
|
|
1709
|
-
/** Opacity. */
|
|
1710
|
-
opacity?: number | undefined;
|
|
1711
|
-
/** Blend mode for compositing. */
|
|
1712
|
-
blendMode?: BlendMode | undefined;
|
|
1713
|
-
/** Dash pattern for border. */
|
|
1714
|
-
borderDashArray?: number[] | undefined;
|
|
1715
|
-
/** Dash phase offset for border. */
|
|
1716
|
-
borderDashPhase?: number | undefined;
|
|
1717
|
-
/** Line cap style for border. */
|
|
1718
|
-
borderLineCap?: 0 | 1 | 2 | undefined;
|
|
1719
|
-
/** Border stroke opacity `[0, 1]`. */
|
|
1720
|
-
borderOpacity?: number | undefined;
|
|
1721
|
-
}
|
|
1722
|
-
/** Options for {@link PdfPage.drawEllipse}. */
|
|
1723
|
-
interface DrawEllipseOptions {
|
|
1724
|
-
/** Centre x. */
|
|
1725
|
-
x?: number | undefined;
|
|
1726
|
-
/** Centre y. */
|
|
1727
|
-
y?: number | undefined;
|
|
1728
|
-
/** Horizontal radius. */
|
|
1729
|
-
xScale?: number | undefined;
|
|
1730
|
-
/** Vertical radius. */
|
|
1731
|
-
yScale?: number | undefined;
|
|
1732
|
-
/** Fill colour. */
|
|
1733
|
-
color?: Color | undefined;
|
|
1734
|
-
/** Border colour. */
|
|
1735
|
-
borderColor?: Color | undefined;
|
|
1736
|
-
/** Border width. */
|
|
1737
|
-
borderWidth?: number | undefined;
|
|
1738
|
-
/** Opacity `[0, 1]`. */
|
|
1739
|
-
opacity?: number | undefined;
|
|
1740
|
-
/** Blend mode for compositing. */
|
|
1741
|
-
blendMode?: BlendMode | undefined;
|
|
1742
|
-
/** Dash pattern for border. */
|
|
1743
|
-
borderDashArray?: number[] | undefined;
|
|
1744
|
-
/** Dash phase offset for border. */
|
|
1745
|
-
borderDashPhase?: number | undefined;
|
|
1746
|
-
/** Line cap style for border. */
|
|
1747
|
-
borderLineCap?: 0 | 1 | 2 | undefined;
|
|
1748
|
-
/** Border stroke opacity `[0, 1]`. */
|
|
1749
|
-
borderOpacity?: number | undefined;
|
|
1750
|
-
}
|
|
1751
|
-
/** Options for {@link PdfPage.drawSvgPath}. */
|
|
1752
|
-
interface DrawSvgPathOptions {
|
|
1753
|
-
/** X translation (PDF coordinates). */
|
|
1754
|
-
x?: number | undefined;
|
|
1755
|
-
/** Y translation (PDF coordinates). */
|
|
1756
|
-
y?: number | undefined;
|
|
1757
|
-
/** Uniform scale factor applied to the path. */
|
|
1758
|
-
scale?: number | undefined;
|
|
1759
|
-
/** Fill colour. */
|
|
1760
|
-
color?: Color | undefined;
|
|
1761
|
-
/** Border (stroke) colour. */
|
|
1762
|
-
borderColor?: Color | undefined;
|
|
1763
|
-
/** Border width in points. */
|
|
1764
|
-
borderWidth?: number | undefined;
|
|
1765
|
-
/** Opacity `[0, 1]`. */
|
|
1766
|
-
opacity?: number | undefined;
|
|
1767
|
-
/** Blend mode for compositing. */
|
|
1768
|
-
blendMode?: BlendMode | undefined;
|
|
1769
|
-
/** Dash pattern for border. */
|
|
1770
|
-
borderDashArray?: number[] | undefined;
|
|
1771
|
-
/** Dash phase offset for border. */
|
|
1772
|
-
borderDashPhase?: number | undefined;
|
|
1773
|
-
/** Line cap style for border. */
|
|
1774
|
-
borderLineCap?: 0 | 1 | 2 | undefined;
|
|
1775
|
-
/** Border stroke opacity `[0, 1]`. */
|
|
1776
|
-
borderOpacity?: number | undefined;
|
|
1777
|
-
}
|
|
1778
|
-
/** Options for {@link PdfPage.drawQrCode}. */
|
|
1779
|
-
interface DrawQrCodeOptions {
|
|
1780
|
-
/** X coordinate (bottom-left of QR code). */
|
|
1781
|
-
x?: number | undefined;
|
|
1782
|
-
/** Y coordinate (bottom-left of QR code). */
|
|
1783
|
-
y?: number | undefined;
|
|
1784
|
-
/** Error correction level. Default: `'M'`. */
|
|
1785
|
-
errorCorrection?: ErrorCorrectionLevel | undefined;
|
|
1786
|
-
/** Size of each module in PDF points. Default: `2`. */
|
|
1787
|
-
moduleSize?: number | undefined;
|
|
1788
|
-
/** Number of quiet-zone modules around the code. Default: `4`. */
|
|
1789
|
-
quietZone?: number | undefined;
|
|
1790
|
-
/** Foreground (dark module) colour. Default: black. */
|
|
1791
|
-
color?: Color | undefined;
|
|
1792
|
-
/** Background colour. Default: white. */
|
|
1793
|
-
backgroundColor?: Color | undefined;
|
|
1794
|
-
}
|
|
1795
|
-
/** Options for {@link PdfPage.drawSquare}. */
|
|
1796
|
-
interface DrawSquareOptions {
|
|
1797
|
-
/** X coordinate. */
|
|
1798
|
-
x?: number | undefined;
|
|
1799
|
-
/** Y coordinate. */
|
|
1800
|
-
y?: number | undefined;
|
|
1801
|
-
/** Side length of the square. Defaults to `100`. */
|
|
1802
|
-
size?: number | undefined;
|
|
1803
|
-
/** Fill colour. */
|
|
1804
|
-
color?: Color | undefined;
|
|
1805
|
-
/** Border (stroke) colour. */
|
|
1806
|
-
borderColor?: Color | undefined;
|
|
1807
|
-
/** Border width in points. */
|
|
1808
|
-
borderWidth?: number | undefined;
|
|
1809
|
-
/** Rotation angle. */
|
|
1810
|
-
rotate?: Angle | undefined;
|
|
1811
|
-
/** Opacity `[0, 1]`. */
|
|
1812
|
-
opacity?: number | undefined;
|
|
1813
|
-
/** Blend mode for compositing. */
|
|
1814
|
-
blendMode?: BlendMode | undefined;
|
|
1815
|
-
/** Horizontal skew angle. */
|
|
1816
|
-
xSkew?: Angle | undefined;
|
|
1817
|
-
/** Vertical skew angle. */
|
|
1818
|
-
ySkew?: Angle | undefined;
|
|
1819
|
-
/** Dash pattern for border. */
|
|
1820
|
-
borderDashArray?: number[] | undefined;
|
|
1821
|
-
/** Dash phase offset for border. */
|
|
1822
|
-
borderDashPhase?: number | undefined;
|
|
1823
|
-
/** Line cap style for border. */
|
|
1824
|
-
borderLineCap?: 0 | 1 | 2 | undefined;
|
|
1825
|
-
/** Border stroke opacity `[0, 1]`. */
|
|
1826
|
-
borderOpacity?: number | undefined;
|
|
1827
|
-
}
|
|
1828
|
-
/** Opaque handle for a font that has been embedded in the document. */
|
|
1829
|
-
interface FontRef {
|
|
1830
|
-
/** Resource name used in content-stream operators (e.g. `F1`). */
|
|
1831
|
-
readonly name: string;
|
|
1832
|
-
/** Indirect reference to the font dictionary. */
|
|
1833
|
-
readonly ref: PdfRef;
|
|
1834
|
-
/**
|
|
1835
|
-
* Compute the width of a text string at the given font size (in points).
|
|
1836
|
-
* Available for both standard and TrueType fonts.
|
|
1837
|
-
*/
|
|
1838
|
-
widthOfTextAtSize(text: string, size: number): number;
|
|
1839
|
-
/**
|
|
1840
|
-
* Compute the height of the font at the given size (ascender - descender).
|
|
1841
|
-
* Available for both standard and TrueType fonts.
|
|
1842
|
-
*/
|
|
1843
|
-
heightAtSize(size: number): number;
|
|
1844
|
-
/**
|
|
1845
|
-
* Whether this font uses CID (Identity-H) encoding.
|
|
1846
|
-
* When true, text must be encoded as hex glyph IDs in content streams.
|
|
1847
|
-
* @internal
|
|
1848
|
-
*/
|
|
1849
|
-
readonly _isCIDFont?: boolean;
|
|
1850
|
-
/**
|
|
1851
|
-
* Encode text as a hex string of CID glyph IDs for content streams.
|
|
1852
|
-
* Only present for CID (TrueType) fonts.
|
|
1853
|
-
* @internal
|
|
1854
|
-
*/
|
|
1855
|
-
_encodeText?(text: string): string;
|
|
1856
|
-
/**
|
|
1857
|
-
* Compute the font size needed to achieve a given height (ascender - descender).
|
|
1858
|
-
* This is the inverse of `heightAtSize()`.
|
|
1859
|
-
*
|
|
1860
|
-
* @param height Desired height in points.
|
|
1861
|
-
* @returns Font size in points.
|
|
1862
|
-
*/
|
|
1863
|
-
sizeAtHeight?(height: number): number;
|
|
1864
|
-
/**
|
|
1865
|
-
* Return the set of Unicode codepoints supported by this font.
|
|
1866
|
-
*
|
|
1867
|
-
* For standard fonts, returns the WinAnsi character set.
|
|
1868
|
-
* For embedded fonts, returns all codepoints in the cmap table.
|
|
1869
|
-
*
|
|
1870
|
-
* @returns Array of Unicode codepoint numbers.
|
|
1871
|
-
*/
|
|
1872
|
-
getCharacterSet?(): number[];
|
|
1873
|
-
}
|
|
1874
|
-
/** Opaque handle for an image that has been embedded in the document. */
|
|
1875
|
-
interface ImageRef {
|
|
1876
|
-
/** Resource name used in content-stream operators (e.g. `Im1`). */
|
|
1877
|
-
readonly name: string;
|
|
1878
|
-
/** Indirect reference to the image XObject. */
|
|
1879
|
-
readonly ref: PdfRef;
|
|
1880
|
-
/** Intrinsic width in pixels. */
|
|
1881
|
-
readonly width: number;
|
|
1882
|
-
/** Intrinsic height in pixels. */
|
|
1883
|
-
readonly height: number;
|
|
1884
|
-
/**
|
|
1885
|
-
* Return a new `{ width, height }` scaled by the given factor.
|
|
1886
|
-
*
|
|
1887
|
-
* @param factor Scale multiplier (e.g. `0.5` for half size).
|
|
1888
|
-
*/
|
|
1889
|
-
scale(factor: number): {
|
|
1890
|
-
width: number;
|
|
1891
|
-
height: number;
|
|
1892
|
-
};
|
|
1893
|
-
/**
|
|
1894
|
-
* Return a new `{ width, height }` that fits within the given bounds
|
|
1895
|
-
* while preserving the aspect ratio.
|
|
1896
|
-
*
|
|
1897
|
-
* @param maxWidth Maximum allowed width.
|
|
1898
|
-
* @param maxHeight Maximum allowed height.
|
|
1899
|
-
*/
|
|
1900
|
-
scaleToFit(maxWidth: number, maxHeight: number): {
|
|
1901
|
-
width: number;
|
|
1902
|
-
height: number;
|
|
1903
|
-
};
|
|
1904
|
-
}
|
|
1905
|
-
/**
|
|
1906
|
-
* Options for transparency groups.
|
|
1907
|
-
*
|
|
1908
|
-
* Transparency groups allow a set of drawing operations to be composited
|
|
1909
|
-
* as a single unit before being blended with the page content.
|
|
1910
|
-
*/
|
|
1911
|
-
interface TransparencyGroupOptions {
|
|
1912
|
-
/**
|
|
1913
|
-
* When `true`, the group is composited against a fully transparent
|
|
1914
|
-
* backdrop rather than the existing page content. Default: `true`.
|
|
1915
|
-
*/
|
|
1916
|
-
isolated?: boolean;
|
|
1917
|
-
/**
|
|
1918
|
-
* When `true`, earlier objects in the group are knocked out (replaced)
|
|
1919
|
-
* by later objects, rather than composited on top. Default: `false`.
|
|
1920
|
-
*/
|
|
1921
|
-
knockout?: boolean;
|
|
1922
|
-
/**
|
|
1923
|
-
* Color space for the transparency group. Default: `'DeviceRGB'`.
|
|
1924
|
-
*/
|
|
1925
|
-
colorSpace?: 'DeviceRGB' | 'DeviceCMYK' | 'DeviceGray';
|
|
1926
|
-
}
|
|
1927
|
-
/**
|
|
1928
|
-
* Builder interface for constructing soft mask content.
|
|
1929
|
-
*
|
|
1930
|
-
* All drawing is in grayscale: `1` = fully opaque, `0` = fully transparent.
|
|
1931
|
-
*/
|
|
1932
|
-
interface SoftMaskBuilder {
|
|
1933
|
-
/**
|
|
1934
|
-
* Draw a filled rectangle at the given position with the specified
|
|
1935
|
-
* grayscale value (`0` = black/transparent, `1` = white/opaque).
|
|
1936
|
-
*/
|
|
1937
|
-
drawRectangle(x: number, y: number, width: number, height: number, gray: number): void;
|
|
1938
|
-
/**
|
|
1939
|
-
* Draw a filled circle at the given center with the specified radius
|
|
1940
|
-
* and grayscale value.
|
|
1941
|
-
*/
|
|
1942
|
-
drawCircle(cx: number, cy: number, radius: number, gray: number): void;
|
|
1943
|
-
/**
|
|
1944
|
-
* Append raw PDF content-stream operators to the mask.
|
|
1945
|
-
*/
|
|
1946
|
-
pushRawOperators(ops: string): void;
|
|
1947
|
-
}
|
|
1948
|
-
/**
|
|
1949
|
-
* Opaque reference to a soft mask Form XObject.
|
|
1950
|
-
*
|
|
1951
|
-
* Created by {@link PdfDocument.createSoftMask} and consumed by
|
|
1952
|
-
* {@link PdfPage.applySoftMask}.
|
|
1953
|
-
*/
|
|
1954
|
-
interface SoftMaskRef {
|
|
1955
|
-
readonly _tag: 'softMask';
|
|
1956
|
-
readonly ref: PdfRef;
|
|
1957
|
-
}
|
|
1958
|
-
/**
|
|
1959
|
-
* A single page in a PDF document.
|
|
1960
|
-
*
|
|
1961
|
-
* Drawing methods are synchronous and append PDF operators to an
|
|
1962
|
-
* internal string buffer. The buffer is converted to a content stream
|
|
1963
|
-
* when the document is saved.
|
|
1964
|
-
*/
|
|
1965
|
-
declare class PdfPage {
|
|
1966
|
-
/** Object registry for allocating refs. */
|
|
1967
|
-
private readonly registry;
|
|
1968
|
-
/** Content-stream operators accumulated so far. */
|
|
1969
|
-
private ops;
|
|
1970
|
-
/** Fonts referenced by this page — maps resource name → PdfRef. */
|
|
1971
|
-
private readonly fonts;
|
|
1972
|
-
/**
|
|
1973
|
-
* CID font text encoders — maps resource name → encode function.
|
|
1974
|
-
* Only present for TrueType (CIDFont Type 2) fonts.
|
|
1975
|
-
* @internal
|
|
1976
|
-
*/
|
|
1977
|
-
private readonly cidFontEncoders;
|
|
1978
|
-
/** XObjects (images) referenced by this page. */
|
|
1979
|
-
private readonly xObjects;
|
|
1980
|
-
/**
|
|
1981
|
-
* ExtGState dictionaries referenced by this page.
|
|
1982
|
-
* Maps a resource name (e.g. `GS1`) to its indirect reference.
|
|
1983
|
-
* Used for opacity and other graphics state parameters.
|
|
1984
|
-
*/
|
|
1985
|
-
private readonly extGStates;
|
|
1986
|
-
/**
|
|
1987
|
-
* Pattern resources referenced by this page.
|
|
1988
|
-
* Maps a resource name (e.g. `Pat5`) to its indirect reference.
|
|
1989
|
-
* Used for gradient fills and tiling patterns.
|
|
1990
|
-
*/
|
|
1991
|
-
private readonly patterns;
|
|
1992
|
-
/**
|
|
1993
|
-
* Counter for ExtGState resource names (`GS1`, `GS2`, ...).
|
|
1994
|
-
*/
|
|
1995
|
-
private extGStateCounter;
|
|
1996
|
-
/**
|
|
1997
|
-
* Counter for transparency group XObject resource names (`TG1`, `TG2`, ...).
|
|
1998
|
-
*/
|
|
1999
|
-
private transparencyGroupCounter;
|
|
2000
|
-
/**
|
|
2001
|
-
* Stack of transparency group state. Each entry records the ops length
|
|
2002
|
-
* at the time `beginTransparencyGroup()` was called, plus the options.
|
|
2003
|
-
*/
|
|
2004
|
-
private readonly transparencyGroupStack;
|
|
2005
|
-
/**
|
|
2006
|
-
* Cache mapping composite keys (opacity + blend mode) to their ExtGState
|
|
2007
|
-
* resource names, so the same combination reuses the same graphics state
|
|
2008
|
-
* dictionary.
|
|
2009
|
-
*/
|
|
2010
|
-
private readonly extGStateCache;
|
|
2011
|
-
/** Default font used by `drawText()` when no `font` option is provided. */
|
|
2012
|
-
private _defaultFont?;
|
|
2013
|
-
/** Default font size used by `drawText()` when no `size` option is provided. */
|
|
2014
|
-
private _defaultFontSize?;
|
|
2015
|
-
/** Default font colour used by `drawText()` when no `color` option is provided. */
|
|
2016
|
-
private _defaultFontColor?;
|
|
2017
|
-
/** Default line height used by `drawText()` when no `lineHeight` option is provided. */
|
|
2018
|
-
private _defaultLineHeight?;
|
|
2019
|
-
/** Current cursor X coordinate (used as fallback when x is not specified). */
|
|
2020
|
-
private _cursorX;
|
|
2021
|
-
/** Current cursor Y coordinate (used as fallback when y is not specified). */
|
|
2022
|
-
private _cursorY;
|
|
2023
|
-
/** Pre-allocated indirect reference for this page's /Page dictionary. */
|
|
2024
|
-
readonly pageRef: PdfRef;
|
|
2025
|
-
/** Pre-allocated indirect reference for this page's content stream. */
|
|
2026
|
-
readonly contentStreamRef: PdfRef;
|
|
2027
|
-
/**
|
|
2028
|
-
* Page rotation in degrees (0, 90, 180, or 270).
|
|
2029
|
-
* This is written to the /Rotate entry in the page dictionary at save time.
|
|
2030
|
-
* @internal
|
|
2031
|
-
*/
|
|
2032
|
-
private rotation;
|
|
2033
|
-
/**
|
|
2034
|
-
* Optional crop box `[llx, lly, urx, ury]`.
|
|
2035
|
-
* When set, written to the /CropBox entry in the page dictionary at save time.
|
|
2036
|
-
* @internal
|
|
2037
|
-
*/
|
|
2038
|
-
private cropBox;
|
|
2039
|
-
/**
|
|
2040
|
-
* Optional bleed box `[llx, lly, urx, ury]`.
|
|
2041
|
-
* When set, written to the /BleedBox entry in the page dictionary at save time.
|
|
2042
|
-
* @internal
|
|
2043
|
-
*/
|
|
2044
|
-
private bleedBox;
|
|
2045
|
-
/**
|
|
2046
|
-
* Optional art box `[llx, lly, urx, ury]`.
|
|
2047
|
-
* When set, written to the /ArtBox entry in the page dictionary at save time.
|
|
2048
|
-
* @internal
|
|
2049
|
-
*/
|
|
2050
|
-
private artBox;
|
|
2051
|
-
/**
|
|
2052
|
-
* Optional trim box `[llx, lly, urx, ury]`.
|
|
2053
|
-
* When set, written to the /TrimBox entry in the page dictionary at save time.
|
|
2054
|
-
* @internal
|
|
2055
|
-
*/
|
|
2056
|
-
private trimBox;
|
|
2057
|
-
/**
|
|
2058
|
-
* Mutable media box origin and dimensions. Initially set from constructor.
|
|
2059
|
-
* @internal
|
|
2060
|
-
*/
|
|
2061
|
-
private mediaX;
|
|
2062
|
-
/** @internal */
|
|
2063
|
-
private mediaY;
|
|
2064
|
-
/** @internal */
|
|
2065
|
-
private mediaWidth;
|
|
2066
|
-
/** @internal */
|
|
2067
|
-
private mediaHeight;
|
|
2068
|
-
/** Original page width from construction time (used by resetSize). */
|
|
2069
|
-
private readonly _originalWidth;
|
|
2070
|
-
/** Original page height from construction time (used by resetSize). */
|
|
2071
|
-
private readonly _originalHeight;
|
|
2072
|
-
/**
|
|
2073
|
-
* @internal Original content stream refs from a loaded PDF.
|
|
2074
|
-
* These are indirect references to PdfStream objects already in the registry.
|
|
2075
|
-
*/
|
|
2076
|
-
private _originalContentRefs;
|
|
2077
|
-
/**
|
|
2078
|
-
* @internal Original resources dictionary from a loaded PDF.
|
|
2079
|
-
* Merged with new resources in `buildResources()`.
|
|
2080
|
-
*/
|
|
2081
|
-
private _originalResources;
|
|
2082
|
-
/**
|
|
2083
|
-
* @internal Original annotation refs from a loaded PDF.
|
|
2084
|
-
* Combined with new annotations in `finalize()`.
|
|
2085
|
-
*/
|
|
2086
|
-
private _originalAnnotRefs;
|
|
2087
|
-
constructor(/** Page width in points. */
|
|
2088
|
-
|
|
2089
|
-
w: number, /** Page height in points. */
|
|
2090
|
-
|
|
2091
|
-
h: number, /** Object registry for allocating refs. */
|
|
2092
|
-
|
|
2093
|
-
registry: PdfObjectRegistry);
|
|
2094
|
-
/**
|
|
2095
|
-
* @internal Create a PdfPage pre-loaded with content from a parsed PDF.
|
|
2096
|
-
*
|
|
2097
|
-
* Unlike the normal constructor which creates a blank page, this factory
|
|
2098
|
-
* preserves the original content streams, resources, annotations, and
|
|
2099
|
-
* other page attributes from the parsed PDF.
|
|
2100
|
-
*/
|
|
2101
|
-
static _fromParsed(width: number, height: number, registry: PdfObjectRegistry, opts: {
|
|
2102
|
-
contentRefs?: PdfRef[] | undefined;
|
|
2103
|
-
resources?: PdfDict | undefined;
|
|
2104
|
-
rotation?: number | undefined;
|
|
2105
|
-
cropBox?: [number, number, number, number] | undefined;
|
|
2106
|
-
bleedBox?: [number, number, number, number] | undefined;
|
|
2107
|
-
artBox?: [number, number, number, number] | undefined;
|
|
2108
|
-
trimBox?: [number, number, number, number] | undefined;
|
|
2109
|
-
annotRefs?: PdfRef[] | undefined;
|
|
2110
|
-
}): PdfPage;
|
|
2111
|
-
/** Page width in points. */
|
|
2112
|
-
get width(): number;
|
|
2113
|
-
/** Page height in points. */
|
|
2114
|
-
get height(): number;
|
|
2115
|
-
/** @internal Register a font resource on this page. */
|
|
2116
|
-
registerFont(name: string, ref: PdfRef): void;
|
|
2117
|
-
/**
|
|
2118
|
-
* @internal Register a CID font encoder for a font resource on this page.
|
|
2119
|
-
* When drawText is called with this font, text will be encoded using the
|
|
2120
|
-
* provided encoder function (producing hex glyph IDs) instead of literal strings.
|
|
2121
|
-
*/
|
|
2122
|
-
registerCIDFont(name: string, encoder: (text: string) => string): void;
|
|
2123
|
-
/** @internal Register an image XObject resource on this page. */
|
|
2124
|
-
registerXObject(name: string, ref: PdfRef): void;
|
|
2125
|
-
/** @internal Register an ExtGState resource on this page. */
|
|
2126
|
-
registerExtGState(name: string, ref: PdfRef): void;
|
|
2127
|
-
/** @internal Register a Pattern resource on this page. */
|
|
2128
|
-
registerPattern(name: string, ref: PdfRef): void;
|
|
2129
|
-
/**
|
|
2130
|
-
* Set the default font used by {@link drawText} when the `font` option
|
|
2131
|
-
* is not provided.
|
|
2132
|
-
*
|
|
2133
|
-
* @param font A {@link FontRef} returned by `doc.embedFont()`.
|
|
2134
|
-
*/
|
|
2135
|
-
setFont(font: FontRef): void;
|
|
2136
|
-
/**
|
|
2137
|
-
* Set the default font size (in points) used by {@link drawText} when
|
|
2138
|
-
* the `size` option is not provided.
|
|
2139
|
-
*
|
|
2140
|
-
* @param size Font size in points.
|
|
2141
|
-
*/
|
|
2142
|
-
setFontSize(size: number): void;
|
|
2143
|
-
/**
|
|
2144
|
-
* Set the default font colour used by {@link drawText} when the `color`
|
|
2145
|
-
* option is not provided.
|
|
2146
|
-
*
|
|
2147
|
-
* @param color A {@link Color} value (e.g. from `rgb()`, `cmyk()`, etc.).
|
|
2148
|
-
*/
|
|
2149
|
-
setFontColor(color: Color): void;
|
|
2150
|
-
/**
|
|
2151
|
-
* Set the default line height used by {@link drawText} when the
|
|
2152
|
-
* `lineHeight` option is not provided.
|
|
2153
|
-
*
|
|
2154
|
-
* @param height Line height in points.
|
|
2155
|
-
*/
|
|
2156
|
-
setLineHeight(height: number): void;
|
|
2157
|
-
/**
|
|
2158
|
-
* Get the current cursor position.
|
|
2159
|
-
*
|
|
2160
|
-
* @returns An object with `x` and `y` properties (in points).
|
|
2161
|
-
*/
|
|
2162
|
-
getPosition(): {
|
|
2163
|
-
x: number;
|
|
2164
|
-
y: number;
|
|
2165
|
-
};
|
|
2166
|
-
/**
|
|
2167
|
-
* Get the current cursor X coordinate.
|
|
2168
|
-
*
|
|
2169
|
-
* @returns The X coordinate in points.
|
|
2170
|
-
*/
|
|
2171
|
-
getX(): number;
|
|
2172
|
-
/**
|
|
2173
|
-
* Get the current cursor Y coordinate.
|
|
2174
|
-
*
|
|
2175
|
-
* @returns The Y coordinate in points.
|
|
2176
|
-
*/
|
|
2177
|
-
getY(): number;
|
|
2178
|
-
/**
|
|
2179
|
-
* Move the cursor to an absolute position.
|
|
2180
|
-
*
|
|
2181
|
-
* Drawing methods that accept optional `x` / `y` parameters will use the
|
|
2182
|
-
* cursor position as a fallback when those parameters are omitted.
|
|
2183
|
-
*
|
|
2184
|
-
* @param x The X coordinate in points.
|
|
2185
|
-
* @param y The Y coordinate in points.
|
|
2186
|
-
*/
|
|
2187
|
-
moveTo(x: number, y: number): void;
|
|
2188
|
-
/**
|
|
2189
|
-
* Move the cursor upward by the given amount (increases Y).
|
|
2190
|
-
*
|
|
2191
|
-
* @param amount Distance in points.
|
|
2192
|
-
*/
|
|
2193
|
-
moveUp(amount: number): void;
|
|
2194
|
-
/**
|
|
2195
|
-
* Move the cursor downward by the given amount (decreases Y).
|
|
2196
|
-
*
|
|
2197
|
-
* @param amount Distance in points.
|
|
2198
|
-
*/
|
|
2199
|
-
moveDown(amount: number): void;
|
|
2200
|
-
/**
|
|
2201
|
-
* Move the cursor to the right by the given amount (increases X).
|
|
2202
|
-
*
|
|
2203
|
-
* @param amount Distance in points.
|
|
2204
|
-
*/
|
|
2205
|
-
moveRight(amount: number): void;
|
|
2206
|
-
/**
|
|
2207
|
-
* Move the cursor to the left by the given amount (decreases X).
|
|
2208
|
-
*
|
|
2209
|
-
* @param amount Distance in points.
|
|
2210
|
-
*/
|
|
2211
|
-
moveLeft(amount: number): void;
|
|
2212
|
-
/**
|
|
2213
|
-
* Reset the cursor position to `(0, 0)`.
|
|
2214
|
-
*/
|
|
2215
|
-
resetPosition(): void;
|
|
2216
|
-
/**
|
|
2217
|
-
* Get or create an ExtGState resource for the given opacity and/or
|
|
2218
|
-
* blend mode.
|
|
2219
|
-
*
|
|
2220
|
-
* Creates a PDF ExtGState dictionary with `/ca` + `/CA` (when opacity
|
|
2221
|
-
* is less than 1) and `/BM` (when a non-Normal blend mode is specified).
|
|
2222
|
-
* The dictionary is registered in the object registry and cached so that
|
|
2223
|
-
* the same combination of parameters shares a single resource.
|
|
2224
|
-
*
|
|
2225
|
-
* @param opacity Opacity value in the range `[0, 1]` (optional).
|
|
2226
|
-
* @param blendMode A PDF blend mode name (optional).
|
|
2227
|
-
* @returns The resource name (e.g. `GS1`) to use in content stream operators.
|
|
2228
|
-
* @internal
|
|
2229
|
-
*/
|
|
2230
|
-
private getOrCreateExtGState;
|
|
2231
|
-
/**
|
|
2232
|
-
* Draw a text string at the specified position.
|
|
2233
|
-
*
|
|
2234
|
-
* @param text The text to render.
|
|
2235
|
-
* @param options Position, font, size, colour, rotation.
|
|
2236
|
-
*/
|
|
2237
|
-
drawText(text: string, options?: DrawTextOptions): void;
|
|
2238
|
-
/**
|
|
2239
|
-
* Draw an embedded image on this page.
|
|
2240
|
-
*
|
|
2241
|
-
* @param image Image reference returned by `doc.embedPng()` or
|
|
2242
|
-
* `doc.embedJpeg()`.
|
|
2243
|
-
* @param options Position, dimensions, rotation.
|
|
2244
|
-
*/
|
|
2245
|
-
drawImage(image: ImageRef, options?: DrawImageOptions): void;
|
|
2246
|
-
/**
|
|
2247
|
-
* Draw an embedded PDF page (Form XObject) on this page.
|
|
2248
|
-
*
|
|
2249
|
-
* The embedded page is painted at the given position and scaled to the
|
|
2250
|
-
* specified dimensions. If `width` or `height` is omitted, the
|
|
2251
|
-
* original page dimensions are used.
|
|
2252
|
-
*
|
|
2253
|
-
* @param embeddedPage An embedded page returned by `doc.embedPdf()` or
|
|
2254
|
-
* `doc.embedPage()`.
|
|
2255
|
-
* @param options Position, dimensions, rotation, opacity.
|
|
2256
|
-
*
|
|
2257
|
-
* @example
|
|
2258
|
-
* ```ts
|
|
2259
|
-
* const [embedded] = await doc.embedPdf(otherPdfBytes, [0]);
|
|
2260
|
-
* page.drawPage(embedded, { x: 50, y: 50, width: 300, height: 400 });
|
|
2261
|
-
* ```
|
|
2262
|
-
*/
|
|
2263
|
-
drawPage(embeddedPage: EmbeddedPdfPage, options?: DrawPageOptions): void;
|
|
2264
|
-
/**
|
|
2265
|
-
* Draw a rectangle.
|
|
2266
|
-
*
|
|
2267
|
-
* By default the rectangle is filled with black. Set `color` to
|
|
2268
|
-
* `undefined` and provide `borderColor` for stroke-only.
|
|
2269
|
-
*/
|
|
2270
|
-
drawRectangle(options?: DrawRectangleOptions): void;
|
|
2271
|
-
/**
|
|
2272
|
-
* Draw a square (convenience wrapper around {@link drawRectangle}).
|
|
2273
|
-
*
|
|
2274
|
-
* @param options Position, size, colours, rotation, opacity, blend mode.
|
|
2275
|
-
*/
|
|
2276
|
-
drawSquare(options?: DrawSquareOptions): void;
|
|
2277
|
-
/**
|
|
2278
|
-
* Draw a straight line.
|
|
2279
|
-
*/
|
|
2280
|
-
drawLine(options: DrawLineOptions): void;
|
|
2281
|
-
/**
|
|
2282
|
-
* Draw a circle.
|
|
2283
|
-
*/
|
|
2284
|
-
drawCircle(options?: DrawCircleOptions): void;
|
|
2285
|
-
/**
|
|
2286
|
-
* Draw an ellipse.
|
|
2287
|
-
*/
|
|
2288
|
-
drawEllipse(options?: DrawEllipseOptions): void;
|
|
2289
|
-
/**
|
|
2290
|
-
* Push the current graphics state onto the stack (`q`).
|
|
2291
|
-
*
|
|
2292
|
-
* Must be balanced with a matching {@link popGraphicsState} call.
|
|
2293
|
-
*/
|
|
2294
|
-
pushGraphicsState(): void;
|
|
2295
|
-
/**
|
|
2296
|
-
* Pop the most recently saved graphics state (`Q`).
|
|
2297
|
-
*/
|
|
2298
|
-
popGraphicsState(): void;
|
|
2299
|
-
/**
|
|
2300
|
-
* Concatenate an arbitrary transformation matrix with the CTM (`cm`).
|
|
2301
|
-
*
|
|
2302
|
-
* @param a Horizontal scaling / rotation.
|
|
2303
|
-
* @param b Rotation / skew.
|
|
2304
|
-
* @param c Rotation / skew.
|
|
2305
|
-
* @param d Vertical scaling / rotation.
|
|
2306
|
-
* @param tx Horizontal translation.
|
|
2307
|
-
* @param ty Vertical translation.
|
|
2308
|
-
*/
|
|
2309
|
-
setTransform(a: number, b: number, c: number, d: number, tx: number, ty: number): void;
|
|
2310
|
-
/**
|
|
2311
|
-
* Append raw PDF operator string(s) to the content stream.
|
|
2312
|
-
*
|
|
2313
|
-
* Use with caution — no validation is performed.
|
|
2314
|
-
*/
|
|
2315
|
-
pushOperators(operators: string): void;
|
|
2316
|
-
/**
|
|
2317
|
-
* Get the current page rotation in degrees.
|
|
2318
|
-
* @returns The rotation angle (0, 90, 180, or 270).
|
|
2319
|
-
*/
|
|
2320
|
-
getRotation(): number;
|
|
2321
|
-
/**
|
|
2322
|
-
* Set the page rotation in degrees.
|
|
2323
|
-
*
|
|
2324
|
-
* @param angle Must be 0, 90, 180, or 270.
|
|
2325
|
-
* @internal
|
|
2326
|
-
*/
|
|
2327
|
-
setRotation(angle: number): void;
|
|
2328
|
-
/** Get the page width in points. Alias for the `width` getter. */
|
|
2329
|
-
getWidth(): number;
|
|
2330
|
-
/** Get the page height in points. Alias for the `height` getter. */
|
|
2331
|
-
getHeight(): number;
|
|
2332
|
-
/** Set the page width in points. */
|
|
2333
|
-
setWidth(w: number): void;
|
|
2334
|
-
/** Set the page height in points. */
|
|
2335
|
-
setHeight(h: number): void;
|
|
2336
|
-
/** Set both page width and height in points. */
|
|
2337
|
-
setSize(w: number, h: number): void;
|
|
2338
|
-
/** Get the page width and height as an object. */
|
|
2339
|
-
getSize(): {
|
|
2340
|
-
width: number;
|
|
2341
|
-
height: number;
|
|
2342
|
-
};
|
|
2343
|
-
/** Reset page dimensions to their original values from creation time. */
|
|
2344
|
-
resetSize(): void;
|
|
2345
|
-
/** Translate all page content by (x, y) points. Prepends a cm operator. */
|
|
2346
|
-
translateContent(x: number, y: number): void;
|
|
2347
|
-
/** Scale page content by the given factors. Prepends a cm operator. */
|
|
2348
|
-
scaleContent(xFactor: number, yFactor: number): void;
|
|
2349
|
-
/** Scale annotation rectangles by the given factors. */
|
|
2350
|
-
scaleAnnotations(xFactor: number, yFactor: number): void;
|
|
2351
|
-
/** Scale page dimensions, content, and annotations together. */
|
|
2352
|
-
scale(xFactor: number, yFactor: number): void;
|
|
2353
|
-
/** Get the media box for this page. */
|
|
2354
|
-
getMediaBox(): {
|
|
2355
|
-
x: number;
|
|
2356
|
-
y: number;
|
|
2357
|
-
width: number;
|
|
2358
|
-
height: number;
|
|
2359
|
-
};
|
|
2360
|
-
/** Set the media box (page dimensions) for this page. */
|
|
2361
|
-
setMediaBox(x: number, y: number, width: number, height: number): void;
|
|
2362
|
-
/** Get the crop box if set, or undefined. */
|
|
2363
|
-
getCropBox(): {
|
|
2364
|
-
x: number;
|
|
2365
|
-
y: number;
|
|
2366
|
-
width: number;
|
|
2367
|
-
height: number;
|
|
2368
|
-
} | undefined;
|
|
2369
|
-
/** Set the crop box for this page. */
|
|
2370
|
-
setCropBox(x: number, y: number, width: number, height: number): void;
|
|
2371
|
-
/** Get the bleed box if set, or undefined. */
|
|
2372
|
-
getBleedBox(): {
|
|
2373
|
-
x: number;
|
|
2374
|
-
y: number;
|
|
2375
|
-
width: number;
|
|
2376
|
-
height: number;
|
|
2377
|
-
} | undefined;
|
|
2378
|
-
/** Set the bleed box for this page. */
|
|
2379
|
-
setBleedBox(x: number, y: number, width: number, height: number): void;
|
|
2380
|
-
/** Get the trim box if set, or undefined. */
|
|
2381
|
-
getTrimBox(): {
|
|
2382
|
-
x: number;
|
|
2383
|
-
y: number;
|
|
2384
|
-
width: number;
|
|
2385
|
-
height: number;
|
|
2386
|
-
} | undefined;
|
|
2387
|
-
/** Set the trim box for this page. */
|
|
2388
|
-
setTrimBox(x: number, y: number, width: number, height: number): void;
|
|
2389
|
-
/** Get the art box if set, or undefined. */
|
|
2390
|
-
getArtBox(): {
|
|
2391
|
-
x: number;
|
|
2392
|
-
y: number;
|
|
2393
|
-
width: number;
|
|
2394
|
-
height: number;
|
|
2395
|
-
} | undefined;
|
|
2396
|
-
/** Set the art box for this page. */
|
|
2397
|
-
setArtBox(x: number, y: number, width: number, height: number): void;
|
|
2398
|
-
/**
|
|
2399
|
-
* Alt text entries for images, keyed by image resource name.
|
|
2400
|
-
* Used during structure tree serialization.
|
|
2401
|
-
* @internal
|
|
2402
|
-
*/
|
|
2403
|
-
private readonly imageAltTexts;
|
|
2404
|
-
/**
|
|
2405
|
-
* Wrap the current content-stream operators in a marked-content
|
|
2406
|
-
* sequence.
|
|
2407
|
-
*
|
|
2408
|
-
* This wraps ALL currently accumulated content in a BDC/EMC pair
|
|
2409
|
-
* with the given structure tag and marked-content ID (MCID). The
|
|
2410
|
-
* MCID links the content to a structure element in the document's
|
|
2411
|
-
* structure tree.
|
|
2412
|
-
*
|
|
2413
|
-
* Call this after adding content to the page and before adding
|
|
2414
|
-
* more content that belongs to a different structure element.
|
|
2415
|
-
*
|
|
2416
|
-
* @param tag The structure type tag (e.g. `"P"`, `"H1"`, `"Span"`).
|
|
2417
|
-
* @param mcid The marked-content ID assigned by the structure tree.
|
|
2418
|
-
*/
|
|
2419
|
-
markContent(tag: StructureType, mcid: number): void;
|
|
2420
|
-
/**
|
|
2421
|
-
* Begin a marked-content sequence in the content stream.
|
|
2422
|
-
*
|
|
2423
|
-
* Must be paired with a call to {@link endMarkedContentSequence}.
|
|
2424
|
-
* Content added between the two calls will be associated with the
|
|
2425
|
-
* given structure element.
|
|
2426
|
-
*
|
|
2427
|
-
* @param tag The structure type tag.
|
|
2428
|
-
* @param mcid The marked-content ID.
|
|
2429
|
-
*/
|
|
2430
|
-
beginMarkedContent(tag: StructureType, mcid: number): void;
|
|
2431
|
-
/**
|
|
2432
|
-
* End a marked-content sequence in the content stream.
|
|
2433
|
-
*
|
|
2434
|
-
* Must be preceded by a call to {@link beginMarkedContent}.
|
|
2435
|
-
*/
|
|
2436
|
-
endMarkedContentSequence(): void;
|
|
2437
|
-
/**
|
|
2438
|
-
* Associate alt text with an image reference on this page.
|
|
2439
|
-
*
|
|
2440
|
-
* The alt text is stored and used during structure tree serialization
|
|
2441
|
-
* to create a Figure structure element with the `/Alt` attribute.
|
|
2442
|
-
*
|
|
2443
|
-
* @param imageRef The image reference returned by `doc.embedPng()`
|
|
2444
|
-
* or `doc.embedJpeg()`.
|
|
2445
|
-
* @param altText The alternative text describing the image.
|
|
2446
|
-
*/
|
|
2447
|
-
addAltText(imageRef: ImageRef, altText: string): void;
|
|
2448
|
-
/**
|
|
2449
|
-
* Get the alt text for an image, if set.
|
|
2450
|
-
*
|
|
2451
|
-
* @param imageRef The image reference.
|
|
2452
|
-
* @returns The alt text, or `undefined`.
|
|
2453
|
-
*/
|
|
2454
|
-
getAltText(imageRef: ImageRef): string | undefined;
|
|
2455
|
-
/**
|
|
2456
|
-
* Annotations on this page.
|
|
2457
|
-
* @internal
|
|
2458
|
-
*/
|
|
2459
|
-
private readonly annotations;
|
|
2460
|
-
/** Raw widget annotation dicts added via addWidgetAnnotation. */
|
|
2461
|
-
private readonly widgetDicts;
|
|
2462
|
-
/**
|
|
2463
|
-
* Get all annotations on this page.
|
|
2464
|
-
*
|
|
2465
|
-
* @returns An array of PdfAnnotation instances.
|
|
2466
|
-
*/
|
|
2467
|
-
getAnnotations(): PdfAnnotation[];
|
|
2468
|
-
/**
|
|
2469
|
-
* Add an annotation to this page.
|
|
2470
|
-
*
|
|
2471
|
-
* @param type The annotation subtype.
|
|
2472
|
-
* @param options Annotation options (rect, contents, color, etc.).
|
|
2473
|
-
* @returns The created PdfAnnotation.
|
|
2474
|
-
*/
|
|
2475
|
-
addAnnotation(type: AnnotationType, options: AnnotationOptions): PdfAnnotation;
|
|
2476
|
-
/**
|
|
2477
|
-
* Add a pre-created annotation to this page.
|
|
2478
|
-
*
|
|
2479
|
-
* @param annotation The annotation to add.
|
|
2480
|
-
* @internal
|
|
2481
|
-
*/
|
|
2482
|
-
addExistingAnnotation(annotation: PdfAnnotation): void;
|
|
2483
|
-
/**
|
|
2484
|
-
* Remove an annotation from this page.
|
|
2485
|
-
*
|
|
2486
|
-
* @param annotation The annotation to remove.
|
|
2487
|
-
*/
|
|
2488
|
-
removeAnnotation(annotation: PdfAnnotation): void;
|
|
2489
|
-
/**
|
|
2490
|
-
* Add a raw widget annotation dictionary to this page.
|
|
2491
|
-
*
|
|
2492
|
-
* Used by form fields' `addToPage()` to register their widget
|
|
2493
|
-
* annotation without wrapping in a `PdfAnnotation` instance.
|
|
2494
|
-
*
|
|
2495
|
-
* @param widgetDict The widget annotation dictionary.
|
|
2496
|
-
*/
|
|
2497
|
-
addWidgetAnnotation(widgetDict: PdfDict): void;
|
|
2498
|
-
/**
|
|
2499
|
-
* Flatten all annotations into the page content stream.
|
|
2500
|
-
*
|
|
2501
|
-
* After flattening, annotations are rendered as part of the page
|
|
2502
|
-
* content and are no longer interactive. The annotations are
|
|
2503
|
-
* removed from the page's annotation list.
|
|
2504
|
-
*/
|
|
2505
|
-
flattenAnnotations(): void;
|
|
2506
|
-
/**
|
|
2507
|
-
* @internal Get annotation refs for the page dictionary /Annots array.
|
|
2508
|
-
*/
|
|
2509
|
-
getAnnotationRefs(registry: PdfObjectRegistry): PdfRef[];
|
|
2510
|
-
/**
|
|
2511
|
-
* Draw an SVG image onto this page.
|
|
2512
|
-
*
|
|
2513
|
-
* @param svgString The SVG markup string.
|
|
2514
|
-
* @param options Rendering options (position, size).
|
|
2515
|
-
*/
|
|
2516
|
-
drawSvg(svgString: string, options?: SvgRenderOptions): void;
|
|
2517
|
-
/**
|
|
2518
|
-
* Draw an SVG path data string onto this page.
|
|
2519
|
-
*
|
|
2520
|
-
* The `pathData` parameter uses the same syntax as the SVG `<path d="...">`
|
|
2521
|
-
* attribute (M, L, C, Q, H, V, S, T, A, Z commands).
|
|
2522
|
-
*
|
|
2523
|
-
* **Important:** SVG path coordinates use a top-down Y axis. This
|
|
2524
|
-
* method applies a Y-axis flip so that the path renders correctly in
|
|
2525
|
-
* PDF's bottom-up coordinate system. The `x` / `y` options position
|
|
2526
|
-
* the origin of the path in PDF space.
|
|
2527
|
-
*
|
|
2528
|
-
* @param pathData SVG path data string (e.g. `"M 0 0 L 100 0 L 100 100 Z"`).
|
|
2529
|
-
* @param options Drawing options (position, scale, colours).
|
|
2530
|
-
*/
|
|
2531
|
-
drawSvgPath(pathData: string, options?: DrawSvgPathOptions): void;
|
|
2532
|
-
/**
|
|
2533
|
-
* Draw a QR code at the specified position.
|
|
2534
|
-
*
|
|
2535
|
-
* The QR code is rendered as native PDF vector graphics (filled
|
|
2536
|
-
* rectangles for each dark module), producing resolution-independent
|
|
2537
|
-
* output.
|
|
2538
|
-
*
|
|
2539
|
-
* @param data The string to encode in the QR code.
|
|
2540
|
-
* @param options Position, error correction level, colours, module size.
|
|
2541
|
-
*/
|
|
2542
|
-
drawQrCode(data: string, options?: DrawQrCodeOptions): void;
|
|
2543
|
-
/**
|
|
2544
|
-
* Draw a table on this page.
|
|
2545
|
-
*
|
|
2546
|
-
* The table is rendered as native PDF vector graphics (rectangles,
|
|
2547
|
-
* borders, and text operators). The top-left corner of the table is
|
|
2548
|
-
* at `(options.x, options.y)` and rows extend downward.
|
|
2549
|
-
*
|
|
2550
|
-
* @param options Table configuration: position, size, rows, columns,
|
|
2551
|
-
* fonts, colours, borders, and padding.
|
|
2552
|
-
* @returns A {@link TableRenderResult} with the computed
|
|
2553
|
-
* dimensions and layout metrics.
|
|
2554
|
-
*
|
|
2555
|
-
* @example
|
|
2556
|
-
* ```ts
|
|
2557
|
-
* const result = page.drawTable({
|
|
2558
|
-
* x: 50,
|
|
2559
|
-
* y: 700,
|
|
2560
|
-
* width: 500,
|
|
2561
|
-
* rows: [
|
|
2562
|
-
* { cells: ['Name', 'Age', 'City'] },
|
|
2563
|
-
* { cells: ['Alice', '30', 'London'] },
|
|
2564
|
-
* { cells: ['Bob', '25', 'Paris'] },
|
|
2565
|
-
* ],
|
|
2566
|
-
* });
|
|
2567
|
-
* ```
|
|
2568
|
-
*/
|
|
2569
|
-
drawTable(options: DrawTableOptions): TableRenderResult;
|
|
2570
|
-
/**
|
|
2571
|
-
* Draw a gradient fill (linear or radial) clipped to a rectangle.
|
|
2572
|
-
*
|
|
2573
|
-
* The gradient is registered as a `/Pattern` resource on this page
|
|
2574
|
-
* and painted within the specified rectangular region.
|
|
2575
|
-
*
|
|
2576
|
-
* @param gradient A gradient descriptor from {@link linearGradient}
|
|
2577
|
-
* or {@link radialGradient}.
|
|
2578
|
-
* @param rect The rectangle to fill.
|
|
2579
|
-
*/
|
|
2580
|
-
drawGradient(gradient: GradientFill, rect: {
|
|
2581
|
-
x: number;
|
|
2582
|
-
y: number;
|
|
2583
|
-
width: number;
|
|
2584
|
-
height: number;
|
|
2585
|
-
}): void;
|
|
2586
|
-
/**
|
|
2587
|
-
* Draw a tiling pattern fill clipped to a rectangle.
|
|
2588
|
-
*
|
|
2589
|
-
* The pattern is registered as a `/Pattern` resource on this page
|
|
2590
|
-
* and painted within the specified rectangular region.
|
|
2591
|
-
*
|
|
2592
|
-
* @param pattern A pattern descriptor from {@link tilingPattern}.
|
|
2593
|
-
* @param rect The rectangle to fill.
|
|
2594
|
-
*/
|
|
2595
|
-
drawPattern(pattern: PatternFill, rect: {
|
|
2596
|
-
x: number;
|
|
2597
|
-
y: number;
|
|
2598
|
-
width: number;
|
|
2599
|
-
height: number;
|
|
2600
|
-
}): void;
|
|
2601
|
-
/**
|
|
2602
|
-
* Begin layer-specific content.
|
|
2603
|
-
*
|
|
2604
|
-
* Content drawn after this call and before {@link endLayer} will be
|
|
2605
|
-
* associated with the given layer and can be shown/hidden by the
|
|
2606
|
-
* viewer.
|
|
2607
|
-
*
|
|
2608
|
-
* @param layer The layer to begin.
|
|
2609
|
-
*/
|
|
2610
|
-
beginLayer(layer: PdfLayer): void;
|
|
2611
|
-
/**
|
|
2612
|
-
* End layer-specific content.
|
|
2613
|
-
*
|
|
2614
|
-
* Must be preceded by a call to {@link beginLayer}.
|
|
2615
|
-
*/
|
|
2616
|
-
endLayer(): void;
|
|
2617
|
-
/**
|
|
2618
|
-
* Begin a transparency group. All drawing operations until
|
|
2619
|
-
* {@link endTransparencyGroup} will be captured and composited as a
|
|
2620
|
-
* single Form XObject with a `/Group` transparency dictionary.
|
|
2621
|
-
*
|
|
2622
|
-
* Transparency groups enable isolated and knockout compositing effects
|
|
2623
|
-
* that are not possible with simple opacity settings.
|
|
2624
|
-
*
|
|
2625
|
-
* Groups can be nested — each call must be paired with a matching
|
|
2626
|
-
* {@link endTransparencyGroup}.
|
|
2627
|
-
*
|
|
2628
|
-
* @param options Isolation, knockout, and color-space settings.
|
|
2629
|
-
*
|
|
2630
|
-
* @example
|
|
2631
|
-
* ```ts
|
|
2632
|
-
* page.beginTransparencyGroup({ isolated: true });
|
|
2633
|
-
* page.drawRectangle({ x: 50, y: 50, width: 100, height: 100, opacity: 0.5 });
|
|
2634
|
-
* page.drawCircle({ x: 100, y: 100, size: 60, opacity: 0.5 });
|
|
2635
|
-
* page.endTransparencyGroup();
|
|
2636
|
-
* ```
|
|
2637
|
-
*/
|
|
2638
|
-
beginTransparencyGroup(options?: TransparencyGroupOptions): void;
|
|
2639
|
-
/**
|
|
2640
|
-
* End the current transparency group and composite it onto the page
|
|
2641
|
-
* as a Form XObject.
|
|
2642
|
-
*
|
|
2643
|
-
* @throws {Error} If there is no matching {@link beginTransparencyGroup}.
|
|
2644
|
-
*/
|
|
2645
|
-
endTransparencyGroup(): void;
|
|
2646
|
-
/**
|
|
2647
|
-
* Apply a soft mask (luminosity-based) for subsequent drawing operations.
|
|
2648
|
-
*
|
|
2649
|
-
* White regions in the mask are fully opaque; black regions are fully
|
|
2650
|
-
* transparent. The mask stays active until {@link clearSoftMask} is
|
|
2651
|
-
* called or the graphics state is restored.
|
|
2652
|
-
*
|
|
2653
|
-
* @param mask A soft mask reference created by
|
|
2654
|
-
* {@link PdfDocument.createSoftMask}.
|
|
2655
|
-
*
|
|
2656
|
-
* @example
|
|
2657
|
-
* ```ts
|
|
2658
|
-
* const mask = doc.createSoftMask(200, 200, (b) => {
|
|
2659
|
-
* b.drawRectangle(0, 0, 200, 200, 1); // white = opaque
|
|
2660
|
-
* b.drawCircle(100, 100, 80, 0); // black = transparent
|
|
2661
|
-
* });
|
|
2662
|
-
* page.applySoftMask(mask);
|
|
2663
|
-
* page.drawImage(image, { x: 50, y: 50, width: 200, height: 200 });
|
|
2664
|
-
* page.clearSoftMask();
|
|
2665
|
-
* ```
|
|
2666
|
-
*/
|
|
2667
|
-
applySoftMask(mask: SoftMaskRef): void;
|
|
2668
|
-
/**
|
|
2669
|
-
* Clear the current soft mask, resetting to no masking.
|
|
2670
|
-
*
|
|
2671
|
-
* This emits an ExtGState with `/SMask /None`, which removes any
|
|
2672
|
-
* previously applied soft mask for subsequent drawing operations.
|
|
2673
|
-
*/
|
|
2674
|
-
clearSoftMask(): void;
|
|
2675
|
-
/**
|
|
2676
|
-
* Mark a rectangular region on this page for redaction.
|
|
2677
|
-
*
|
|
2678
|
-
* The mark is stored but not applied until `doc.applyRedactions()`
|
|
2679
|
-
* is called.
|
|
2680
|
-
*
|
|
2681
|
-
* @param rect The region to redact: [x, y, width, height].
|
|
2682
|
-
* @param options Additional redaction options (overlay text, colour).
|
|
2683
|
-
*/
|
|
2684
|
-
markForRedaction(rect: [number, number, number, number], options?: Partial<RedactionOptions>): void;
|
|
2685
|
-
/** @internal Return the accumulated operator string. */
|
|
2686
|
-
getContentStreamData(): string;
|
|
2687
|
-
/** @internal Return the original content-stream refs from a loaded PDF. */
|
|
2688
|
-
getOriginalContentRefs(): readonly PdfRef[];
|
|
2689
|
-
/** @internal Return the original resources dict from a loaded PDF. */
|
|
2690
|
-
getOriginalResources(): PdfDict | undefined;
|
|
2691
|
-
/** @internal Return the object registry for this page. */
|
|
2692
|
-
getRegistry(): PdfObjectRegistry;
|
|
2693
|
-
/**
|
|
2694
|
-
* @internal Build the `/Resources` dictionary for this page.
|
|
2695
|
-
*/
|
|
2696
|
-
buildResources(): PdfDict;
|
|
2697
|
-
/**
|
|
2698
|
-
* @internal Merge original resources from a loaded PDF with any newly
|
|
2699
|
-
* added resources (fonts, images, graphics states).
|
|
2700
|
-
*
|
|
2701
|
-
* The original resources dict is used as the base. New entries are
|
|
2702
|
-
* added into the appropriate sub-dictionaries (e.g. /Font, /XObject).
|
|
2703
|
-
*/
|
|
2704
|
-
private _mergeResources;
|
|
2705
|
-
/**
|
|
2706
|
-
* @internal Finalize this page: create the content stream object and
|
|
2707
|
-
* register it in the object registry. Returns a {@link PageEntry}
|
|
2708
|
-
* compatible with {@link buildPageTree}.
|
|
2709
|
-
*/
|
|
2710
|
-
finalize(): {
|
|
2711
|
-
pageRef: PdfRef;
|
|
2712
|
-
mediaBox: readonly [number, number, number, number];
|
|
2713
|
-
width: number;
|
|
2714
|
-
height: number;
|
|
2715
|
-
contentStreamRefs: PdfRef | readonly PdfRef[];
|
|
2716
|
-
resources: PdfDict;
|
|
2717
|
-
rotation?: number | undefined;
|
|
2718
|
-
cropBox?: readonly [number, number, number, number] | undefined;
|
|
2719
|
-
bleedBox?: readonly [number, number, number, number] | undefined;
|
|
2720
|
-
artBox?: readonly [number, number, number, number] | undefined;
|
|
2721
|
-
trimBox?: readonly [number, number, number, number] | undefined;
|
|
2722
|
-
annotationRefs?: PdfRef[] | undefined;
|
|
2723
|
-
};
|
|
2724
|
-
}
|
|
2725
|
-
//#endregion
|
|
2726
|
-
//#region src/core/pdfCatalog.d.ts
|
|
2727
|
-
/**
|
|
2728
|
-
* Format a `Date` as a PDF date string.
|
|
2729
|
-
*
|
|
2730
|
-
* PDF dates follow the form: `D:YYYYMMDDHHmmSSOHH'mm`
|
|
2731
|
-
*
|
|
2732
|
-
* - `O` is the relationship to UT: `+`, `-`, or `Z`.
|
|
2733
|
-
* - The trailing `HH'mm` is the UT offset.
|
|
2734
|
-
*
|
|
2735
|
-
* @param date A JavaScript Date object.
|
|
2736
|
-
* @returns A PDF date string wrapped in parentheses.
|
|
2737
|
-
*/
|
|
2738
|
-
declare function formatPdfDate(date: Date): string;
|
|
2739
|
-
/** Metadata fields for the /Info dictionary. */
|
|
2740
|
-
interface DocumentMetadata {
|
|
2741
|
-
title?: string | undefined;
|
|
2742
|
-
author?: string | undefined;
|
|
2743
|
-
subject?: string | undefined;
|
|
2744
|
-
keywords?: string | undefined;
|
|
2745
|
-
creator?: string | undefined;
|
|
2746
|
-
producer?: string | undefined;
|
|
2747
|
-
creationDate?: Date | undefined;
|
|
2748
|
-
modDate?: Date | undefined;
|
|
2749
|
-
}
|
|
2750
|
-
/**
|
|
2751
|
-
* Build the `/Info` dictionary from metadata.
|
|
2752
|
-
*
|
|
2753
|
-
* @param meta Document metadata.
|
|
2754
|
-
* @param registry Object registry — the info dict is registered as an
|
|
2755
|
-
* indirect object.
|
|
2756
|
-
* @returns The indirect reference to the `/Info` dict.
|
|
2757
|
-
*/
|
|
2758
|
-
declare function buildInfoDict(meta: DocumentMetadata, registry: PdfObjectRegistry): PdfRef;
|
|
2759
|
-
/**
|
|
2760
|
-
* Represents a single page's key refs for building the page tree.
|
|
2761
|
-
*/
|
|
2762
|
-
interface PageEntry {
|
|
2763
|
-
/** Indirect reference for this page object. */
|
|
2764
|
-
readonly pageRef: PdfRef;
|
|
2765
|
-
/** Full media box `[llx, lly, urx, ury]`. */
|
|
2766
|
-
readonly mediaBox?: readonly [number, number, number, number] | undefined;
|
|
2767
|
-
/** Width of the page (points). */
|
|
2768
|
-
readonly width: number;
|
|
2769
|
-
/** Height of the page (points). */
|
|
2770
|
-
readonly height: number;
|
|
2771
|
-
/**
|
|
2772
|
-
* Content stream reference(s).
|
|
2773
|
-
*
|
|
2774
|
-
* A single PdfRef for newly created pages, or an array for loaded pages
|
|
2775
|
-
* that may have multiple content streams (or original + appended).
|
|
2776
|
-
*/
|
|
2777
|
-
readonly contentStreamRefs: PdfRef | readonly PdfRef[];
|
|
2778
|
-
/** Resources dictionary (fonts, images, etc.). */
|
|
2779
|
-
readonly resources: PdfDict;
|
|
2780
|
-
/** Optional rotation in degrees (0, 90, 180, 270). */
|
|
2781
|
-
readonly rotation?: number | undefined;
|
|
2782
|
-
/** Optional crop box `[llx, lly, urx, ury]`. */
|
|
2783
|
-
readonly cropBox?: readonly [number, number, number, number] | undefined;
|
|
2784
|
-
/** Optional bleed box `[llx, lly, urx, ury]`. */
|
|
2785
|
-
readonly bleedBox?: readonly [number, number, number, number] | undefined;
|
|
2786
|
-
/** Optional art box `[llx, lly, urx, ury]`. */
|
|
2787
|
-
readonly artBox?: readonly [number, number, number, number] | undefined;
|
|
2788
|
-
/** Optional trim box `[llx, lly, urx, ury]`. */
|
|
2789
|
-
readonly trimBox?: readonly [number, number, number, number] | undefined;
|
|
2790
|
-
/** Optional annotation indirect references. */
|
|
2791
|
-
readonly annotationRefs?: readonly PdfRef[] | undefined;
|
|
2792
|
-
}
|
|
2793
|
-
/**
|
|
2794
|
-
* Build the `/Pages` tree and individual `/Page` dictionaries.
|
|
2795
|
-
*
|
|
2796
|
-
* This implementation uses a flat page tree (a single `/Pages` node)
|
|
2797
|
-
* which is correct for documents with up to several thousand pages.
|
|
2798
|
-
*
|
|
2799
|
-
* @param pages Ordered list of page entries.
|
|
2800
|
-
* @param registry Object registry.
|
|
2801
|
-
* @returns The indirect reference to the root `/Pages` node.
|
|
2802
|
-
*/
|
|
2803
|
-
declare function buildPageTree(pages: readonly PageEntry[], registry: PdfObjectRegistry): PdfRef;
|
|
2804
|
-
/** Options for building the catalog. */
|
|
2805
|
-
interface CatalogOptions {
|
|
2806
|
-
/** Page layout hint. */
|
|
2807
|
-
pageLayout?: 'SinglePage' | 'OneColumn' | 'TwoColumnLeft' | 'TwoColumnRight' | 'TwoPageLeft' | 'TwoPageRight' | undefined;
|
|
2808
|
-
/** Page mode hint. */
|
|
2809
|
-
pageMode?: 'UseNone' | 'UseOutlines' | 'UseThumbs' | 'FullScreen' | 'UseOC' | 'UseAttachments' | undefined;
|
|
2810
|
-
/** The natural language of the document content (e.g. `en-US`). */
|
|
2811
|
-
lang?: string | undefined;
|
|
2812
|
-
}
|
|
2813
|
-
/**
|
|
2814
|
-
* Build the `/Catalog` dictionary.
|
|
2815
|
-
*
|
|
2816
|
-
* @param pagesRef Indirect reference to the root `/Pages` node.
|
|
2817
|
-
* @param registry Object registry.
|
|
2818
|
-
* @param options Optional catalog-level settings.
|
|
2819
|
-
* @returns The indirect reference to the `/Catalog` dict.
|
|
2820
|
-
*/
|
|
2821
|
-
declare function buildCatalog(pagesRef: PdfRef, registry: PdfObjectRegistry, options?: CatalogOptions): PdfRef;
|
|
2822
|
-
/**
|
|
2823
|
-
* High-level helper that wires together the catalog, page tree, and info
|
|
2824
|
-
* dict, returning all the references the writer needs.
|
|
2825
|
-
*/
|
|
2826
|
-
interface DocumentStructure {
|
|
2827
|
-
/** Reference to the /Catalog. */
|
|
2828
|
-
catalogRef: PdfRef;
|
|
2829
|
-
/** Reference to the /Info dict. */
|
|
2830
|
-
infoRef: PdfRef;
|
|
2831
|
-
/** Reference to the /Pages node. */
|
|
2832
|
-
pagesRef: PdfRef;
|
|
2833
|
-
}
|
|
2834
|
-
/**
|
|
2835
|
-
* Build the complete document structure.
|
|
2836
|
-
*
|
|
2837
|
-
* @param pages Page entries (already have refs allocated).
|
|
2838
|
-
* @param meta Document metadata.
|
|
2839
|
-
* @param registry Object registry.
|
|
2840
|
-
* @param options Optional catalog settings.
|
|
2841
|
-
*/
|
|
2842
|
-
declare function buildDocumentStructure(pages: readonly PageEntry[], meta: DocumentMetadata, registry: PdfObjectRegistry, options?: CatalogOptions): DocumentStructure;
|
|
2843
|
-
//#endregion
|
|
2844
|
-
//#region src/core/pdfWriter.d.ts
|
|
2845
|
-
/** Options that control how the PDF is written. */
|
|
2846
|
-
interface PdfSaveOptions {
|
|
2847
|
-
/** Apply FlateDecode compression to streams. Default: `true`. */
|
|
2848
|
-
compress?: boolean | undefined;
|
|
2849
|
-
/**
|
|
2850
|
-
* Compression level for FlateDecode (1–9). Default: `6`.
|
|
2851
|
-
* Ignored when `compress` is `false`.
|
|
2852
|
-
*/
|
|
2853
|
-
compressionLevel?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | undefined;
|
|
2854
|
-
/**
|
|
2855
|
-
* When `true`, attempt to use WASM-accelerated compression if the
|
|
2856
|
-
* WASM module has been initialized. Default: `false`.
|
|
2857
|
-
*/
|
|
2858
|
-
useWasm?: boolean | undefined;
|
|
2859
|
-
/**
|
|
2860
|
-
* Minimum number of non-stream indirect objects before object streams
|
|
2861
|
-
* are used. When the count exceeds this threshold, objects are packed
|
|
2862
|
-
* into compressed object streams and a cross-reference stream replaces
|
|
2863
|
-
* the traditional xref table.
|
|
2864
|
-
*
|
|
2865
|
-
* Set to `Infinity` to disable object streams (traditional xref).
|
|
2866
|
-
* A useful value for size reduction is `100`.
|
|
2867
|
-
*
|
|
2868
|
-
* Default: `Infinity` (disabled for backward compatibility).
|
|
2869
|
-
*/
|
|
2870
|
-
objectStreamThreshold?: number | undefined;
|
|
2871
|
-
/** Add a blank page if the document has no pages. Default: `true`. */
|
|
2872
|
-
addDefaultPage?: boolean | undefined;
|
|
2873
|
-
/** Regenerate form field appearances before saving. Default: `true`. */
|
|
2874
|
-
updateFieldAppearances?: boolean | undefined;
|
|
2875
|
-
}
|
|
2876
|
-
/**
|
|
2877
|
-
* Serialize a PDF document to a `Uint8Array`.
|
|
2878
|
-
*
|
|
2879
|
-
* ```ts
|
|
2880
|
-
* const writer = new PdfWriter(registry, structure, options);
|
|
2881
|
-
* const bytes = writer.write();
|
|
2882
|
-
* ```
|
|
2883
|
-
*/
|
|
2884
|
-
declare class PdfWriter {
|
|
2885
|
-
/** All indirect objects. */
|
|
2886
|
-
private readonly registry;
|
|
2887
|
-
/** Document structure references. */
|
|
2888
|
-
private readonly structure;
|
|
2889
|
-
private readonly buf;
|
|
2890
|
-
private readonly xrefOffsets;
|
|
2891
|
-
private readonly compress;
|
|
2892
|
-
private readonly compressionLevel;
|
|
2893
|
-
private readonly useWasm;
|
|
2894
|
-
private readonly objectStreamThreshold;
|
|
2895
|
-
constructor(/** All indirect objects. */
|
|
2896
|
-
|
|
2897
|
-
registry: PdfObjectRegistry, /** Document structure references. */
|
|
2898
|
-
|
|
2899
|
-
structure: DocumentStructure, options?: PdfSaveOptions);
|
|
2900
|
-
/**
|
|
2901
|
-
* Produce the complete PDF file as a `Uint8Array`.
|
|
2902
|
-
*/
|
|
2903
|
-
write(): Uint8Array;
|
|
2904
|
-
private writeHeader;
|
|
2905
|
-
private writeBody;
|
|
2906
|
-
private writeIndirectObject;
|
|
2907
|
-
/**
|
|
2908
|
-
* Apply FlateDecode compression to a stream's data if it is not
|
|
2909
|
-
* already compressed.
|
|
2910
|
-
*/
|
|
2911
|
-
private compressStream;
|
|
2912
|
-
/**
|
|
2913
|
-
* Set of object numbers that must NOT be placed inside an object
|
|
2914
|
-
* stream. This includes the catalog, info dict, pages root, and
|
|
2915
|
-
* any stream objects (which by definition cannot nest in an ObjStm).
|
|
2916
|
-
*/
|
|
2917
|
-
private protectedObjectNumbers;
|
|
2918
|
-
/**
|
|
2919
|
-
* Write the document body using object streams when the number of
|
|
2920
|
-
* eligible non-stream objects exceeds `threshold`.
|
|
2921
|
-
*
|
|
2922
|
-
* @returns `true` if object streams (and a cross-reference stream)
|
|
2923
|
-
* were used and the PDF is complete. `false` if the
|
|
2924
|
-
* threshold was not met — in that case the body has been
|
|
2925
|
-
* written in traditional format and the caller must still
|
|
2926
|
-
* emit the classic xref table and trailer.
|
|
2927
|
-
*/
|
|
2928
|
-
writeBodyWithObjectStreams(threshold: number): boolean;
|
|
2929
|
-
/**
|
|
2930
|
-
* Serialize a group of non-stream objects into a single object stream
|
|
2931
|
-
* (`/Type /ObjStm`) and record xref entries for them.
|
|
2932
|
-
*/
|
|
2933
|
-
private writeObjectStream;
|
|
2934
|
-
/**
|
|
2935
|
-
* Write a cross-reference stream (PDF 1.5+) that replaces the
|
|
2936
|
-
* traditional xref table and trailer.
|
|
2937
|
-
*/
|
|
2938
|
-
private writeXrefStream;
|
|
2939
|
-
private writeXref;
|
|
2940
|
-
private writeTrailer;
|
|
2941
|
-
}
|
|
2942
|
-
/**
|
|
2943
|
-
* Serialize a complete PDF from a registry and structure refs.
|
|
2944
|
-
*
|
|
2945
|
-
* @param registry All registered indirect objects.
|
|
2946
|
-
* @param structure Catalog / Info / Pages references.
|
|
2947
|
-
* @param options Save options.
|
|
2948
|
-
* @returns The raw PDF bytes.
|
|
2949
|
-
*/
|
|
2950
|
-
declare function serializePdf(registry: PdfObjectRegistry, structure: DocumentStructure, options?: PdfSaveOptions): Uint8Array;
|
|
2951
|
-
//#endregion
|
|
2952
|
-
//#region src/parser/documentParser.d.ts
|
|
2953
|
-
/**
|
|
2954
|
-
* Options for loading a PDF document from bytes.
|
|
2955
|
-
*/
|
|
2956
|
-
interface LoadPdfOptions {
|
|
2957
|
-
/** Password for encrypted PDFs (Phase 5). */
|
|
2958
|
-
password?: string;
|
|
2959
|
-
/** When true, skip decryption even if the PDF is encrypted. */
|
|
2960
|
-
ignoreEncryption?: boolean;
|
|
2961
|
-
/**
|
|
2962
|
-
* When true, update the /ModDate in the /Info dictionary to the
|
|
2963
|
-
* current time when saving. Defaults to true.
|
|
2964
|
-
*/
|
|
2965
|
-
updateMetadata?: boolean;
|
|
2966
|
-
/**
|
|
2967
|
-
* Number of objects to process per event-loop tick during parsing.
|
|
2968
|
-
* Lower values keep the main thread more responsive in browsers.
|
|
2969
|
-
* Defaults to `Infinity` (no throttling).
|
|
2970
|
-
*/
|
|
2971
|
-
objectsPerTick?: number;
|
|
2972
|
-
/**
|
|
2973
|
-
* When `true`, throw an error if a malformed or invalid PDF object
|
|
2974
|
-
* is encountered during parsing. When `false` (default), malformed
|
|
2975
|
-
* objects are silently skipped.
|
|
2976
|
-
*/
|
|
2977
|
-
throwOnInvalidObject?: boolean | undefined;
|
|
2978
|
-
/**
|
|
2979
|
-
* When `true`, clamp extreme floating-point values (very large or
|
|
2980
|
-
* very small numbers) to safe ranges during parsing. This prevents
|
|
2981
|
-
* numeric overflows from producing garbage output.
|
|
2982
|
-
*
|
|
2983
|
-
* Default: `false`.
|
|
2984
|
-
*/
|
|
2985
|
-
capNumbers?: boolean | undefined;
|
|
2986
|
-
}
|
|
2987
|
-
/**
|
|
2988
|
-
* Load a PDF document from raw bytes, an ArrayBuffer, or a Base64-encoded
|
|
2989
|
-
* string.
|
|
2990
|
-
*
|
|
2991
|
-
* This is the primary entry point for parsing existing PDFs. It creates
|
|
2992
|
-
* a `PdfDocumentParser`, runs the full parse pipeline, and returns
|
|
2993
|
-
* a populated {@link PdfDocument}.
|
|
2994
|
-
*
|
|
2995
|
-
* @param data The PDF data as a `Uint8Array`, `ArrayBuffer`, or a
|
|
2996
|
-
* Base64-encoded string.
|
|
2997
|
-
* @param options Optional loading options.
|
|
2998
|
-
* @returns A fully parsed PdfDocument.
|
|
2999
|
-
*
|
|
3000
|
-
* @example
|
|
3001
|
-
* ```ts
|
|
3002
|
-
* import { loadPdf } from 'modern-pdf-lib';
|
|
3003
|
-
*
|
|
3004
|
-
* // From fetch (ArrayBuffer)
|
|
3005
|
-
* const pdfBytes = await fetch('document.pdf').then(r => r.arrayBuffer());
|
|
3006
|
-
* const doc = await loadPdf(pdfBytes);
|
|
3007
|
-
*
|
|
3008
|
-
* // From a Base64 string
|
|
3009
|
-
* const doc2 = await loadPdf(base64String);
|
|
3010
|
-
* ```
|
|
3011
|
-
*/
|
|
3012
|
-
declare function loadPdf(data: Uint8Array | ArrayBuffer | string, options?: LoadPdfOptions): Promise<PdfDocument>;
|
|
3013
|
-
//#endregion
|
|
3014
|
-
//#region src/crypto/permissions.d.ts
|
|
3015
|
-
/**
|
|
3016
|
-
* @module crypto/permissions
|
|
3017
|
-
*
|
|
3018
|
-
* PDF document permission flags encoding and decoding.
|
|
3019
|
-
*
|
|
3020
|
-
* The /P entry in the encryption dictionary is a 32-bit signed integer
|
|
3021
|
-
* whose individual bits represent document access permissions. Bits
|
|
3022
|
-
* are numbered starting from 1 (least significant).
|
|
3023
|
-
*
|
|
3024
|
-
* Reference: PDF 1.7 spec, Table 22 (User access permissions).
|
|
3025
|
-
*
|
|
3026
|
-
* Bit layout (1-indexed):
|
|
3027
|
-
* - Bits 1-2: Reserved, must be 0
|
|
3028
|
-
* - Bit 3: Print the document
|
|
3029
|
-
* - Bit 4: Modify the contents of the document
|
|
3030
|
-
* - Bit 5: Copy or otherwise extract text and graphics
|
|
3031
|
-
* - Bit 6: Add or modify text annotations, fill in interactive form fields
|
|
3032
|
-
* - Bits 7-8: Reserved, must be 1
|
|
3033
|
-
* - Bit 9: Fill in existing interactive form fields (revision 3+)
|
|
3034
|
-
* - Bit 10: Extract text and graphics for accessibility (revision 3+)
|
|
3035
|
-
* - Bit 11: Assemble the document (revision 3+)
|
|
3036
|
-
* - Bit 12: Print in high fidelity (revision 3+)
|
|
3037
|
-
* - Bits 13-32: Reserved, must be 0
|
|
3038
|
-
*
|
|
3039
|
-
* When a bit is SET (1), the corresponding permission is GRANTED.
|
|
3040
|
-
* Bits 7-8 must always be 1. Bits 13-32 must always be 0.
|
|
3041
|
-
*/
|
|
3042
|
-
/**
|
|
3043
|
-
* Human-friendly permission flags for a PDF document.
|
|
3044
|
-
*
|
|
3045
|
-
* Each flag controls a specific capability:
|
|
3046
|
-
*
|
|
3047
|
-
* - `printing`: `true` = full quality, `'lowResolution'` = low-res only,
|
|
3048
|
-
* `false` / `undefined` = no printing allowed.
|
|
3049
|
-
* - `modifying`: Allow content modifications.
|
|
3050
|
-
* - `copying`: Allow text/graphics extraction.
|
|
3051
|
-
* - `annotating`: Allow adding/modifying annotations.
|
|
3052
|
-
* - `fillingForms`: Allow filling interactive form fields.
|
|
3053
|
-
* - `contentAccessibility`: Allow text extraction for accessibility.
|
|
3054
|
-
* - `documentAssembly`: Allow inserting/deleting/rotating pages.
|
|
3055
|
-
*/
|
|
3056
|
-
interface PdfPermissionFlags {
|
|
3057
|
-
printing?: boolean | 'lowResolution' | undefined;
|
|
3058
|
-
modifying?: boolean | undefined;
|
|
3059
|
-
copying?: boolean | undefined;
|
|
3060
|
-
annotating?: boolean | undefined;
|
|
3061
|
-
fillingForms?: boolean | undefined;
|
|
3062
|
-
contentAccessibility?: boolean | undefined;
|
|
3063
|
-
documentAssembly?: boolean | undefined;
|
|
3064
|
-
}
|
|
3065
|
-
/**
|
|
3066
|
-
* Encode human-friendly permission flags into the 32-bit /P integer
|
|
3067
|
-
* used in the PDF encryption dictionary.
|
|
3068
|
-
*
|
|
3069
|
-
* By default (when all flags are `undefined` or `false`), no
|
|
3070
|
-
* permissions are granted beyond the reserved bits.
|
|
3071
|
-
*
|
|
3072
|
-
* @param flags The permissions to encode.
|
|
3073
|
-
* @returns A 32-bit signed integer for the /P entry.
|
|
3074
|
-
*/
|
|
3075
|
-
declare function encodePermissions(flags: PdfPermissionFlags): number;
|
|
3076
|
-
/**
|
|
3077
|
-
* Decode the 32-bit /P integer from a PDF encryption dictionary into
|
|
3078
|
-
* human-friendly permission flags.
|
|
3079
|
-
*
|
|
3080
|
-
* @param value The /P integer from the encryption dictionary.
|
|
3081
|
-
* @returns The decoded permission flags.
|
|
3082
|
-
*/
|
|
3083
|
-
declare function decodePermissions(value: number): PdfPermissionFlags;
|
|
3084
|
-
//#endregion
|
|
3085
|
-
//#region src/crypto/encryptionHandler.d.ts
|
|
3086
|
-
/**
|
|
3087
|
-
* Algorithm selection for new encryption.
|
|
3088
|
-
*/
|
|
3089
|
-
type EncryptAlgorithm = 'rc4-40' | 'rc4-128' | 'aes-128' | 'aes-256';
|
|
3090
|
-
/**
|
|
3091
|
-
* Options for encrypting a PDF document.
|
|
3092
|
-
*/
|
|
3093
|
-
interface EncryptOptions {
|
|
3094
|
-
/** The user password (may be empty string for open access). */
|
|
3095
|
-
userPassword: string;
|
|
3096
|
-
/** The owner password (restricts editing). */
|
|
3097
|
-
ownerPassword: string;
|
|
3098
|
-
/** Permission flags. */
|
|
3099
|
-
permissions?: PdfPermissionFlags | undefined;
|
|
3100
|
-
/** Encryption algorithm. Default: `'aes-128'`. */
|
|
3101
|
-
algorithm?: EncryptAlgorithm | undefined;
|
|
3102
|
-
}
|
|
3103
|
-
/**
|
|
3104
|
-
* Handles encryption and decryption of PDF objects according to the
|
|
3105
|
-
* standard security handler.
|
|
3106
|
-
*
|
|
3107
|
-
* Create via:
|
|
3108
|
-
* - `PdfEncryptionHandler.create(options)` for new encryption
|
|
3109
|
-
* - `PdfEncryptionHandler.fromEncryptDict(dict, fileId, password)` for existing
|
|
3110
|
-
*/
|
|
3111
|
-
declare class PdfEncryptionHandler {
|
|
3112
|
-
/** The file-level encryption key. */
|
|
3113
|
-
private readonly fileKey;
|
|
3114
|
-
/** Algorithm version (/V). */
|
|
3115
|
-
private readonly version;
|
|
3116
|
-
/** Security handler revision (/R). */
|
|
3117
|
-
private readonly revision;
|
|
3118
|
-
/** Key length in bits. */
|
|
3119
|
-
private readonly keyLengthBits;
|
|
3120
|
-
/** Whether to use AES (true) or RC4 (false). */
|
|
3121
|
-
private readonly useAes;
|
|
3122
|
-
/** Whether to encrypt the /Metadata stream. */
|
|
3123
|
-
private readonly encryptMetadata;
|
|
3124
|
-
/** Permission flags as a 32-bit integer. */
|
|
3125
|
-
private readonly permissionsValue;
|
|
3126
|
-
/** Owner key (/O). */
|
|
3127
|
-
private readonly ownerKey;
|
|
3128
|
-
/** User key (/U). */
|
|
3129
|
-
private readonly userKey;
|
|
3130
|
-
/** Owner encryption key (/OE, V=5 only). */
|
|
3131
|
-
private readonly ownerEncryptionKey?;
|
|
3132
|
-
/** User encryption key (/UE, V=5 only). */
|
|
3133
|
-
private readonly userEncryptionKey?;
|
|
3134
|
-
/** Encrypted permissions (/Perms, V=5 only). */
|
|
3135
|
-
private readonly perms?;
|
|
3136
|
-
/** The file ID (first element of /ID array). */
|
|
3137
|
-
private readonly fileId;
|
|
3138
|
-
/**
|
|
3139
|
-
* Cache for per-object derived keys (V=1-4 only).
|
|
3140
|
-
* Key: `(objNum << 16) | genNum` — unique integer per object.
|
|
3141
|
-
* Value: the derived encryption key.
|
|
3142
|
-
*
|
|
3143
|
-
* Avoids recomputing MD5(fileKey + objNum + genNum [+ sAlT]) for
|
|
3144
|
-
* every string and stream in the same object.
|
|
3145
|
-
*/
|
|
3146
|
-
private readonly objectKeyCache;
|
|
3147
|
-
private constructor();
|
|
3148
|
-
/**
|
|
3149
|
-
* Create a new encryption handler for encrypting a document.
|
|
3150
|
-
*
|
|
3151
|
-
* Generates all necessary keys and values for the /Encrypt dictionary.
|
|
3152
|
-
*
|
|
3153
|
-
* @param options Encryption options.
|
|
3154
|
-
* @param fileId Optional file ID. If omitted, a random one is generated.
|
|
3155
|
-
* @returns A configured PdfEncryptionHandler.
|
|
3156
|
-
*/
|
|
3157
|
-
static create(options: EncryptOptions, fileId?: Uint8Array | undefined): Promise<PdfEncryptionHandler>;
|
|
3158
|
-
/**
|
|
3159
|
-
* Create an encryption handler from an existing /Encrypt dictionary.
|
|
3160
|
-
*
|
|
3161
|
-
* @param dict The /Encrypt dictionary from the PDF trailer.
|
|
3162
|
-
* @param fileId The first element of the /ID array.
|
|
3163
|
-
* @param password The password to try (user or owner).
|
|
3164
|
-
* @returns A configured PdfEncryptionHandler.
|
|
3165
|
-
* @throws If the password is incorrect or the dict is invalid.
|
|
3166
|
-
*/
|
|
3167
|
-
static fromEncryptDict(dict: PdfDict, fileId: Uint8Array, password: string): Promise<PdfEncryptionHandler>;
|
|
3168
|
-
/**
|
|
3169
|
-
* Derive the per-object encryption key for V=1-4.
|
|
3170
|
-
*
|
|
3171
|
-
* Per the spec: MD5(fileKey + objNum(3LE) + genNum(2LE) [+ "sAlT" for AES])
|
|
3172
|
-
* Truncated to min(keyLength/8 + 5, 16) bytes.
|
|
3173
|
-
*
|
|
3174
|
-
* @param objNum Object number.
|
|
3175
|
-
* @param genNum Generation number.
|
|
3176
|
-
* @returns The per-object key.
|
|
3177
|
-
*/
|
|
3178
|
-
private deriveObjectKey;
|
|
3179
|
-
/**
|
|
3180
|
-
* Encrypt raw data for a specific object.
|
|
3181
|
-
*
|
|
3182
|
-
* @param objNum Object number.
|
|
3183
|
-
* @param genNum Generation number.
|
|
3184
|
-
* @param data Plaintext data.
|
|
3185
|
-
* @returns Encrypted data.
|
|
3186
|
-
*/
|
|
3187
|
-
encryptObject(objNum: number, genNum: number, data: Uint8Array): Promise<Uint8Array>;
|
|
3188
|
-
/**
|
|
3189
|
-
* Decrypt raw data for a specific object.
|
|
3190
|
-
*
|
|
3191
|
-
* @param objNum Object number.
|
|
3192
|
-
* @param genNum Generation number.
|
|
3193
|
-
* @param data Encrypted data.
|
|
3194
|
-
* @returns Decrypted data.
|
|
3195
|
-
*/
|
|
3196
|
-
decryptObject(objNum: number, genNum: number, data: Uint8Array): Promise<Uint8Array>;
|
|
3197
|
-
/**
|
|
3198
|
-
* Encrypt a PdfString value.
|
|
3199
|
-
*
|
|
3200
|
-
* Converts the string value to bytes, encrypts, and returns a new
|
|
3201
|
-
* hex-encoded PdfString.
|
|
3202
|
-
*
|
|
3203
|
-
* @param objNum Object number.
|
|
3204
|
-
* @param genNum Generation number.
|
|
3205
|
-
* @param str The string to encrypt.
|
|
3206
|
-
* @returns An encrypted PdfString (hex-encoded).
|
|
3207
|
-
*/
|
|
3208
|
-
encryptString(objNum: number, genNum: number, str: PdfString): Promise<PdfString>;
|
|
3209
|
-
/**
|
|
3210
|
-
* Decrypt a stream's data.
|
|
3211
|
-
*
|
|
3212
|
-
* @param objNum Object number.
|
|
3213
|
-
* @param genNum Generation number.
|
|
3214
|
-
* @param streamData Encrypted stream bytes.
|
|
3215
|
-
* @returns Decrypted stream bytes.
|
|
3216
|
-
*/
|
|
3217
|
-
decryptStream(objNum: number, genNum: number, streamData: Uint8Array): Promise<Uint8Array>;
|
|
3218
|
-
/**
|
|
3219
|
-
* Build the /Encrypt dictionary for the PDF trailer.
|
|
3220
|
-
*
|
|
3221
|
-
* @returns A PdfDict suitable for use as the /Encrypt entry.
|
|
3222
|
-
*/
|
|
3223
|
-
buildEncryptDict(): PdfDict;
|
|
3224
|
-
/** Get the permission flags. */
|
|
3225
|
-
getPermissions(): PdfPermissionFlags;
|
|
3226
|
-
/** Get the raw permissions value. */
|
|
3227
|
-
getPermissionsValue(): number;
|
|
3228
|
-
/** Whether this handler uses AES (vs RC4). */
|
|
3229
|
-
isAes(): boolean;
|
|
3230
|
-
/** The algorithm version (/V). */
|
|
3231
|
-
getVersion(): number;
|
|
3232
|
-
/** The security handler revision (/R). */
|
|
3233
|
-
getRevision(): number;
|
|
3234
|
-
/** The file encryption key (for testing/debugging). */
|
|
3235
|
-
getFileKey(): Uint8Array;
|
|
3236
|
-
/** The file ID used for key derivation. */
|
|
3237
|
-
getFileId(): Uint8Array;
|
|
3238
|
-
/** Whether metadata streams are encrypted. */
|
|
3239
|
-
isMetadataEncrypted(): boolean;
|
|
3240
|
-
}
|
|
3241
|
-
//#endregion
|
|
3242
|
-
//#region src/outline/pdfOutline.d.ts
|
|
3243
|
-
/**
|
|
3244
|
-
* Describes where an outline item navigates to when clicked.
|
|
3245
|
-
*
|
|
3246
|
-
* - `type: 'page'` — navigate to a specific page by zero-based index.
|
|
3247
|
-
* - `type: 'named'` — use a named destination string.
|
|
3248
|
-
*/
|
|
3249
|
-
interface OutlineDestination {
|
|
3250
|
-
/** Whether to navigate by page index or named destination. */
|
|
3251
|
-
type: 'page' | 'named';
|
|
3252
|
-
/** Zero-based page index (used when `type` is `'page'`). */
|
|
3253
|
-
pageIndex?: number | undefined;
|
|
3254
|
-
/** Named destination string (used when `type` is `'named'`). */
|
|
3255
|
-
namedDestination?: string | undefined;
|
|
3256
|
-
/** Page fit mode — how the page should be displayed. */
|
|
3257
|
-
fit?: 'Fit' | 'FitH' | 'FitV' | 'FitB' | 'FitBH' | 'FitBV' | 'XYZ' | undefined;
|
|
3258
|
-
/** Top coordinate for FitH, FitBH, XYZ fit modes. */
|
|
3259
|
-
top?: number | undefined;
|
|
3260
|
-
/** Left coordinate for FitV, FitBV, XYZ fit modes. */
|
|
3261
|
-
left?: number | undefined;
|
|
3262
|
-
/** Zoom factor for XYZ fit mode (0 means keep current). */
|
|
3263
|
-
zoom?: number | undefined;
|
|
3264
|
-
}
|
|
3265
|
-
/** Options for creating an outline item. */
|
|
3266
|
-
interface OutlineItemOptions {
|
|
3267
|
-
/** Whether the item's children are initially visible. Default: `true`. */
|
|
3268
|
-
isOpen?: boolean | undefined;
|
|
3269
|
-
/** Colour of the outline text as RGB in range 0-1. */
|
|
3270
|
-
color?: {
|
|
3271
|
-
r: number;
|
|
3272
|
-
g: number;
|
|
3273
|
-
b: number;
|
|
3274
|
-
} | undefined;
|
|
3275
|
-
/** Whether the title text is bold. */
|
|
3276
|
-
bold?: boolean | undefined;
|
|
3277
|
-
/** Whether the title text is italic. */
|
|
3278
|
-
italic?: boolean | undefined;
|
|
3279
|
-
}
|
|
3280
|
-
/**
|
|
3281
|
-
* A single node in the outline tree. Each item has a title, a
|
|
3282
|
-
* destination, and zero or more child items.
|
|
3283
|
-
*/
|
|
3284
|
-
declare class PdfOutlineItem {
|
|
3285
|
-
/** The displayed bookmark title. */
|
|
3286
|
-
title: string;
|
|
3287
|
-
/** Where clicking this bookmark navigates. */
|
|
3288
|
-
destination: OutlineDestination;
|
|
3289
|
-
/** Child outline items. */
|
|
3290
|
-
children: PdfOutlineItem[];
|
|
3291
|
-
/** Whether children are initially expanded. */
|
|
3292
|
-
isOpen: boolean;
|
|
3293
|
-
/** Optional colour for the outline text (RGB, 0-1 range). */
|
|
3294
|
-
color?: {
|
|
3295
|
-
r: number;
|
|
3296
|
-
g: number;
|
|
3297
|
-
b: number;
|
|
3298
|
-
} | undefined;
|
|
3299
|
-
/** Whether the title is displayed in bold. */
|
|
3300
|
-
bold?: boolean | undefined;
|
|
3301
|
-
/** Whether the title is displayed in italic. */
|
|
3302
|
-
italic?: boolean | undefined;
|
|
3303
|
-
/**
|
|
3304
|
-
* Create a new outline item.
|
|
3305
|
-
*
|
|
3306
|
-
* @param title Display title for the bookmark.
|
|
3307
|
-
* @param destination Navigation target.
|
|
3308
|
-
* @param options Visual style options.
|
|
3309
|
-
*/
|
|
3310
|
-
constructor(title: string, destination: OutlineDestination, options?: OutlineItemOptions);
|
|
3311
|
-
/**
|
|
3312
|
-
* Add a child outline item.
|
|
3313
|
-
*
|
|
3314
|
-
* @param title Display title.
|
|
3315
|
-
* @param destination Navigation target.
|
|
3316
|
-
* @param options Visual style options.
|
|
3317
|
-
* @returns The newly created child item.
|
|
3318
|
-
*/
|
|
3319
|
-
addChild(title: string, destination: OutlineDestination, options?: OutlineItemOptions): PdfOutlineItem;
|
|
3320
|
-
/**
|
|
3321
|
-
* Remove a child outline item.
|
|
3322
|
-
*
|
|
3323
|
-
* @param item The child item to remove.
|
|
3324
|
-
* @throws If the item is not a direct child.
|
|
3325
|
-
*/
|
|
3326
|
-
removeChild(item: PdfOutlineItem): void;
|
|
3327
|
-
/**
|
|
3328
|
-
* Count all visible descendants (for the /Count entry).
|
|
3329
|
-
*
|
|
3330
|
-
* Per the PDF spec:
|
|
3331
|
-
* - If the item is open, /Count is the total number of visible
|
|
3332
|
-
* descendants (children + their visible descendants).
|
|
3333
|
-
* - If the item is closed, /Count is the negative of the total
|
|
3334
|
-
* number of descendants that *would* be visible if opened.
|
|
3335
|
-
*
|
|
3336
|
-
* @returns The count value for the /Count entry.
|
|
3337
|
-
*/
|
|
3338
|
-
getVisibleDescendantCount(): number;
|
|
3339
|
-
/**
|
|
3340
|
-
* Count the total number of descendants regardless of open/closed state.
|
|
3341
|
-
* @internal
|
|
3342
|
-
*/
|
|
3343
|
-
getTotalDescendantCount(): number;
|
|
3344
|
-
}
|
|
3345
|
-
/**
|
|
3346
|
-
* The root of the outline tree, containing top-level outline items.
|
|
3347
|
-
*/
|
|
3348
|
-
declare class PdfOutlineTree {
|
|
3349
|
-
/** Top-level outline items. */
|
|
3350
|
-
items: PdfOutlineItem[];
|
|
3351
|
-
constructor();
|
|
3352
|
-
/**
|
|
3353
|
-
* Add a top-level outline item.
|
|
3354
|
-
*
|
|
3355
|
-
* @param title Display title.
|
|
3356
|
-
* @param destination Navigation target.
|
|
3357
|
-
* @param options Visual style options.
|
|
3358
|
-
* @returns The newly created item.
|
|
3359
|
-
*/
|
|
3360
|
-
addItem(title: string, destination: OutlineDestination, options?: OutlineItemOptions): PdfOutlineItem;
|
|
3361
|
-
/**
|
|
3362
|
-
* Remove a top-level outline item.
|
|
3363
|
-
*
|
|
3364
|
-
* @param item The item to remove.
|
|
3365
|
-
* @throws If the item is not in the tree.
|
|
3366
|
-
*/
|
|
3367
|
-
removeItem(item: PdfOutlineItem): void;
|
|
3368
|
-
/**
|
|
3369
|
-
* Serialize the outline tree to a PDF /Outlines dictionary.
|
|
3370
|
-
*
|
|
3371
|
-
* This creates the complete outline object graph:
|
|
3372
|
-
* - A root /Outlines dict with /Type, /First, /Last, /Count
|
|
3373
|
-
* - One dict per outline item with /Title, /Parent, /Prev, /Next,
|
|
3374
|
-
* /First, /Last, /Count, /Dest (or /A), /C, /F
|
|
3375
|
-
*
|
|
3376
|
-
* All dictionaries are registered in the provided registry and
|
|
3377
|
-
* cross-linked via indirect references.
|
|
3378
|
-
*
|
|
3379
|
-
* @param registry Object registry for allocating refs.
|
|
3380
|
-
* @param pageRefs Array of PdfRef for each page (indexed by page number).
|
|
3381
|
-
* @returns The indirect reference to the /Outlines root dict.
|
|
3382
|
-
*/
|
|
3383
|
-
toDict(registry: PdfObjectRegistry, pageRefs: readonly PdfRef[]): PdfRef;
|
|
3384
|
-
/**
|
|
3385
|
-
* Parse an outline tree from an existing /Outlines dictionary.
|
|
3386
|
-
*
|
|
3387
|
-
* @param dict The /Outlines dictionary.
|
|
3388
|
-
* @param resolver Function to resolve indirect references to objects.
|
|
3389
|
-
* @param pageRefToIndex Mapping from page ref object numbers to page indices.
|
|
3390
|
-
* @returns A fully populated PdfOutlineTree.
|
|
3391
|
-
*/
|
|
3392
|
-
static fromDict(dict: PdfDict, resolver: (ref: PdfRef) => PdfObject | undefined, pageRefToIndex: ReadonlyMap<number, number>): PdfOutlineTree;
|
|
3393
|
-
/**
|
|
3394
|
-
* Serialize a list of sibling outline items, linking them with
|
|
3395
|
-
* /Prev and /Next references.
|
|
3396
|
-
*
|
|
3397
|
-
* @param items The sibling items to serialize.
|
|
3398
|
-
* @param parentRef The indirect reference to the parent node.
|
|
3399
|
-
* @param registry Object registry.
|
|
3400
|
-
* @param pageRefs Page references array.
|
|
3401
|
-
* @returns Array of refs for the serialized items.
|
|
3402
|
-
*
|
|
3403
|
-
* @internal
|
|
3404
|
-
*/
|
|
3405
|
-
private serializeItems;
|
|
3406
|
-
/**
|
|
3407
|
-
* Serialize a destination into a /Dest array on the item dict.
|
|
3408
|
-
*
|
|
3409
|
-
* Destination formats per PDF spec:
|
|
3410
|
-
* - [page /Fit]
|
|
3411
|
-
* - [page /FitH top]
|
|
3412
|
-
* - [page /FitV left]
|
|
3413
|
-
* - [page /FitB]
|
|
3414
|
-
* - [page /FitBH top]
|
|
3415
|
-
* - [page /FitBV left]
|
|
3416
|
-
* - [page /XYZ left top zoom]
|
|
3417
|
-
*
|
|
3418
|
-
* @internal
|
|
3419
|
-
*/
|
|
3420
|
-
private serializeDestination;
|
|
3421
|
-
}
|
|
3422
|
-
//#endregion
|
|
3423
|
-
//#region src/metadata/viewerPreferences.d.ts
|
|
3424
|
-
/**
|
|
3425
|
-
* Viewer preference settings for a PDF document.
|
|
3426
|
-
*
|
|
3427
|
-
* All properties are optional. Omitted properties use the viewer's
|
|
3428
|
-
* default behaviour.
|
|
3429
|
-
*/
|
|
3430
|
-
interface ViewerPreferences {
|
|
3431
|
-
/** Hide the viewer's toolbar when the document is active. */
|
|
3432
|
-
hideToolbar?: boolean | undefined;
|
|
3433
|
-
/** Hide the viewer's menu bar when the document is active. */
|
|
3434
|
-
hideMenubar?: boolean | undefined;
|
|
3435
|
-
/** Hide the viewer's window UI elements (scrollbars, etc.). */
|
|
3436
|
-
hideWindowUI?: boolean | undefined;
|
|
3437
|
-
/** Resize the document's window to fit the first page. */
|
|
3438
|
-
fitWindow?: boolean | undefined;
|
|
3439
|
-
/** Center the document's window on the screen. */
|
|
3440
|
-
centerWindow?: boolean | undefined;
|
|
3441
|
-
/** Display the document title (from /Info /Title) in the title bar. */
|
|
3442
|
-
displayDocTitle?: boolean | undefined;
|
|
3443
|
-
/** Page mode to use when exiting full-screen mode. */
|
|
3444
|
-
nonFullScreenPageMode?: 'UseNone' | 'UseOutlines' | 'UseThumbs' | 'UseOC' | undefined;
|
|
3445
|
-
/** Predominant reading order for text. */
|
|
3446
|
-
direction?: 'L2R' | 'R2L' | undefined;
|
|
3447
|
-
/** Page scaling preference for the print dialog. */
|
|
3448
|
-
printScaling?: 'None' | 'AppDefault' | undefined;
|
|
3449
|
-
/** Paper handling option for duplex printing. */
|
|
3450
|
-
duplex?: 'Simplex' | 'DuplexFlipShortEdge' | 'DuplexFlipLongEdge' | undefined;
|
|
3451
|
-
/** Page ranges to print, as [start, end] pairs (1-based). */
|
|
3452
|
-
printPageRange?: [number, number][] | undefined;
|
|
3453
|
-
/** Default number of copies to print. */
|
|
3454
|
-
numCopies?: number | undefined;
|
|
3455
|
-
/** Whether to pick the paper tray based on the PDF page size. */
|
|
3456
|
-
pickTrayByPDFSize?: boolean | undefined;
|
|
3457
|
-
}
|
|
3458
|
-
/**
|
|
3459
|
-
* Build a `/ViewerPreferences` dictionary from preferences.
|
|
3460
|
-
*
|
|
3461
|
-
* Only includes entries for properties that are explicitly set
|
|
3462
|
-
* (non-undefined). Boolean values of `false` are included to
|
|
3463
|
-
* explicitly override viewer defaults.
|
|
3464
|
-
*
|
|
3465
|
-
* @param prefs Viewer preferences to serialize.
|
|
3466
|
-
* @returns A PdfDict representing the `/ViewerPreferences` entry.
|
|
3467
|
-
*/
|
|
3468
|
-
declare function buildViewerPreferencesDict(prefs: ViewerPreferences): PdfDict;
|
|
3469
|
-
/**
|
|
3470
|
-
* Parse a `/ViewerPreferences` dictionary into a ViewerPreferences object.
|
|
3471
|
-
*
|
|
3472
|
-
* @param dict The PDF dictionary to parse.
|
|
3473
|
-
* @returns The parsed viewer preferences.
|
|
3474
|
-
*/
|
|
3475
|
-
declare function parseViewerPreferences(dict: PdfDict): ViewerPreferences;
|
|
3476
|
-
//#endregion
|
|
3477
|
-
//#region src/metadata/pdfViewerPreferences.d.ts
|
|
3478
|
-
/**
|
|
3479
|
-
* Class-based API for PDF viewer preferences with individual getter/setter pairs.
|
|
3480
|
-
*
|
|
3481
|
-
* Provides the same functionality as the plain `ViewerPreferences` interface
|
|
3482
|
-
* but with a more discoverable, pdf-lib-compatible API.
|
|
3483
|
-
*
|
|
3484
|
-
* ```ts
|
|
3485
|
-
* const prefs = doc.getViewerPreferences();
|
|
3486
|
-
* prefs.setHideToolbar(true);
|
|
3487
|
-
* prefs.setDisplayDocTitle(true);
|
|
3488
|
-
* prefs.setPrintScaling('None');
|
|
3489
|
-
* ```
|
|
3490
|
-
*/
|
|
3491
|
-
declare class PdfViewerPreferences {
|
|
3492
|
-
private data;
|
|
3493
|
-
constructor(data?: ViewerPreferences);
|
|
3494
|
-
/** Whether the viewer's toolbar should be hidden. */
|
|
3495
|
-
getHideToolbar(): boolean;
|
|
3496
|
-
/** Set whether the viewer's toolbar should be hidden. */
|
|
3497
|
-
setHideToolbar(value: boolean): void;
|
|
3498
|
-
/** Whether the viewer's menu bar should be hidden. */
|
|
3499
|
-
getHideMenubar(): boolean;
|
|
3500
|
-
/** Set whether the viewer's menu bar should be hidden. */
|
|
3501
|
-
setHideMenubar(value: boolean): void;
|
|
3502
|
-
/** Whether the viewer's window UI elements should be hidden. */
|
|
3503
|
-
getHideWindowUI(): boolean;
|
|
3504
|
-
/** Set whether the viewer's window UI elements should be hidden. */
|
|
3505
|
-
setHideWindowUI(value: boolean): void;
|
|
3506
|
-
/** Whether the document window should be resized to fit the first page. */
|
|
3507
|
-
getFitWindow(): boolean;
|
|
3508
|
-
/** Set whether the document window should be resized to fit the first page. */
|
|
3509
|
-
setFitWindow(value: boolean): void;
|
|
3510
|
-
/** Whether the document window should be centered on the screen. */
|
|
3511
|
-
getCenterWindow(): boolean;
|
|
3512
|
-
/** Set whether the document window should be centered on the screen. */
|
|
3513
|
-
setCenterWindow(value: boolean): void;
|
|
3514
|
-
/** Whether the title bar should display the document title from metadata. */
|
|
3515
|
-
getDisplayDocTitle(): boolean;
|
|
3516
|
-
/** Set whether the title bar should display the document title. */
|
|
3517
|
-
setDisplayDocTitle(value: boolean): void;
|
|
3518
|
-
/** Whether the paper tray should be selected based on the PDF page size. */
|
|
3519
|
-
getPickTrayByPDFSize(): boolean;
|
|
3520
|
-
/** Set whether the paper tray should be selected based on the PDF page size. */
|
|
3521
|
-
setPickTrayByPDFSize(value: boolean): void;
|
|
3522
|
-
/** Page mode to use when exiting full-screen mode. */
|
|
3523
|
-
getNonFullScreenPageMode(): 'UseNone' | 'UseOutlines' | 'UseThumbs' | 'UseOC';
|
|
3524
|
-
/** Set the page mode to use when exiting full-screen mode. */
|
|
3525
|
-
setNonFullScreenPageMode(value: 'UseNone' | 'UseOutlines' | 'UseThumbs' | 'UseOC'): void;
|
|
3526
|
-
/** Predominant reading order for text. */
|
|
3527
|
-
getDirection(): 'L2R' | 'R2L';
|
|
3528
|
-
/** Set the predominant reading order for text. */
|
|
3529
|
-
setDirection(value: 'L2R' | 'R2L'): void;
|
|
3530
|
-
/** Page scaling preference for the print dialog. */
|
|
3531
|
-
getPrintScaling(): 'None' | 'AppDefault';
|
|
3532
|
-
/** Set the page scaling preference for the print dialog. */
|
|
3533
|
-
setPrintScaling(value: 'None' | 'AppDefault'): void;
|
|
3534
|
-
/** Paper handling option for duplex printing, or undefined if not set. */
|
|
3535
|
-
getDuplex(): 'Simplex' | 'DuplexFlipShortEdge' | 'DuplexFlipLongEdge' | undefined;
|
|
3536
|
-
/** Set the paper handling option for duplex printing. */
|
|
3537
|
-
setDuplex(value: 'Simplex' | 'DuplexFlipShortEdge' | 'DuplexFlipLongEdge'): void;
|
|
3538
|
-
/** Default number of copies to print. */
|
|
3539
|
-
getNumCopies(): number;
|
|
3540
|
-
/** Set the default number of copies to print. */
|
|
3541
|
-
setNumCopies(value: number): void;
|
|
3542
|
-
/** Page ranges to print, as [start, end] pairs, or undefined if not set. */
|
|
3543
|
-
getPrintPageRange(): [number, number][] | undefined;
|
|
3544
|
-
/** Set the page ranges to print, as [start, end] pairs. */
|
|
3545
|
-
setPrintPageRange(value: [number, number][]): void;
|
|
3546
|
-
/** Convert to a PdfDict for embedding in the PDF catalog. */
|
|
3547
|
-
toDict(): PdfDict;
|
|
3548
|
-
/** Convert to a plain ViewerPreferences object. */
|
|
3549
|
-
toObject(): ViewerPreferences;
|
|
3550
|
-
}
|
|
3551
|
-
//#endregion
|
|
3552
|
-
//#region src/signature/signatureHandler.d.ts
|
|
3553
|
-
/**
|
|
3554
|
-
* @module signature/signatureHandler
|
|
3555
|
-
*
|
|
3556
|
-
* High-level API for signing PDF documents and extracting signature
|
|
3557
|
-
* information.
|
|
3558
|
-
*
|
|
3559
|
-
* This module orchestrates the lower-level modules (byteRange, pkcs7)
|
|
3560
|
-
* to provide a simple `signPdf()` function and a `getSignatures()`
|
|
3561
|
-
* function for inspecting existing signatures.
|
|
3562
|
-
*
|
|
3563
|
-
* @packageDocumentation
|
|
3564
|
-
*/
|
|
3565
|
-
/**
|
|
3566
|
-
* Options for a visible signature appearance on the page.
|
|
3567
|
-
*/
|
|
3568
|
-
interface VisibleSignatureOptions {
|
|
3569
|
-
/** Zero-based page index where the signature should appear. Default: 0. */
|
|
3570
|
-
pageIndex?: number | undefined;
|
|
3571
|
-
/** Rectangle [x, y, width, height] in PDF points from the bottom-left corner. */
|
|
3572
|
-
rect: [number, number, number, number];
|
|
3573
|
-
/**
|
|
3574
|
-
* Text lines to display in the signature box.
|
|
3575
|
-
* Each string becomes a separate line. If omitted, auto-generates
|
|
3576
|
-
* from the signer name, reason, location, and date.
|
|
3577
|
-
*/
|
|
3578
|
-
text?: string[] | undefined;
|
|
3579
|
-
/** Font size for the text. Default: 10. */
|
|
3580
|
-
fontSize?: number | undefined;
|
|
3581
|
-
/**
|
|
3582
|
-
* Background color as [r, g, b] values (0–1). Default: transparent.
|
|
3583
|
-
*/
|
|
3584
|
-
backgroundColor?: [number, number, number] | undefined;
|
|
3585
|
-
/**
|
|
3586
|
-
* Border color as [r, g, b] values (0–1). Default: [0, 0, 0] (black).
|
|
3587
|
-
*/
|
|
3588
|
-
borderColor?: [number, number, number] | undefined;
|
|
3589
|
-
/** Border width in points. Default: 1. Set to 0 for no border. */
|
|
3590
|
-
borderWidth?: number | undefined;
|
|
3591
|
-
}
|
|
3592
|
-
/**
|
|
3593
|
-
* Options for signing a PDF.
|
|
3594
|
-
*/
|
|
3595
|
-
interface SignOptions {
|
|
3596
|
-
/** DER-encoded X.509 certificate. */
|
|
3597
|
-
certificate: Uint8Array;
|
|
3598
|
-
/** PKCS#8 DER-encoded private key. */
|
|
3599
|
-
privateKey: Uint8Array;
|
|
3600
|
-
/** Hash algorithm. Default: 'SHA-256'. */
|
|
3601
|
-
hashAlgorithm?: 'SHA-256' | 'SHA-384' | 'SHA-512' | undefined;
|
|
3602
|
-
/** Reason for signing. */
|
|
3603
|
-
reason?: string | undefined;
|
|
3604
|
-
/** Location of signing. */
|
|
3605
|
-
location?: string | undefined;
|
|
3606
|
-
/** Contact information. */
|
|
3607
|
-
contactInfo?: string | undefined;
|
|
3608
|
-
/** RFC 3161 TSA URL for timestamping (optional). */
|
|
3609
|
-
timestampUrl?: string | undefined;
|
|
3610
|
-
/**
|
|
3611
|
-
* Visible signature appearance options. When provided, the signature
|
|
3612
|
-
* field is rendered visibly on the specified page with text and
|
|
3613
|
-
* optional styling. When omitted, the signature is invisible.
|
|
3614
|
-
*/
|
|
3615
|
-
appearance?: VisibleSignatureOptions | undefined;
|
|
3616
|
-
}
|
|
3617
|
-
/**
|
|
3618
|
-
* Information about an existing signature in a PDF.
|
|
3619
|
-
*/
|
|
3620
|
-
interface PdfSignatureInfo {
|
|
3621
|
-
/** The signature field name. */
|
|
3622
|
-
fieldName: string;
|
|
3623
|
-
/** Subject CN from the certificate. */
|
|
3624
|
-
signedBy: string;
|
|
3625
|
-
/** Reason for signing. */
|
|
3626
|
-
reason?: string | undefined;
|
|
3627
|
-
/** Location of signing. */
|
|
3628
|
-
location?: string | undefined;
|
|
3629
|
-
/** Contact information. */
|
|
3630
|
-
contactInfo?: string | undefined;
|
|
3631
|
-
/** Signing date/time. */
|
|
3632
|
-
signingDate?: Date | undefined;
|
|
3633
|
-
/** The ByteRange covering this signature. */
|
|
3634
|
-
byteRange: [number, number, number, number];
|
|
3635
|
-
/** Whether the signature is valid (set during verification). */
|
|
3636
|
-
signatureValid?: boolean | undefined;
|
|
3637
|
-
}
|
|
3638
|
-
/**
|
|
3639
|
-
* Sign a PDF document.
|
|
3640
|
-
*
|
|
3641
|
-
* Returns the signed PDF bytes. Uses incremental save to preserve
|
|
3642
|
-
* existing content (including any previous signatures).
|
|
3643
|
-
*
|
|
3644
|
-
* @param pdfBytes The original PDF file bytes.
|
|
3645
|
-
* @param fieldName The name for the signature field.
|
|
3646
|
-
* @param options Signing options (certificate, key, etc.).
|
|
3647
|
-
* @returns The signed PDF bytes.
|
|
3648
|
-
*
|
|
3649
|
-
* @example
|
|
3650
|
-
* ```ts
|
|
3651
|
-
* const signedPdf = await signPdf(pdfBytes, 'Signature1', {
|
|
3652
|
-
* certificate: certDer,
|
|
3653
|
-
* privateKey: keyDer,
|
|
3654
|
-
* reason: 'Document approval',
|
|
3655
|
-
* location: 'New York, NY',
|
|
3656
|
-
* });
|
|
3657
|
-
* ```
|
|
3658
|
-
*/
|
|
3659
|
-
declare function signPdf(pdfBytes: Uint8Array, fieldName: string, options: SignOptions): Promise<Uint8Array>;
|
|
3660
|
-
/**
|
|
3661
|
-
* Extract signature information from a PDF.
|
|
3662
|
-
*
|
|
3663
|
-
* Scans the PDF for signature dictionaries and extracts metadata
|
|
3664
|
-
* from each one.
|
|
3665
|
-
*
|
|
3666
|
-
* @param pdfBytes The PDF file bytes.
|
|
3667
|
-
* @returns Array of signature info objects.
|
|
3668
|
-
*/
|
|
3669
|
-
declare function getSignatures(pdfBytes: Uint8Array): PdfSignatureInfo[];
|
|
3670
|
-
//#endregion
|
|
3671
|
-
//#region src/core/embeddedFiles.d.ts
|
|
3672
|
-
/** Describes a file to attach to (or already attached to) a PDF. */
|
|
3673
|
-
interface EmbeddedFile {
|
|
3674
|
-
/** Filename. */
|
|
3675
|
-
name: string;
|
|
3676
|
-
/** File data. */
|
|
3677
|
-
data: Uint8Array;
|
|
3678
|
-
/** MIME type (e.g. `"application/pdf"`, `"text/plain"`). */
|
|
3679
|
-
mimeType: string;
|
|
3680
|
-
/** Optional description. */
|
|
3681
|
-
description?: string | undefined;
|
|
3682
|
-
/** Optional creation date. */
|
|
3683
|
-
creationDate?: Date | undefined;
|
|
3684
|
-
/** Optional modification date. */
|
|
3685
|
-
modificationDate?: Date | undefined;
|
|
3686
|
-
}
|
|
3687
|
-
/**
|
|
3688
|
-
* Create an embedded file stream and filespec dictionary, registering
|
|
3689
|
-
* them in the object registry.
|
|
3690
|
-
*
|
|
3691
|
-
* @param registry The PDF object registry.
|
|
3692
|
-
* @param file The file to embed.
|
|
3693
|
-
* @returns The indirect reference to the filespec dictionary.
|
|
3694
|
-
*/
|
|
3695
|
-
declare function attachFile(registry: PdfObjectRegistry, file: EmbeddedFile): PdfRef;
|
|
3696
|
-
/**
|
|
3697
|
-
* Extract embedded file attachments from a catalog dictionary.
|
|
3698
|
-
*
|
|
3699
|
-
* @param catalogDict The catalog dictionary.
|
|
3700
|
-
* @param resolver A function to resolve indirect references.
|
|
3701
|
-
* @returns An array of embedded file descriptions.
|
|
3702
|
-
*/
|
|
3703
|
-
declare function getAttachments(catalogDict: PdfDict, resolver: (ref: PdfRef) => PdfObject): EmbeddedFile[];
|
|
3704
|
-
/**
|
|
3705
|
-
* Build an `/EmbeddedFiles` name tree dictionary.
|
|
3706
|
-
*
|
|
3707
|
-
* @param files Array of indirect references to filespec dictionaries.
|
|
3708
|
-
* @param names Corresponding file names (same order as `files`).
|
|
3709
|
-
* @param registry The PDF object registry.
|
|
3710
|
-
* @returns The name tree dictionary.
|
|
3711
|
-
*/
|
|
3712
|
-
declare function buildEmbeddedFilesNameTree(files: PdfRef[], names: string[], registry: PdfObjectRegistry): PdfDict;
|
|
3713
|
-
//#endregion
|
|
3714
|
-
//#region src/core/watermark.d.ts
|
|
3715
|
-
/** Options for watermark rendering. */
|
|
3716
|
-
interface WatermarkOptions {
|
|
3717
|
-
/** The watermark text. */
|
|
3718
|
-
text: string;
|
|
3719
|
-
/** Font size in points (default: 60). */
|
|
3720
|
-
fontSize?: number | undefined;
|
|
3721
|
-
/** Text colour as RGB (0-1 range, default: light gray). */
|
|
3722
|
-
color?: {
|
|
3723
|
-
r: number;
|
|
3724
|
-
g: number;
|
|
3725
|
-
b: number;
|
|
3726
|
-
} | undefined;
|
|
3727
|
-
/** Opacity from 0 (invisible) to 1 (opaque), default: 0.3. */
|
|
3728
|
-
opacity?: number | undefined;
|
|
3729
|
-
/** Rotation angle in degrees (default: 45). */
|
|
3730
|
-
rotation?: number | undefined;
|
|
3731
|
-
/** Position: `'center'`, `'top'`, or `'bottom'` (default: `'center'`). */
|
|
3732
|
-
position?: 'center' | 'top' | 'bottom' | undefined;
|
|
3733
|
-
}
|
|
3734
|
-
/**
|
|
3735
|
-
* Add a watermark to a single page.
|
|
3736
|
-
*
|
|
3737
|
-
* The watermark is drawn using the Helvetica standard font (no
|
|
3738
|
-
* embedding required). The text is rendered with the specified
|
|
3739
|
-
* rotation, opacity, and colour.
|
|
3740
|
-
*
|
|
3741
|
-
* @param page The page to watermark.
|
|
3742
|
-
* @param options Watermark options.
|
|
3743
|
-
* @param registry The PDF object registry (for ExtGState).
|
|
3744
|
-
*/
|
|
3745
|
-
declare function addWatermarkToPage(page: PdfPage, options: WatermarkOptions, registry: PdfObjectRegistry): void;
|
|
3746
|
-
/**
|
|
3747
|
-
* Add a watermark to all pages in a document.
|
|
3748
|
-
*
|
|
3749
|
-
* @param doc The PDF document.
|
|
3750
|
-
* @param options Watermark options.
|
|
3751
|
-
*/
|
|
3752
|
-
declare function addWatermark(doc: PdfDocument, options: WatermarkOptions): void;
|
|
3753
|
-
//#endregion
|
|
3754
|
-
//#region src/signature/signatureVerifier.d.ts
|
|
3755
|
-
/**
|
|
3756
|
-
* @module signature/signatureVerifier
|
|
3757
|
-
*
|
|
3758
|
-
* Signature verification for signed PDF documents.
|
|
3759
|
-
*
|
|
3760
|
-
* Verifies that:
|
|
3761
|
-
* 1. The PDF bytes covered by the ByteRange have not been tampered with
|
|
3762
|
-
* (integrity check by hashing the covered regions).
|
|
3763
|
-
* 2. The PKCS#7 signature is valid for the hash (cryptographic verification
|
|
3764
|
-
* using the certificate's public key via Web Crypto).
|
|
3765
|
-
*
|
|
3766
|
-
* Limitations:
|
|
3767
|
-
* - Certificate chain validation (CA trust) is not performed because
|
|
3768
|
-
* Web Crypto does not provide chain validation APIs. Only the
|
|
3769
|
-
* mathematical signature is verified against the embedded certificate.
|
|
3770
|
-
* - CRL/OCSP revocation checking is not performed.
|
|
3771
|
-
*
|
|
3772
|
-
* @packageDocumentation
|
|
3773
|
-
*/
|
|
3774
|
-
/**
|
|
3775
|
-
* Result of verifying a single signature.
|
|
3776
|
-
*/
|
|
3777
|
-
interface SignatureVerificationResult {
|
|
3778
|
-
/** The signature field name. */
|
|
3779
|
-
fieldName: string;
|
|
3780
|
-
/** Subject CN from the certificate. */
|
|
3781
|
-
signedBy: string;
|
|
3782
|
-
/** Overall validity (integrity AND signature). */
|
|
3783
|
-
valid: boolean;
|
|
3784
|
-
/** Reason for signing (if present). */
|
|
3785
|
-
reason?: string | undefined;
|
|
3786
|
-
/** Whether the ByteRange hash matches the signed hash. */
|
|
3787
|
-
integrityValid: boolean;
|
|
3788
|
-
/** Whether the cryptographic signature is valid. */
|
|
3789
|
-
certificateValid?: boolean | undefined;
|
|
3790
|
-
/** Signing date (if present in signed attributes). */
|
|
3791
|
-
signingDate?: Date | undefined;
|
|
3792
|
-
}
|
|
3793
|
-
/**
|
|
3794
|
-
* Verify all signatures in a PDF.
|
|
3795
|
-
*
|
|
3796
|
-
* For each signature found:
|
|
3797
|
-
* 1. Computes the hash of the ByteRange-covered bytes
|
|
3798
|
-
* 2. Extracts the PKCS#7 structure
|
|
3799
|
-
* 3. Verifies the message digest matches
|
|
3800
|
-
* 4. Verifies the cryptographic signature against the certificate
|
|
3801
|
-
*
|
|
3802
|
-
* @param pdfBytes The PDF file bytes.
|
|
3803
|
-
* @returns Array of verification results.
|
|
3804
|
-
*/
|
|
3805
|
-
declare function verifySignatures(pdfBytes: Uint8Array): Promise<SignatureVerificationResult[]>;
|
|
3806
|
-
/**
|
|
3807
|
-
* Verify a single signature.
|
|
3808
|
-
*
|
|
3809
|
-
* Extracts the signed attributes from the PKCS#7 structure and
|
|
3810
|
-
* verifies the signature using the certificate's public key.
|
|
3811
|
-
*
|
|
3812
|
-
* @param pdfBytes The PDF file bytes.
|
|
3813
|
-
* @param byteRange The ByteRange array.
|
|
3814
|
-
* @param signatureBytes The DER-encoded PKCS#7 signature.
|
|
3815
|
-
* @param certificateBytes The DER-encoded X.509 certificate.
|
|
3816
|
-
* @returns `true` if the signature is valid.
|
|
3817
|
-
*/
|
|
3818
|
-
declare function verifySignature(pdfBytes: Uint8Array, byteRange: [number, number, number, number], signatureBytes: Uint8Array, certificateBytes: Uint8Array): Promise<boolean>;
|
|
3819
|
-
//#endregion
|
|
3820
|
-
//#region src/core/pdfDocument.d.ts
|
|
3821
|
-
/**
|
|
3822
|
-
* The 14 standard PDF fonts guaranteed to be available in every PDF
|
|
3823
|
-
* viewer. These can be used without embedding font data.
|
|
3824
|
-
*/
|
|
3825
|
-
declare const StandardFonts: {
|
|
3826
|
-
readonly Courier: "Courier";
|
|
3827
|
-
readonly CourierBold: "Courier-Bold";
|
|
3828
|
-
readonly CourierOblique: "Courier-Oblique";
|
|
3829
|
-
readonly CourierBoldOblique: "Courier-BoldOblique";
|
|
3830
|
-
readonly Helvetica: "Helvetica";
|
|
3831
|
-
readonly HelveticaBold: "Helvetica-Bold";
|
|
3832
|
-
readonly HelveticaOblique: "Helvetica-Oblique";
|
|
3833
|
-
readonly HelveticaBoldOblique: "Helvetica-BoldOblique";
|
|
3834
|
-
readonly TimesRoman: "Times-Roman";
|
|
3835
|
-
readonly TimesBold: "Times-Bold";
|
|
3836
|
-
readonly TimesItalic: "Times-Italic";
|
|
3837
|
-
readonly TimesBoldItalic: "Times-BoldItalic";
|
|
3838
|
-
readonly Symbol: "Symbol";
|
|
3839
|
-
readonly ZapfDingbats: "ZapfDingbats";
|
|
3840
|
-
};
|
|
3841
|
-
type StandardFontName = (typeof StandardFonts)[keyof typeof StandardFonts];
|
|
3842
|
-
/**
|
|
3843
|
-
* Options for font embedding.
|
|
3844
|
-
*/
|
|
3845
|
-
interface EmbedFontOptions {
|
|
3846
|
-
/** Whether to subset the font to reduce file size. Default: true. */
|
|
3847
|
-
subset?: boolean | undefined;
|
|
3848
|
-
/** OpenType feature flags. e.g., { kern: true, liga: true }. */
|
|
3849
|
-
features?: Record<string, boolean> | undefined;
|
|
3850
|
-
/** Custom name to use in the font dictionary's /BaseFont instead of the font's PostScript name. */
|
|
3851
|
-
customName?: string | undefined;
|
|
3852
|
-
}
|
|
3853
|
-
/**
|
|
3854
|
-
* Options for {@link PdfDocument.setTitle}.
|
|
3855
|
-
*/
|
|
3856
|
-
interface SetTitleOptions {
|
|
3857
|
-
/** When `true`, tell PDF viewers to display the document title in the window title bar. */
|
|
3858
|
-
showInWindowTitleBar?: boolean | undefined;
|
|
3859
|
-
}
|
|
3860
|
-
/**
|
|
3861
|
-
* The root document object. Create via {@link createPdf}.
|
|
3862
|
-
*
|
|
3863
|
-
* Manages:
|
|
3864
|
-
* - Page collection (ordered)
|
|
3865
|
-
* - Embedded resources (fonts, images)
|
|
3866
|
-
* - Document metadata (title, author, dates, …)
|
|
3867
|
-
* - Object-number allocation
|
|
3868
|
-
*/
|
|
3869
|
-
declare class PdfDocument {
|
|
3870
|
-
/**
|
|
3871
|
-
* Load an existing PDF document from raw bytes, an ArrayBuffer, or a
|
|
3872
|
-
* Base64-encoded string.
|
|
3873
|
-
*
|
|
3874
|
-
* This is the primary entry point for parsing existing PDFs. It
|
|
3875
|
-
* validates the file header, parses the cross-reference structure,
|
|
3876
|
-
* resolves the page tree and metadata, and returns a fully populated
|
|
3877
|
-
* {@link PdfDocument} that can be inspected or further modified.
|
|
3878
|
-
*
|
|
3879
|
-
* @param data The PDF data as a `Uint8Array`, `ArrayBuffer`, or a
|
|
3880
|
-
* Base64-encoded string.
|
|
3881
|
-
* @param options Optional loading options (e.g. password, encryption).
|
|
3882
|
-
* @returns A promise that resolves to the parsed PdfDocument.
|
|
3883
|
-
*
|
|
3884
|
-
* @example
|
|
3885
|
-
* ```ts
|
|
3886
|
-
* // From fetch (ArrayBuffer)
|
|
3887
|
-
* const pdfBytes = await fetch('document.pdf').then(r => r.arrayBuffer());
|
|
3888
|
-
* const doc = await PdfDocument.load(pdfBytes);
|
|
3889
|
-
*
|
|
3890
|
-
* // From a Base64 string
|
|
3891
|
-
* const doc2 = await PdfDocument.load(base64String);
|
|
3892
|
-
* ```
|
|
3893
|
-
*/
|
|
3894
|
-
static load(data: Uint8Array | ArrayBuffer | string, options?: LoadPdfOptions): Promise<PdfDocument>;
|
|
3895
|
-
/**
|
|
3896
|
-
* Create a new, empty PDF document.
|
|
3897
|
-
*
|
|
3898
|
-
* This is the static-method equivalent of {@link createPdf}.
|
|
3899
|
-
*
|
|
3900
|
-
* ```ts
|
|
3901
|
-
* const doc = PdfDocument.create();
|
|
3902
|
-
* ```
|
|
3903
|
-
*/
|
|
3904
|
-
static create(): PdfDocument;
|
|
3905
|
-
/** Object registry — allocates indirect references. */
|
|
3906
|
-
private readonly registry;
|
|
3907
|
-
/** Pages in document order. */
|
|
3908
|
-
private readonly pages;
|
|
3909
|
-
/** Metadata fields. */
|
|
3910
|
-
private readonly meta;
|
|
3911
|
-
/** Counter for font resource names (F1, F2, …). */
|
|
3912
|
-
private fontCounter;
|
|
3913
|
-
/** Counter for image resource names (Im1, Im2, …). */
|
|
3914
|
-
private imageCounter;
|
|
3915
|
-
/** Counter for form XObject resource names (XF1, XF2, …). */
|
|
3916
|
-
private formXObjectCounter;
|
|
3917
|
-
/**
|
|
3918
|
-
* @param registry Optional pre-populated object registry (used when
|
|
3919
|
-
* loading an existing PDF so parsed objects are preserved).
|
|
3920
|
-
*/
|
|
3921
|
-
constructor(registry?: PdfObjectRegistry);
|
|
3922
|
-
/** Embedded fonts — maps base font name → FontRef. */
|
|
3923
|
-
private readonly embeddedFonts;
|
|
3924
|
-
/** Embedded images — maps an internal key → ImageRef. */
|
|
3925
|
-
private readonly embeddedImages;
|
|
3926
|
-
/**
|
|
3927
|
-
* Add a page to the document.
|
|
3928
|
-
*
|
|
3929
|
-
* When called with a {@link PageSize} (or no argument), a new blank page
|
|
3930
|
-
* is created. When called with an existing {@link PdfPage} instance
|
|
3931
|
-
* (e.g. one returned by {@link copyPages}), that page is inserted
|
|
3932
|
-
* directly.
|
|
3933
|
-
*
|
|
3934
|
-
* @param sizeOrPage A page size as `[width, height]` tuple,
|
|
3935
|
-
* `{ width, height }` object, one of the
|
|
3936
|
-
* {@link PageSizes} constants, or an existing
|
|
3937
|
-
* {@link PdfPage} instance. Defaults to A4.
|
|
3938
|
-
* @returns The {@link PdfPage} that was added.
|
|
3939
|
-
*/
|
|
3940
|
-
addPage(sizeOrPage?: PageSize | PdfPage): PdfPage;
|
|
3941
|
-
/**
|
|
3942
|
-
* Return a specific page by zero-based index.
|
|
3943
|
-
*
|
|
3944
|
-
* @param index Zero-based page index.
|
|
3945
|
-
* @returns The {@link PdfPage} at the given index.
|
|
3946
|
-
* @throws If the index is out of range.
|
|
3947
|
-
*/
|
|
3948
|
-
getPage(index: number): PdfPage;
|
|
3949
|
-
/**
|
|
3950
|
-
* Return all pages.
|
|
3951
|
-
*/
|
|
3952
|
-
getPages(): readonly PdfPage[];
|
|
3953
|
-
/**
|
|
3954
|
-
* Return the page count.
|
|
3955
|
-
*/
|
|
3956
|
-
getPageCount(): number;
|
|
3957
|
-
/** The number of pages in this document. */
|
|
3958
|
-
get pageCount(): number;
|
|
3959
|
-
/**
|
|
3960
|
-
* @internal Return the mutable internal pages array.
|
|
3961
|
-
* Used by `pageManipulation.ts` and `documentMerge.ts`.
|
|
3962
|
-
*/
|
|
3963
|
-
getInternalPages(): PdfPage[];
|
|
3964
|
-
/**
|
|
3965
|
-
* @internal Return the object registry for external modules.
|
|
3966
|
-
*/
|
|
3967
|
-
getRegistry(): PdfObjectRegistry;
|
|
3968
|
-
/**
|
|
3969
|
-
* @internal Register all currently embedded fonts and CID encoders
|
|
3970
|
-
* on the given page. Used when inserting or copying pages.
|
|
3971
|
-
*/
|
|
3972
|
-
registerFontsOnPage(page: PdfPage): void;
|
|
3973
|
-
/**
|
|
3974
|
-
* @internal Return the embedded fonts map for cross-document operations.
|
|
3975
|
-
*/
|
|
3976
|
-
getEmbeddedFonts(): ReadonlyMap<string, FontRef>;
|
|
3977
|
-
/**
|
|
3978
|
-
* @internal Add a pre-built page (from loading a parsed PDF).
|
|
3979
|
-
* Unlike `addPage()`, this does NOT create a new blank page —
|
|
3980
|
-
* it inserts a PdfPage that already carries original content.
|
|
3981
|
-
*/
|
|
3982
|
-
_addLoadedPage(page: PdfPage): void;
|
|
3983
|
-
/**
|
|
3984
|
-
* @internal Advance font/image counters past names already used
|
|
3985
|
-
* by loaded pages so new resources don't collide.
|
|
3986
|
-
*/
|
|
3987
|
-
_advanceCounters(maxFont: number, maxImage: number, maxGState: number): void;
|
|
3988
|
-
/**
|
|
3989
|
-
* @internal Get the next font counter value and increment it.
|
|
3990
|
-
*/
|
|
3991
|
-
allocateFontName(): string;
|
|
3992
|
-
/**
|
|
3993
|
-
* @internal Get the next image counter value and increment it.
|
|
3994
|
-
*/
|
|
3995
|
-
allocateImageName(): string;
|
|
3996
|
-
/**
|
|
3997
|
-
* Insert a new blank page at the specified position.
|
|
3998
|
-
*
|
|
3999
|
-
* @param index Zero-based position (0 to pageCount inclusive).
|
|
4000
|
-
* @param size Optional page size. Defaults to A4.
|
|
4001
|
-
* @returns The newly created PdfPage.
|
|
4002
|
-
*/
|
|
4003
|
-
insertPage(index: number, size?: PageSize): PdfPage;
|
|
4004
|
-
/**
|
|
4005
|
-
* Remove a page by its zero-based index.
|
|
4006
|
-
*
|
|
4007
|
-
* @param index Zero-based page index to remove.
|
|
4008
|
-
* @throws RangeError if the index is out of bounds.
|
|
4009
|
-
*/
|
|
4010
|
-
removePage(index: number): void;
|
|
4011
|
-
/**
|
|
4012
|
-
* Move a page from one position to another.
|
|
4013
|
-
*
|
|
4014
|
-
* @param fromIndex Current zero-based index of the page.
|
|
4015
|
-
* @param toIndex Target zero-based index (after removal).
|
|
4016
|
-
*/
|
|
4017
|
-
movePage(fromIndex: number, toIndex: number): void;
|
|
4018
|
-
/**
|
|
4019
|
-
* Copy pages from another document into this one.
|
|
4020
|
-
*
|
|
4021
|
-
* The copied pages are appended to the end of this document.
|
|
4022
|
-
* Resources (fonts, images) are deeply cloned and re-registered
|
|
4023
|
-
* in the target document's registry.
|
|
4024
|
-
*
|
|
4025
|
-
* @param sourceDoc The source document to copy pages from.
|
|
4026
|
-
* @param indices Zero-based indices of pages to copy.
|
|
4027
|
-
* @returns The newly created pages in this document.
|
|
4028
|
-
*/
|
|
4029
|
-
copyPages(sourceDoc: PdfDocument, indices: number[]): Promise<PdfPage[]>;
|
|
4030
|
-
/** Counter for unique TTF font keys (to distinguish multiple TTF embeds). */
|
|
4031
|
-
private ttfCounter;
|
|
4032
|
-
/**
|
|
4033
|
-
* Maps TTF font resource name → EmbeddedFont and mutable PDF objects
|
|
4034
|
-
* that need to be updated at save time with subsetted data.
|
|
4035
|
-
*/
|
|
4036
|
-
private readonly ttfFonts;
|
|
4037
|
-
/**
|
|
4038
|
-
* Embed a font in the document.
|
|
4039
|
-
*
|
|
4040
|
-
* Accepts either:
|
|
4041
|
-
* - A **standard font name** string (e.g. `"Helvetica"`) — embeds a
|
|
4042
|
-
* Type 1 font reference (no font data needed).
|
|
4043
|
-
* - A **Uint8Array** of TrueType font bytes — embeds a CIDFont Type 2
|
|
4044
|
-
* composite font with /Identity-H encoding, /FontDescriptor, /ToUnicode
|
|
4045
|
-
* CMap, and /FontFile2 stream.
|
|
4046
|
-
*
|
|
4047
|
-
* The returned {@link FontRef} includes `widthOfTextAtSize()` and
|
|
4048
|
-
* `heightAtSize()` methods for text measurement.
|
|
4049
|
-
*
|
|
4050
|
-
* @param fontNameOrData Base font name string or raw TTF/OTF bytes.
|
|
4051
|
-
* @param options Optional embedding options (subset, OpenType features).
|
|
4052
|
-
* @returns A {@link FontRef} to pass to drawing methods.
|
|
4053
|
-
*/
|
|
4054
|
-
embedFont(fontNameOrData: string | Uint8Array, options?: EmbedFontOptions): Promise<FontRef>;
|
|
4055
|
-
/**
|
|
4056
|
-
* Embed a standard (Type 1) font.
|
|
4057
|
-
* @internal
|
|
4058
|
-
*/
|
|
4059
|
-
private embedStandardFont;
|
|
4060
|
-
/**
|
|
4061
|
-
* Embed a TrueType font from raw bytes as a CIDFont Type 2.
|
|
4062
|
-
* @internal
|
|
4063
|
-
*/
|
|
4064
|
-
private embedTrueTypeFont;
|
|
4065
|
-
/**
|
|
4066
|
-
* Embed a CFF-based OpenType font from raw bytes as a CIDFont Type 0.
|
|
4067
|
-
*
|
|
4068
|
-
* CFF fonts use /CIDFontType0 (instead of /CIDFontType2 for TrueType),
|
|
4069
|
-
* /FontFile3 with /Subtype /CIDFontType0C (instead of /FontFile2),
|
|
4070
|
-
* and embed only the raw CFF table data (not the full OTF wrapper).
|
|
4071
|
-
* No /CIDToGIDMap is needed since CFF fonts map CIDs directly.
|
|
4072
|
-
*
|
|
4073
|
-
* @internal
|
|
4074
|
-
*/
|
|
4075
|
-
private embedCffFont;
|
|
4076
|
-
/**
|
|
4077
|
-
* Embed a PNG image.
|
|
4078
|
-
*
|
|
4079
|
-
* Fully decodes the PNG (including filter reconstruction and alpha
|
|
4080
|
-
* channel separation) and creates a correct PDF image XObject.
|
|
4081
|
-
* For images with transparency, a separate SMask XObject is created
|
|
4082
|
-
* and referenced from the main image.
|
|
4083
|
-
*
|
|
4084
|
-
* @param pngData Raw PNG file bytes as a `Uint8Array` or `ArrayBuffer`.
|
|
4085
|
-
* @returns An {@link ImageRef} to pass to `page.drawImage()`.
|
|
4086
|
-
*/
|
|
4087
|
-
embedPng(pngData: Uint8Array | ArrayBuffer): ImageRef;
|
|
4088
|
-
/**
|
|
4089
|
-
* Embed a JPEG image.
|
|
4090
|
-
*
|
|
4091
|
-
* JPEG data can be embedded directly as a PDF stream with
|
|
4092
|
-
* `DCTDecode` filter — no re-encoding is needed.
|
|
4093
|
-
*
|
|
4094
|
-
* @param jpegData Raw JPEG file bytes as a `Uint8Array` or `ArrayBuffer`.
|
|
4095
|
-
* @returns An {@link ImageRef}.
|
|
4096
|
-
*/
|
|
4097
|
-
embedJpeg(jpegData: Uint8Array | ArrayBuffer): Promise<ImageRef>;
|
|
4098
|
-
/**
|
|
4099
|
-
* Embed a WebP image.
|
|
4100
|
-
*
|
|
4101
|
-
* WebP cannot be directly embedded in PDF. This method decodes the
|
|
4102
|
-
* WebP image to raw pixels (VP8/lossy, VP8L/lossless, or VP8+ALPH),
|
|
4103
|
-
* then embeds as a FlateDecode image XObject. If the WebP has
|
|
4104
|
-
* transparency, the alpha channel is embedded as a soft mask.
|
|
4105
|
-
*
|
|
4106
|
-
* @param webpData Raw WebP file bytes as a `Uint8Array` or `ArrayBuffer`.
|
|
4107
|
-
* @returns An {@link ImageRef}.
|
|
4108
|
-
*/
|
|
4109
|
-
embedWebP(webpData: Uint8Array | ArrayBuffer): ImageRef;
|
|
4110
|
-
/**
|
|
4111
|
-
* Embed a TIFF image.
|
|
4112
|
-
*
|
|
4113
|
-
* Decodes the TIFF image and creates a PDF image XObject with
|
|
4114
|
-
* FlateDecode compression. For multi-page TIFFs, a specific page
|
|
4115
|
-
* can be selected via options.
|
|
4116
|
-
*
|
|
4117
|
-
* @param tiffData Raw TIFF file bytes as a `Uint8Array` or `ArrayBuffer`.
|
|
4118
|
-
* @param options Options (e.g., `{ page: 0 }` for multi-page TIFFs).
|
|
4119
|
-
* @returns An {@link ImageRef}.
|
|
4120
|
-
*/
|
|
4121
|
-
embedTiff(tiffData: Uint8Array | ArrayBuffer, options?: {
|
|
4122
|
-
page?: number | undefined;
|
|
4123
|
-
} | undefined): ImageRef;
|
|
4124
|
-
/**
|
|
4125
|
-
* Embed an image, auto-detecting the format from file headers.
|
|
4126
|
-
*
|
|
4127
|
-
* Inspects the first bytes to determine the image format (PNG, JPEG,
|
|
4128
|
-
* WebP, or TIFF), then delegates to the appropriate embedding method.
|
|
4129
|
-
*
|
|
4130
|
-
* Supported formats:
|
|
4131
|
-
* - **PNG**: `89 50 4E 47` — embedded via {@link embedPng}
|
|
4132
|
-
* - **JPEG**: `FF D8 FF` — embedded via {@link embedJpeg}
|
|
4133
|
-
* - **WebP**: `52 49 46 46` + `57 45 42 50` — embedded via {@link embedWebP}
|
|
4134
|
-
* - **TIFF LE**: `49 49 2A 00` — embedded via {@link embedTiff}
|
|
4135
|
-
* - **TIFF BE**: `4D 4D 00 2A` — embedded via {@link embedTiff}
|
|
4136
|
-
*
|
|
4137
|
-
* @param imageData Raw image file bytes (PNG, JPEG, WebP, or TIFF).
|
|
4138
|
-
* @returns An {@link ImageRef} to pass to `page.drawImage()`.
|
|
4139
|
-
* @throws If the image format cannot be detected.
|
|
4140
|
-
*
|
|
4141
|
-
* @example
|
|
4142
|
-
* ```ts
|
|
4143
|
-
* const bytes = new Uint8Array(await readFile('photo.jpg'));
|
|
4144
|
-
* const image = await pdf.embedImage(bytes);
|
|
4145
|
-
* page.drawImage(image, { x: 50, y: 400, width: 200, height: 150 });
|
|
4146
|
-
* ```
|
|
4147
|
-
*/
|
|
4148
|
-
embedImage(imageData: Uint8Array | ArrayBuffer): Promise<ImageRef>;
|
|
4149
|
-
/**
|
|
4150
|
-
* Embed pages from another PDF as Form XObjects.
|
|
4151
|
-
*
|
|
4152
|
-
* Each embedded page is turned into a self-contained Form XObject that
|
|
4153
|
-
* can be painted onto any page via `page.drawPage()`. The source PDF's
|
|
4154
|
-
* content streams are decoded and concatenated, and all referenced
|
|
4155
|
-
* resources (fonts, images, etc.) are deep-cloned into this document's
|
|
4156
|
-
* registry.
|
|
4157
|
-
*
|
|
4158
|
-
* @param data Raw PDF bytes (Uint8Array or ArrayBuffer).
|
|
4159
|
-
* @param pageIndices Zero-based page indices to embed. Defaults to
|
|
4160
|
-
* `[0]` (first page only).
|
|
4161
|
-
* @returns Array of {@link EmbeddedPdfPage} handles.
|
|
4162
|
-
*
|
|
4163
|
-
* @example
|
|
4164
|
-
* ```ts
|
|
4165
|
-
* const [embeddedPage] = await doc.embedPdf(existingPdfBytes, [0]);
|
|
4166
|
-
* page.drawPage(embeddedPage, { x: 50, y: 50, width: 300, height: 400 });
|
|
4167
|
-
* ```
|
|
4168
|
-
*/
|
|
4169
|
-
embedPdf(data: Uint8Array | ArrayBuffer, pageIndices?: number[], options?: EmbedPageOptions): Promise<EmbeddedPdfPage[]>;
|
|
4170
|
-
/**
|
|
4171
|
-
* Embed a single page (from this or another document) as a Form XObject.
|
|
4172
|
-
*
|
|
4173
|
-
* This is useful when you have an already-parsed PdfPage and want to
|
|
4174
|
-
* stamp it onto other pages as a form XObject.
|
|
4175
|
-
*
|
|
4176
|
-
* @param page The PdfPage to embed.
|
|
4177
|
-
* @param options Optional bounding box / transformation matrix.
|
|
4178
|
-
* @returns An {@link EmbeddedPdfPage} handle.
|
|
4179
|
-
*/
|
|
4180
|
-
embedPage(page: PdfPage, options?: EmbedPageOptions): EmbeddedPdfPage;
|
|
4181
|
-
/**
|
|
4182
|
-
* Embed multiple pages as Form XObjects in batch.
|
|
4183
|
-
* Convenience wrapper around {@link embedPage}.
|
|
4184
|
-
*
|
|
4185
|
-
* @param pages Array of PdfPage instances to embed.
|
|
4186
|
-
* @returns Array of {@link EmbeddedPdfPage} handles, one per input page.
|
|
4187
|
-
*/
|
|
4188
|
-
embedPages(pages: PdfPage[]): EmbeddedPdfPage[];
|
|
4189
|
-
/** Set the document title. */
|
|
4190
|
-
setTitle(title: string, options?: SetTitleOptions): void;
|
|
4191
|
-
/** Set the document author. */
|
|
4192
|
-
setAuthor(author: string): void;
|
|
4193
|
-
/** Set the document subject. */
|
|
4194
|
-
setSubject(subject: string): void;
|
|
4195
|
-
/** Set the document keywords. */
|
|
4196
|
-
setKeywords(keywords: string | string[]): void;
|
|
4197
|
-
/** Set the creator application name. */
|
|
4198
|
-
setCreator(creator: string): void;
|
|
4199
|
-
/** Set the producer string (defaults to `"modern-pdf"`). */
|
|
4200
|
-
setProducer(producer: string): void;
|
|
4201
|
-
/** Set the document creation date. */
|
|
4202
|
-
setCreationDate(date: Date): void;
|
|
4203
|
-
/** Set the document modification date. */
|
|
4204
|
-
setModDate(date: Date): void;
|
|
4205
|
-
/** Get the document title, or `undefined` if not set. */
|
|
4206
|
-
getTitle(): string | undefined;
|
|
4207
|
-
/** Get the document author, or `undefined` if not set. */
|
|
4208
|
-
getAuthor(): string | undefined;
|
|
4209
|
-
/** Get the document subject, or `undefined` if not set. */
|
|
4210
|
-
getSubject(): string | undefined;
|
|
4211
|
-
/** Get the document keywords, or `undefined` if not set. */
|
|
4212
|
-
getKeywords(): string | undefined;
|
|
4213
|
-
/** Get the creator application name, or `undefined` if not set. */
|
|
4214
|
-
getCreator(): string | undefined;
|
|
4215
|
-
/** Get the producer string. */
|
|
4216
|
-
getProducer(): string | undefined;
|
|
4217
|
-
/** Get the document creation date. */
|
|
4218
|
-
getCreationDate(): Date | undefined;
|
|
4219
|
-
/** Get the document modification date, or `undefined` if not set. */
|
|
4220
|
-
getModDate(): Date | undefined;
|
|
4221
|
-
/** The encryption handler, set when `encrypt()` is called. */
|
|
4222
|
-
private encryptionHandler;
|
|
4223
|
-
/**
|
|
4224
|
-
* Configure encryption for this document.
|
|
4225
|
-
*
|
|
4226
|
-
* When encryption is set, the document will be encrypted on the next
|
|
4227
|
-
* call to `save()`. The /Encrypt dictionary and file ID are
|
|
4228
|
-
* generated automatically.
|
|
4229
|
-
*
|
|
4230
|
-
* @param options Encryption options (passwords, permissions, algorithm).
|
|
4231
|
-
*
|
|
4232
|
-
* @example
|
|
4233
|
-
* ```ts
|
|
4234
|
-
* const doc = createPdf();
|
|
4235
|
-
* doc.addPage();
|
|
4236
|
-
* doc.encrypt({
|
|
4237
|
-
* userPassword: 'user123',
|
|
4238
|
-
* ownerPassword: 'owner456',
|
|
4239
|
-
* permissions: { printing: true, copying: false },
|
|
4240
|
-
* algorithm: 'aes-256',
|
|
4241
|
-
* });
|
|
4242
|
-
* const bytes = await doc.save();
|
|
4243
|
-
* ```
|
|
4244
|
-
*/
|
|
4245
|
-
encrypt(options: EncryptOptions): Promise<void>;
|
|
4246
|
-
/**
|
|
4247
|
-
* Check whether this document has encryption configured.
|
|
4248
|
-
*
|
|
4249
|
-
* Returns `true` if `encrypt()` has been called on this document,
|
|
4250
|
-
* or if the document was loaded from an encrypted PDF.
|
|
4251
|
-
*/
|
|
4252
|
-
isEncrypted(): boolean;
|
|
4253
|
-
/**
|
|
4254
|
-
* Get the permission flags for this document, if encrypted.
|
|
4255
|
-
*
|
|
4256
|
-
* @returns The decoded permission flags, or `undefined` if the
|
|
4257
|
-
* document is not encrypted.
|
|
4258
|
-
*/
|
|
4259
|
-
getPermissions(): PdfPermissionFlags | undefined;
|
|
4260
|
-
/**
|
|
4261
|
-
* Get the encryption handler (for advanced use / testing).
|
|
4262
|
-
* @internal
|
|
4263
|
-
*/
|
|
4264
|
-
getEncryptionHandler(): PdfEncryptionHandler | undefined;
|
|
4265
|
-
/** Original PDF bytes (set when loaded from an existing file). */
|
|
4266
|
-
private originalBytes;
|
|
4267
|
-
/**
|
|
4268
|
-
* @internal Set the original bytes (called by the parser on load).
|
|
4269
|
-
*/
|
|
4270
|
-
setOriginalBytes(bytes: Uint8Array): void;
|
|
4271
|
-
/**
|
|
4272
|
-
* @internal Get the original bytes.
|
|
4273
|
-
*/
|
|
4274
|
-
getOriginalBytes(): Uint8Array | undefined;
|
|
4275
|
-
/**
|
|
4276
|
-
* Add a signature field to a page.
|
|
4277
|
-
*
|
|
4278
|
-
* This is a placeholder method that records the intent to sign.
|
|
4279
|
-
* The actual signature creation happens in `sign()`.
|
|
4280
|
-
*
|
|
4281
|
-
* @param pageIndex Zero-based page index.
|
|
4282
|
-
* @param rect Rectangle [x1, y1, x2, y2] for the visual appearance.
|
|
4283
|
-
* @param name The signature field name (must be unique).
|
|
4284
|
-
*/
|
|
4285
|
-
addSignatureField(pageIndex: number, rect: [number, number, number, number], name: string): void;
|
|
4286
|
-
/** Pending signature field definitions. */
|
|
4287
|
-
private readonly signatureFields;
|
|
4288
|
-
/**
|
|
4289
|
-
* Sign the PDF document.
|
|
4290
|
-
*
|
|
4291
|
-
* Returns the signed PDF bytes. Uses incremental save to preserve
|
|
4292
|
-
* existing content and any previous signatures.
|
|
4293
|
-
*
|
|
4294
|
-
* @param fieldName The signature field name.
|
|
4295
|
-
* @param options Signing options (certificate, private key, etc.).
|
|
4296
|
-
* @returns The signed PDF bytes.
|
|
4297
|
-
*
|
|
4298
|
-
* @example
|
|
4299
|
-
* ```ts
|
|
4300
|
-
* const doc = await PdfDocument.load(pdfBytes);
|
|
4301
|
-
* const signedBytes = await doc.sign('Signature1', {
|
|
4302
|
-
* certificate: certDer,
|
|
4303
|
-
* privateKey: keyDer,
|
|
4304
|
-
* reason: 'Document approval',
|
|
4305
|
-
* });
|
|
4306
|
-
* ```
|
|
4307
|
-
*/
|
|
4308
|
-
sign(fieldName: string, options: SignOptions): Promise<Uint8Array>;
|
|
4309
|
-
/**
|
|
4310
|
-
* Get information about all signatures in this document.
|
|
4311
|
-
*
|
|
4312
|
-
* @returns Array of signature info objects.
|
|
4313
|
-
*/
|
|
4314
|
-
getSignatures(): PdfSignatureInfo[];
|
|
4315
|
-
/**
|
|
4316
|
-
* Verify all signatures in this document.
|
|
4317
|
-
*
|
|
4318
|
-
* @returns Array of verification results.
|
|
4319
|
-
*/
|
|
4320
|
-
verifySignatures(): Promise<SignatureVerificationResult[]>;
|
|
4321
|
-
/** The outline tree, lazily created. */
|
|
4322
|
-
private outlineTree;
|
|
4323
|
-
/**
|
|
4324
|
-
* Get the outline (bookmark) tree for this document.
|
|
4325
|
-
*
|
|
4326
|
-
* If no outlines have been added, returns an empty tree.
|
|
4327
|
-
*
|
|
4328
|
-
* @returns The {@link PdfOutlineTree} for this document.
|
|
4329
|
-
*/
|
|
4330
|
-
getOutlines(): PdfOutlineTree;
|
|
4331
|
-
/**
|
|
4332
|
-
* Add a top-level outline (bookmark) entry.
|
|
4333
|
-
*
|
|
4334
|
-
* Convenience method that creates or retrieves the outline tree and
|
|
4335
|
-
* adds a new item pointing to the specified page.
|
|
4336
|
-
*
|
|
4337
|
-
* @param title The display title for the bookmark.
|
|
4338
|
-
* @param pageIndex Zero-based page index to navigate to.
|
|
4339
|
-
* @param options Optional visual style and behaviour settings.
|
|
4340
|
-
* @returns The newly created {@link PdfOutlineItem}.
|
|
4341
|
-
*/
|
|
4342
|
-
addOutline(title: string, pageIndex: number, options?: OutlineItemOptions & {
|
|
4343
|
-
fit?: OutlineDestination['fit'];
|
|
4344
|
-
top?: number;
|
|
4345
|
-
left?: number;
|
|
4346
|
-
zoom?: number;
|
|
4347
|
-
}): PdfOutlineItem;
|
|
4348
|
-
/**
|
|
4349
|
-
* Replace the outline tree for this document.
|
|
4350
|
-
*
|
|
4351
|
-
* @param outlines The new outline tree.
|
|
4352
|
-
*/
|
|
4353
|
-
setOutlines(outlines: PdfOutlineTree): void;
|
|
4354
|
-
/** Raw XMP metadata string, if set. */
|
|
4355
|
-
private xmpMetadataString;
|
|
4356
|
-
/**
|
|
4357
|
-
* Get the raw XMP metadata string, or `undefined` if not set.
|
|
4358
|
-
*/
|
|
4359
|
-
getXmpMetadata(): string | undefined;
|
|
4360
|
-
/**
|
|
4361
|
-
* Set raw XMP metadata as an XML string.
|
|
4362
|
-
*
|
|
4363
|
-
* The string should be a valid XMP packet. Use
|
|
4364
|
-
* {@link buildXmpMetadata} from `modern-pdf` to generate one
|
|
4365
|
-
* from standard metadata fields.
|
|
4366
|
-
*
|
|
4367
|
-
* @param xmp The XMP XML string.
|
|
4368
|
-
*/
|
|
4369
|
-
setXmpMetadata(xmp: string): void;
|
|
4370
|
-
/** The document's structure tree (for tagged PDF), if created. */
|
|
4371
|
-
private structureTree;
|
|
4372
|
-
/** The document's natural language (BCP 47 tag, e.g. "en-US"). */
|
|
4373
|
-
private documentLanguage;
|
|
4374
|
-
/**
|
|
4375
|
-
* Get the structure tree for this document, or `undefined` if
|
|
4376
|
-
* no structure tree has been created.
|
|
4377
|
-
*
|
|
4378
|
-
* A structure tree is required for tagged PDF / PDF/UA compliance.
|
|
4379
|
-
*
|
|
4380
|
-
* @returns The {@link PdfStructureTree}, or `undefined`.
|
|
4381
|
-
*/
|
|
4382
|
-
getStructureTree(): PdfStructureTree | undefined;
|
|
4383
|
-
/**
|
|
4384
|
-
* Create a new structure tree for this document.
|
|
4385
|
-
*
|
|
4386
|
-
* If a structure tree already exists, it is returned as-is.
|
|
4387
|
-
* Call this to begin making the document accessible (tagged PDF).
|
|
4388
|
-
*
|
|
4389
|
-
* @returns The {@link PdfStructureTree} for this document.
|
|
4390
|
-
*/
|
|
4391
|
-
createStructureTree(): PdfStructureTree;
|
|
4392
|
-
/**
|
|
4393
|
-
* Set the document's natural language.
|
|
4394
|
-
*
|
|
4395
|
-
* This is required by PDF/UA and should be a BCP 47 language tag
|
|
4396
|
-
* (e.g. `"en"`, `"en-US"`, `"de-DE"`, `"ja"`).
|
|
4397
|
-
*
|
|
4398
|
-
* @param lang The BCP 47 language tag.
|
|
4399
|
-
*/
|
|
4400
|
-
setLanguage(lang: string): void;
|
|
4401
|
-
/**
|
|
4402
|
-
* Get the document's natural language, or `undefined` if not set.
|
|
4403
|
-
*
|
|
4404
|
-
* @returns The BCP 47 language tag, or `undefined`.
|
|
4405
|
-
*/
|
|
4406
|
-
getLanguage(): string | undefined;
|
|
4407
|
-
/**
|
|
4408
|
-
* Run accessibility checks on this document.
|
|
4409
|
-
*
|
|
4410
|
-
* Validates the document against PDF/UA requirements and general
|
|
4411
|
-
* accessibility best practices.
|
|
4412
|
-
*
|
|
4413
|
-
* @returns An array of {@link AccessibilityIssue} objects.
|
|
4414
|
-
*/
|
|
4415
|
-
checkAccessibility(): AccessibilityIssue[];
|
|
4416
|
-
/** Viewer preferences, if set. */
|
|
4417
|
-
private viewerPrefs;
|
|
4418
|
-
/** Cached PdfViewerPreferences instance. */
|
|
4419
|
-
private _viewerPrefsInstance?;
|
|
4420
|
-
/**
|
|
4421
|
-
* Get the viewer preferences for this document as a
|
|
4422
|
-
* {@link PdfViewerPreferences} instance with getter/setter pairs.
|
|
4423
|
-
*
|
|
4424
|
-
* If no preferences have been set, a default (empty) instance is
|
|
4425
|
-
* returned. The instance is cached so that repeated calls return
|
|
4426
|
-
* the same object and mutations are preserved.
|
|
4427
|
-
*/
|
|
4428
|
-
getViewerPreferences(): PdfViewerPreferences;
|
|
4429
|
-
/**
|
|
4430
|
-
* Set viewer preferences for this document.
|
|
4431
|
-
*
|
|
4432
|
-
* Controls how the document is displayed when opened in a PDF viewer
|
|
4433
|
-
* (toolbar visibility, window sizing, print options, etc.).
|
|
4434
|
-
*
|
|
4435
|
-
* Accepts either a plain {@link ViewerPreferences} object or a
|
|
4436
|
-
* {@link PdfViewerPreferences} class instance.
|
|
4437
|
-
*
|
|
4438
|
-
* @param prefs The viewer preferences to set.
|
|
4439
|
-
*/
|
|
4440
|
-
setViewerPreferences(prefs: ViewerPreferences | PdfViewerPreferences): void;
|
|
4441
|
-
/** The form instance, lazily created. */
|
|
4442
|
-
private form;
|
|
4443
|
-
/**
|
|
4444
|
-
* Check whether this document has an AcroForm (interactive form).
|
|
4445
|
-
*
|
|
4446
|
-
* Returns `true` if a form has been created or if the document
|
|
4447
|
-
* was loaded from a PDF that contains an /AcroForm dictionary.
|
|
4448
|
-
*/
|
|
4449
|
-
hasForm(): boolean;
|
|
4450
|
-
/**
|
|
4451
|
-
* Get the interactive form (AcroForm) for this document.
|
|
4452
|
-
*
|
|
4453
|
-
* If the document does not yet have a form, an empty one is created.
|
|
4454
|
-
* The form provides access to all form fields and supports fill,
|
|
4455
|
-
* flatten, and field creation operations.
|
|
4456
|
-
*
|
|
4457
|
-
* @returns The {@link PdfForm} for this document.
|
|
4458
|
-
*/
|
|
4459
|
-
getForm(): PdfForm;
|
|
4460
|
-
/**
|
|
4461
|
-
* Set the form for this document (used when loading parsed PDFs).
|
|
4462
|
-
* @internal
|
|
4463
|
-
*/
|
|
4464
|
-
setForm(form: PdfForm): void;
|
|
4465
|
-
/**
|
|
4466
|
-
* Draw an SVG image onto a page.
|
|
4467
|
-
*
|
|
4468
|
-
* @param pageIndex Zero-based page index.
|
|
4469
|
-
* @param svgString The SVG markup string.
|
|
4470
|
-
* @param options Rendering options (position, size).
|
|
4471
|
-
*/
|
|
4472
|
-
drawSvg(pageIndex: number, svgString: string, options?: SvgRenderOptions): void;
|
|
4473
|
-
/** The layer manager, lazily created. */
|
|
4474
|
-
private layerManager;
|
|
4475
|
-
/**
|
|
4476
|
-
* Add a new optional content layer.
|
|
4477
|
-
*
|
|
4478
|
-
* @param name The display name for the layer.
|
|
4479
|
-
* @param visible Whether the layer is visible by default.
|
|
4480
|
-
* @returns The newly created {@link PdfLayer}.
|
|
4481
|
-
*/
|
|
4482
|
-
addLayer(name: string, visible?: boolean): PdfLayer;
|
|
4483
|
-
/**
|
|
4484
|
-
* Get all layers in this document.
|
|
4485
|
-
*
|
|
4486
|
-
* @returns An array of {@link PdfLayer} objects.
|
|
4487
|
-
*/
|
|
4488
|
-
getLayers(): PdfLayer[];
|
|
4489
|
-
/** Attached file references. */
|
|
4490
|
-
private readonly attachedFiles;
|
|
4491
|
-
/** Document-level JavaScript actions — maps name → script source. */
|
|
4492
|
-
private readonly javaScripts;
|
|
4493
|
-
/**
|
|
4494
|
-
* Attach a file to this PDF document.
|
|
4495
|
-
*
|
|
4496
|
-
* @param name File name.
|
|
4497
|
-
* @param data File data.
|
|
4498
|
-
* @param mimeType MIME type string.
|
|
4499
|
-
* @param options Optional description.
|
|
4500
|
-
*/
|
|
4501
|
-
attachFile(name: string, data: Uint8Array, mimeType: string, options?: {
|
|
4502
|
-
description?: string | undefined;
|
|
4503
|
-
}): void;
|
|
4504
|
-
/**
|
|
4505
|
-
* Get all file attachments in this document.
|
|
4506
|
-
*
|
|
4507
|
-
* Note: Currently returns information about files attached via
|
|
4508
|
-
* this API. For parsing attachments from loaded PDFs, use the
|
|
4509
|
-
* lower-level `getAttachments()` function.
|
|
4510
|
-
*
|
|
4511
|
-
* @returns An array of embedded file metadata.
|
|
4512
|
-
*/
|
|
4513
|
-
getAttachments(): EmbeddedFile[];
|
|
4514
|
-
/**
|
|
4515
|
-
* Add a document-level JavaScript action.
|
|
4516
|
-
*
|
|
4517
|
-
* The script is registered in the catalog's `/Names` dictionary under
|
|
4518
|
-
* the `/JavaScript` name tree. When a conforming viewer opens the
|
|
4519
|
-
* document, scripts listed here are executed automatically (in name
|
|
4520
|
-
* order).
|
|
4521
|
-
*
|
|
4522
|
-
* @param name A unique name for this JavaScript entry.
|
|
4523
|
-
* @param script The JavaScript source code.
|
|
4524
|
-
*
|
|
4525
|
-
* @example
|
|
4526
|
-
* ```ts
|
|
4527
|
-
* doc.addJavaScript('init', 'app.alert("Hello from PDF JavaScript!");');
|
|
4528
|
-
* ```
|
|
4529
|
-
*/
|
|
4530
|
-
addJavaScript(name: string, script: string): void;
|
|
4531
|
-
/**
|
|
4532
|
-
* Add a text watermark to all pages in the document.
|
|
4533
|
-
*
|
|
4534
|
-
* @param options Watermark appearance options.
|
|
4535
|
-
*/
|
|
4536
|
-
addWatermark(options: WatermarkOptions): void;
|
|
4537
|
-
/**
|
|
4538
|
-
* Create a soft mask Form XObject that can be used with
|
|
4539
|
-
* {@link PdfPage.applySoftMask}.
|
|
4540
|
-
*
|
|
4541
|
-
* The builder callback receives a {@link SoftMaskBuilder} with methods
|
|
4542
|
-
* for generating grayscale content where white (`1`) represents fully
|
|
4543
|
-
* opaque regions and black (`0`) represents fully transparent regions.
|
|
4544
|
-
*
|
|
4545
|
-
* The returned {@link SoftMaskRef} is passed to
|
|
4546
|
-
* {@link PdfPage.applySoftMask} to activate the mask for subsequent
|
|
4547
|
-
* drawing operations on that page.
|
|
4548
|
-
*
|
|
4549
|
-
* @param width Width of the mask in points.
|
|
4550
|
-
* @param height Height of the mask in points.
|
|
4551
|
-
* @param builder Callback that draws the mask content.
|
|
4552
|
-
* @returns A reference to the soft mask Form XObject.
|
|
4553
|
-
*
|
|
4554
|
-
* @example
|
|
4555
|
-
* ```ts
|
|
4556
|
-
* const mask = doc.createSoftMask(200, 200, (b) => {
|
|
4557
|
-
* // White background = fully opaque
|
|
4558
|
-
* b.drawRectangle(0, 0, 200, 200, 1);
|
|
4559
|
-
* // Black circle = fully transparent hole
|
|
4560
|
-
* b.drawCircle(100, 100, 80, 0);
|
|
4561
|
-
* });
|
|
4562
|
-
* page.applySoftMask(mask);
|
|
4563
|
-
* page.drawRectangle({ x: 50, y: 50, width: 200, height: 200, color: rgb(1, 0, 0) });
|
|
4564
|
-
* page.clearSoftMask();
|
|
4565
|
-
* ```
|
|
4566
|
-
*/
|
|
4567
|
-
createSoftMask(width: number, height: number, builder: (ops: SoftMaskBuilder) => void): SoftMaskRef;
|
|
4568
|
-
/**
|
|
4569
|
-
* Apply all pending redactions across all pages.
|
|
4570
|
-
*
|
|
4571
|
-
* Redaction marks are added to individual pages using
|
|
4572
|
-
* `page.markForRedaction()`. This method draws the redaction
|
|
4573
|
-
* rectangles on all pages that have pending marks.
|
|
4574
|
-
*/
|
|
4575
|
-
applyRedactions(): void;
|
|
4576
|
-
/**
|
|
4577
|
-
* Create an independent deep copy of this document.
|
|
4578
|
-
*
|
|
4579
|
-
* The copy is produced by serializing the document to bytes and then
|
|
4580
|
-
* re-parsing those bytes. This guarantees that the returned
|
|
4581
|
-
* `PdfDocument` is completely independent — mutations to the copy
|
|
4582
|
-
* do not affect the original, and vice versa.
|
|
4583
|
-
*
|
|
4584
|
-
* @returns A new `PdfDocument` that is a deep copy of this one.
|
|
4585
|
-
*
|
|
4586
|
-
* @example
|
|
4587
|
-
* ```ts
|
|
4588
|
-
* const doc = createPdf();
|
|
4589
|
-
* doc.addPage(PageSizes.A4);
|
|
4590
|
-
* const clone = await doc.copy();
|
|
4591
|
-
* clone.addPage(PageSizes.Letter); // does not affect `doc`
|
|
4592
|
-
* ```
|
|
4593
|
-
*/
|
|
4594
|
-
copy(): Promise<PdfDocument>;
|
|
4595
|
-
/**
|
|
4596
|
-
* Serialize the document to a `Uint8Array`.
|
|
4597
|
-
*
|
|
4598
|
-
* @param options Compression and serialization options.
|
|
4599
|
-
* @returns The complete PDF file as bytes.
|
|
4600
|
-
*/
|
|
4601
|
-
save(options?: PdfSaveOptions): Promise<Uint8Array>;
|
|
4602
|
-
/**
|
|
4603
|
-
* Serialize the document as a `ReadableStream<Uint8Array>`.
|
|
4604
|
-
*
|
|
4605
|
-
* Ideal for streaming responses in edge/serverless environments.
|
|
4606
|
-
*
|
|
4607
|
-
* @param options Compression and serialization options.
|
|
4608
|
-
*/
|
|
4609
|
-
saveAsStream(options?: PdfSaveOptions): ReadableStream<Uint8Array>;
|
|
4610
|
-
/**
|
|
4611
|
-
* Serialize the document to a `Blob`.
|
|
4612
|
-
*
|
|
4613
|
-
* Convenient for client-side download links.
|
|
4614
|
-
*
|
|
4615
|
-
* @param options Compression and serialization options.
|
|
4616
|
-
*/
|
|
4617
|
-
saveAsBlob(options?: PdfSaveOptions): Promise<Blob>;
|
|
4618
|
-
/**
|
|
4619
|
-
* Serialize the document to a Base64-encoded string.
|
|
4620
|
-
*
|
|
4621
|
-
* Useful for embedding PDFs in JSON payloads, data URIs, or
|
|
4622
|
-
* transferring over text-only channels.
|
|
4623
|
-
*
|
|
4624
|
-
* @param options Standard save options plus an optional `dataUri`
|
|
4625
|
-
* flag. When `dataUri` is `true`, the returned
|
|
4626
|
-
* string is prefixed with
|
|
4627
|
-
* `data:application/pdf;base64,`.
|
|
4628
|
-
* @returns A Base64-encoded string of the PDF bytes.
|
|
4629
|
-
*
|
|
4630
|
-
* @example
|
|
4631
|
-
* ```ts
|
|
4632
|
-
* const b64 = await doc.saveAsBase64();
|
|
4633
|
-
* const dataUri = await doc.saveAsBase64({ dataUri: true });
|
|
4634
|
-
* // dataUri === "data:application/pdf;base64,JVBERi0..."
|
|
4635
|
-
* ```
|
|
4636
|
-
*/
|
|
4637
|
-
saveAsBase64(options?: PdfSaveOptions & {
|
|
4638
|
-
dataUri?: boolean;
|
|
4639
|
-
}): Promise<string>;
|
|
4640
|
-
/**
|
|
4641
|
-
* Finalize all pages and build the catalog / page tree / info dict.
|
|
4642
|
-
*/
|
|
4643
|
-
private buildStructure;
|
|
4644
|
-
/**
|
|
4645
|
-
* Subset all embedded TrueType fonts.
|
|
4646
|
-
*
|
|
4647
|
-
* Called at save time, after all text has been drawn. For each TTF
|
|
4648
|
-
* font, this:
|
|
4649
|
-
* 1. Calls {@link subsetFont} with the used glyph set
|
|
4650
|
-
* 2. Updates the `/FontFile2` stream data with the (possibly subsetted) font bytes
|
|
4651
|
-
* 3. Updates the `/Length1` in the font file dict
|
|
4652
|
-
* 4. Rebuilds the `/W` (widths) array for the CIDFont dict
|
|
4653
|
-
* 5. Rebuilds the `/ToUnicode` CMap stream
|
|
4654
|
-
*
|
|
4655
|
-
* Since WASM subsetting is not yet available, the fallback returns
|
|
4656
|
-
* the full font unchanged. But the /W array and /ToUnicode CMap
|
|
4657
|
-
* are rebuilt to only include used glyphs, reducing PDF overhead.
|
|
4658
|
-
*
|
|
4659
|
-
* @internal
|
|
4660
|
-
*/
|
|
4661
|
-
private subsetTtfFonts;
|
|
4662
|
-
}
|
|
4663
|
-
/**
|
|
4664
|
-
* Create a new, empty PDF document.
|
|
4665
|
-
*
|
|
4666
|
-
* ```ts
|
|
4667
|
-
* const doc = createPdf();
|
|
4668
|
-
* ```
|
|
4669
|
-
*/
|
|
4670
|
-
declare function createPdf(): PdfDocument;
|
|
4671
|
-
//#endregion
|
|
4672
|
-
export { DrawLineOptions as $, colorToComponents as $n, PdfLayerManager as $t, EncryptAlgorithm as A, Angle as An, ColorStop as At, serializePdf as B, rotationMatrix as Bn, linearGradient as Bt, ViewerPreferences as C, BlendMode as Cn, renderMultiPageTable as Ct, OutlineItemOptions as D, ParseSpeeds as Dn, QrCodeOptions as Dt, OutlineDestination as E, LineJoinStyle as En, QrCodeMatrix as Et, encodePermissions as F, degreesToRadians as Fn, RadialGradientFill as Ft, buildCatalog as G, translate as Gn, EmbeddedPdfPage as Gt, DocumentMetadata as H, scale as Hn, tilingPattern as Ht, LoadPdfOptions as I, radians as In, RadialGradientOptions as It, buildPageTree as J, GrayscaleColor as Jn, RedactionOptions as Jt, buildDocumentStructure as K, CmykColor as Kn, embedPageAsFormXObject as Kt, loadPdf as L, radiansToDegrees as Ln, TilingPatternOptions as Lt, PdfEncryptionHandler as M, Radians as Mn, LinearGradientOptions as Mt, PdfPermissionFlags as N, concatMatrix as Nn, NormalizedStop as Nt, PdfOutlineItem as O, TextAlignment as On, encodeQrCode as Ot, decodePermissions as P, degrees as Pn, PatternFill as Pt, DrawImageOptions as Q, cmyk as Qn, PdfLayer as Qt, PdfSaveOptions as R, restoreState as Rn, buildGradientObjects as Rt, PdfViewerPreferences as S, StructureType as Sn, TextRun as St, parseViewerPreferences as T, LineCapStyle as Tn, ErrorCorrectionLevel as Tt, DocumentStructure as U, setGraphicsState as Un, DrawPageOptions as Ut, CatalogOptions as V, saveState as Vn, radialGradient as Vt, PageEntry as W, skew as Wn, EmbedPageOptions as Wt, DrawCircleOptions as X, applyFillColor as Xn, getRedactionMarks as Xt, formatPdfDate as Y, RgbColor as Yn, applyRedactions as Yt, DrawEllipseOptions as Z, applyStrokeColor as Zn, markForRedaction as Zt, PdfSignatureInfo as _, createAnnotation as _n, PageContent as _t, StandardFonts as a, SvgDrawCommand as an, setFillColorCmyk as ar, FontRef as at, getSignatures as b, PdfStructureTree as bn, TableRenderResult as bt, verifySignature as c, parseSvgColor as cn, setFillingColor as cr, PageSizes as ct, addWatermark as d, AnnotationFlags as dn, setStrokeColorGray as dr, SoftMaskRef as dt, beginLayerContent as en, componentsToColor as er, DrawQrCodeOptions as et, addWatermarkToPage as f, AnnotationOptions as fn, setStrokeColorRgb as fr, TransparencyGroupOptions as ft, getAttachments as g, buildAnnotationDict as gn, NestedTableContent as gt, buildEmbeddedFilesNameTree as h, annotationFromDict as hn, MultiPageTableResult as ht, StandardFontName as i, svgToPdfOperators as in, setFillColor as ir, DrawTextOptions as it, EncryptOptions as j, Degrees as jn, GradientFill as jt, PdfOutlineTree as k, TextRenderingMode as kn, qrCodeToOperators as kt, verifySignatures as l, parseSvgPath as ln, setStrokeColor as lr, PdfPage as lt, attachFile as m, PdfAnnotation as mn, setStrokingColor as mr, DrawTableOptions as mt, PdfDocument as n, SvgRenderOptions as nn, rgb as nr, DrawSquareOptions as nt, createPdf as o, SvgElement as on, setFillColorGray as or, ImageRef as ot, EmbeddedFile as p, AnnotationType as pn, setStrokeColorSpace as pr, CellContent as pt, buildInfoDict as q, Color as qn, RedactionMark as qt, SetTitleOptions as r, drawSvgOnPage as rn, setColorSpace as rr, DrawSvgPathOptions as rt, SignatureVerificationResult as s, parseSvg as sn, setFillColorRgb as sr, PageSize as st, EmbedFontOptions as t, endLayerContent as tn, grayscale as tr, DrawRectangleOptions as tt, WatermarkOptions as u, parseSvgTransform as un, setStrokeColorCmyk as ur, SoftMaskBuilder as ut, SignOptions as v, AccessibilityIssue as vn, TableCell as vt, buildViewerPreferencesDict as w, ImageAlignment as wn, renderTable as wt, signPdf as x, StructureElementOptions as xn, TableRow as xt, VisibleSignatureOptions as y, PdfStructureElement as yn, TableColumn as yt, PdfWriter as z, rotate as zn, buildPatternObjects as zt };
|
|
4673
|
-
//# sourceMappingURL=pdfDocument-BgvEP5Po.d.mts.map
|