@kittl/pdfkit 0.17.3 → 0.17.5

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.
@@ -0,0 +1,1160 @@
1
+ /// <reference types="node" />
2
+
3
+ declare namespace PDFKit {
4
+ interface PDFGradient {
5
+ new(document: any): PDFGradient;
6
+ stop(pos: number, color?: string | PDFKit.PDFGradient, opacity?: number): PDFGradient;
7
+ embed(): void;
8
+ apply(): void;
9
+ }
10
+
11
+ interface PDFLinearGradient extends PDFGradient {
12
+ new(document: any, x1: number, y1: number, x2: number, y2: number): PDFLinearGradient;
13
+ shader(fn: () => any): any;
14
+ opacityGradient(): PDFLinearGradient;
15
+ }
16
+
17
+ interface PDFRadialGradient extends PDFGradient {
18
+ new(document: any, x1: number, y1: number, x2: number, y2: number): PDFRadialGradient;
19
+ shader(fn: () => any): any;
20
+ opacityGradient(): PDFRadialGradient;
21
+ }
22
+
23
+ interface PDFTilingPattern {
24
+ new(
25
+ document: any,
26
+ bbox: PDFKit.Mixins.BoundingBox,
27
+ xStep: number,
28
+ yStep: number,
29
+ stream: string,
30
+ ): PDFTilingPattern;
31
+ createPattern(): PDFKitReference;
32
+ embedPatternColorSpaces(): void;
33
+ getPatternColorSpaceId(underlyingColorspace: string): string;
34
+ embed(): void;
35
+ apply(stroke: boolean, patternColor: PDFKit.Mixins.TilingPatternColorValue): PDFKit.PDFDocument;
36
+ }
37
+
38
+ interface PDFICCProfile {
39
+ label: string;
40
+ data: Uint8Array | Buffer;
41
+ channels: number;
42
+ alternate: string | string[];
43
+ }
44
+ }
45
+
46
+ declare namespace PDFKit.Mixins {
47
+ interface AnnotationOption {
48
+ Type?: string | undefined;
49
+ Rect?: any;
50
+ Border?: number[] | undefined;
51
+ SubType?: string | undefined;
52
+ Contents?: string | undefined;
53
+ Name?: string | undefined;
54
+ color?: string | undefined;
55
+ QuadPoints?: number[] | undefined;
56
+
57
+ A?: any;
58
+ B?: any;
59
+ C?: any;
60
+ L?: any;
61
+ DA?: string | undefined;
62
+ }
63
+
64
+ interface PDFAnnotation {
65
+ annotate(x: number, y: number, w: number, h: number, option: AnnotationOption): this;
66
+ note(x: number, y: number, w: number, h: number, content: string, option?: AnnotationOption): this;
67
+ goTo(x: number, y: number, w: number, h: number, name: string, options?: AnnotationOption): this;
68
+ link(x: number, y: number, w: number, h: number, url: string, option?: AnnotationOption): this;
69
+ highlight(x: number, y: number, w: number, h: number, option?: AnnotationOption): this;
70
+ underline(x: number, y: number, w: number, h: number, option?: AnnotationOption): this;
71
+ strike(x: number, y: number, w: number, h: number, option?: AnnotationOption): this;
72
+ lineAnnotation(x1: number, y1: number, x2: number, y2: number, option?: AnnotationOption): this;
73
+ rectAnnotation(x: number, y: number, w: number, h: number, option?: AnnotationOption): this;
74
+ ellipseAnnotation(x: number, y: number, w: number, h: number, option?: AnnotationOption): this;
75
+ textAnnotation(x: number, y: number, w: number, h: number, text: string, option?: AnnotationOption): this;
76
+ }
77
+
78
+ interface PDFAttachmentOptions {
79
+ name?: string;
80
+ type?: string;
81
+ description?: string;
82
+ hidden?: boolean;
83
+ creationDate?: Date;
84
+ modifiedDate?: Date;
85
+ }
86
+
87
+ interface PDFAttachment {
88
+ /**
89
+ * Embed content of `src` in PDF
90
+ */
91
+ file(src: Buffer | ArrayBuffer | string, options?: PDFAttachmentOptions): this;
92
+ }
93
+
94
+ // The color forms accepted by PDFKit:
95
+ // example: "red" [R, G, B] [C, M, Y, K]
96
+ type ColorValue = string | PDFGradient | [PDFTilingPattern, TilingPatternColorValue] | [number, number, number] | [
97
+ number,
98
+ number,
99
+ number,
100
+ number,
101
+ ];
102
+
103
+ // The color forms accepted by PDFKit Tiling Pattern:
104
+ // example: "red" [R, G, B] [C, M, Y, K]
105
+ type TilingPatternColorValue = string | PDFGradient | [number, number, number] | [number, number, number, number];
106
+
107
+ // The winding / filling rule accepted by PDFKit:
108
+ type RuleValue = "even-odd" | "evenodd" | "non-zero" | "nonzero";
109
+
110
+ // Text option opentype features as listed at https://docs.microsoft.com/en-us/typography/opentype/spec/featurelist
111
+ type OpenTypeFeatures =
112
+ | "aalt"
113
+ | "abvf"
114
+ | "abvm"
115
+ | "abvs"
116
+ | "afrc"
117
+ | "akhn"
118
+ | "blwf"
119
+ | "blwm"
120
+ | "blws"
121
+ | "calt"
122
+ | "case"
123
+ | "cfar"
124
+ | "cjct"
125
+ | "clig"
126
+ | "cpct"
127
+ | "cpsp"
128
+ | "cswh"
129
+ | "curs"
130
+ | "cv01"
131
+ | "cv02"
132
+ | "cv03"
133
+ | "cv04"
134
+ | "cv05"
135
+ | "cv06"
136
+ | "cv07"
137
+ | "cv08"
138
+ | "cv09"
139
+ | "cv10"
140
+ | "cv11"
141
+ | "cv12"
142
+ | "cv13"
143
+ | "cv14"
144
+ | "cv15"
145
+ | "cv16"
146
+ | "cv17"
147
+ | "cv18"
148
+ | "cv19"
149
+ | "cv20"
150
+ | "cv21"
151
+ | "cv22"
152
+ | "cv23"
153
+ | "cv24"
154
+ | "cv25"
155
+ | "cv26"
156
+ | "cv27"
157
+ | "cv28"
158
+ | "cv29"
159
+ | "cv30"
160
+ | "cv31"
161
+ | "cv32"
162
+ | "cv33"
163
+ | "cv34"
164
+ | "cv35"
165
+ | "cv36"
166
+ | "cv37"
167
+ | "cv38"
168
+ | "cv39"
169
+ | "cv40"
170
+ | "cv41"
171
+ | "cv42"
172
+ | "cv43"
173
+ | "cv44"
174
+ | "cv45"
175
+ | "cv46"
176
+ | "cv47"
177
+ | "cv48"
178
+ | "cv49"
179
+ | "cv50"
180
+ | "cv51"
181
+ | "cv52"
182
+ | "cv53"
183
+ | "cv54"
184
+ | "cv55"
185
+ | "cv56"
186
+ | "cv57"
187
+ | "cv58"
188
+ | "cv59"
189
+ | "cv60"
190
+ | "cv61"
191
+ | "cv62"
192
+ | "cv63"
193
+ | "cv64"
194
+ | "cv65"
195
+ | "cv66"
196
+ | "cv67"
197
+ | "cv68"
198
+ | "cv69"
199
+ | "cv70"
200
+ | "cv71"
201
+ | "cv72"
202
+ | "cv73"
203
+ | "cv74"
204
+ | "cv75"
205
+ | "cv76"
206
+ | "cv77"
207
+ | "cv78"
208
+ | "cv79"
209
+ | "cv80"
210
+ | "cv81"
211
+ | "cv82"
212
+ | "cv83"
213
+ | "cv84"
214
+ | "cv85"
215
+ | "cv86"
216
+ | "cv87"
217
+ | "cv88"
218
+ | "cv89"
219
+ | "cv90"
220
+ | "cv91"
221
+ | "cv92"
222
+ | "cv93"
223
+ | "cv94"
224
+ | "cv95"
225
+ | "cv96"
226
+ | "cv97"
227
+ | "cv98"
228
+ | "cv99"
229
+ | "c2pc"
230
+ | "c2sc"
231
+ | "dist"
232
+ | "ccmp"
233
+ | "dlig"
234
+ | "dnom"
235
+ | "dtls"
236
+ | "expt"
237
+ | "falt"
238
+ | "fin2"
239
+ | "fin3"
240
+ | "fina"
241
+ | "flac"
242
+ | "frac"
243
+ | "fwid"
244
+ | "half"
245
+ | "haln"
246
+ | "halt"
247
+ | "hist"
248
+ | "hkna"
249
+ | "hlig"
250
+ | "hngl"
251
+ | "hojo"
252
+ | "hwid"
253
+ | "init"
254
+ | "isol"
255
+ | "ital"
256
+ | "jalt"
257
+ | "jp78"
258
+ | "jp83"
259
+ | "jp90"
260
+ | "jp04"
261
+ | "kern"
262
+ | "lfbd"
263
+ | "liga"
264
+ | "ljmo"
265
+ | "lnum"
266
+ | "locl"
267
+ | "ltra"
268
+ | "ltrm"
269
+ | "mark"
270
+ | "med2"
271
+ | "medi"
272
+ | "mgrk"
273
+ | "mkmk"
274
+ | "mset"
275
+ | "nalt"
276
+ | "nlck"
277
+ | "nukt"
278
+ | "numr"
279
+ | "onum"
280
+ | "opbd"
281
+ | "ordn"
282
+ | "ornm"
283
+ | "palt"
284
+ | "pcap"
285
+ | "pkna"
286
+ | "pnum"
287
+ | "pref"
288
+ | "pres"
289
+ | "pstf"
290
+ | "psts"
291
+ | "pwid"
292
+ | "qwid"
293
+ | "rand"
294
+ | "rclt"
295
+ | "rkrf"
296
+ | "rlig"
297
+ | "rphf"
298
+ | "rtbd"
299
+ | "rtla"
300
+ | "rtlm"
301
+ | "ruby"
302
+ | "rvrn"
303
+ | "salt"
304
+ | "sinf"
305
+ | "size"
306
+ | "smcp"
307
+ | "smpl"
308
+ | "ss01"
309
+ | "ss02"
310
+ | "ss03"
311
+ | "ss04"
312
+ | "ss05"
313
+ | "ss06"
314
+ | "ss07"
315
+ | "ss08"
316
+ | "ss09"
317
+ | "ss10"
318
+ | "ss11"
319
+ | "ss12"
320
+ | "ss13"
321
+ | "ss14"
322
+ | "ss15"
323
+ | "ss16"
324
+ | "ss17"
325
+ | "ss18"
326
+ | "ss19"
327
+ | "ss20"
328
+ | "ssty"
329
+ | "stch"
330
+ | "subs"
331
+ | "sups"
332
+ | "swsh"
333
+ | "titl"
334
+ | "tjmo"
335
+ | "tnam"
336
+ | "tnum"
337
+ | "trad"
338
+ | "twid"
339
+ | "unic"
340
+ | "valt"
341
+ | "vatu"
342
+ | "vert"
343
+ | "vhal"
344
+ | "vjmo"
345
+ | "vkna"
346
+ | "vkrn"
347
+ | "vpal"
348
+ | "vrt2"
349
+ | "vrtr"
350
+ | "zero";
351
+
352
+ type BoundingBox = [number, number, number, number];
353
+
354
+ type SizeUnits =
355
+ | "em"
356
+ | "in"
357
+ | "px"
358
+ | "cm"
359
+ | "mm"
360
+ | "pc"
361
+ | "ex"
362
+ | "ch"
363
+ | "rem"
364
+ | "vw"
365
+ | "vmin"
366
+ | "vmax"
367
+ | "%"
368
+ | "pt";
369
+
370
+ type Size = number | `${number}` | `${number}${SizeUnits}`;
371
+
372
+ type Wideness = Size | boolean;
373
+
374
+ type Sides<T> = T | [T, T] | [T, T, T, T] | SlightlyExpandedSides<T> | ExpandedSides<T>;
375
+
376
+ type PartialSides<T> = T | [T, T] | [T, T, T, T] | Partial<SlightlyExpandedSides<T>> | Partial<ExpandedSides<T>>;
377
+
378
+ interface SlightlyExpandedSides<T> {
379
+ vertical: T;
380
+ horizontal: T;
381
+ }
382
+
383
+ interface ExpandedSides<T> {
384
+ top: T;
385
+ right: T;
386
+ bottom: T;
387
+ left: T;
388
+ }
389
+
390
+ interface PDFColor {
391
+ beginColorSpace(label: string): this;
392
+ endColorSpace(): this;
393
+ fillColor(color: ColorValue, opacity?: number): this;
394
+ strokeColor(color: ColorValue, opacity?: number): this;
395
+ opacity(opacity: number): this;
396
+ fillOpacity(opacity: number): this;
397
+ strokeOpacity(opacity: number): this;
398
+ linearGradient(x1: number, y1: number, x2: number, y2: number): PDFLinearGradient;
399
+ radialGradient(x1: number, y1: number, r1: number, x2: number, y2: number, r2: number): PDFRadialGradient;
400
+ pattern(bbox: BoundingBox, xStep: number, yStep: number, stream: string): PDFTilingPattern;
401
+ }
402
+
403
+ type PDFFontSource = string | Buffer | Uint8Array | ArrayBuffer;
404
+
405
+ interface PDFFont {
406
+ font(src: PDFFontSource, size?: number): this;
407
+ font(src: PDFFontSource, family: string, size?: number): this;
408
+ fontSize(size: number): this;
409
+ sizeToPoint(size: Size, defaultValue?: number, page?: PDFPage, percentageWidth?: number): number;
410
+ currentLineHeight(includeGap?: boolean): number;
411
+ /** Helpful method to give a font an alias, eg: `registerFont('bold', './Roboto.ttf')` */
412
+ registerFont(
413
+ name: string,
414
+ src?: PDFFontSource,
415
+ /** Only specify family if the font type is `TTC` or `DFont` */
416
+ family?: string,
417
+ ): this;
418
+ }
419
+
420
+ type ImageSrc = Buffer | ArrayBuffer | string;
421
+
422
+ interface ImageOption {
423
+ width?: number | undefined;
424
+ height?: number | undefined;
425
+ /** Scale percentage */
426
+ scale?: number | undefined;
427
+ /** Two elements array specifying dimensions(w,h) */
428
+ fit?: [number, number] | undefined;
429
+ cover?: [number, number] | undefined;
430
+ align?: "center" | "right" | undefined;
431
+ valign?: "center" | "bottom" | undefined;
432
+ link?: string | AnnotationOption | undefined;
433
+ goTo?: AnnotationOption | undefined;
434
+ destination?: string | undefined;
435
+ }
436
+
437
+ interface PDFImage {
438
+ /**
439
+ * Draw an image in PDFKit document.
440
+ *
441
+ * Warning: If string 'src' is provided, the file will be loaded synchronously using `fs.readFileSync(src)`!
442
+ */
443
+ image(src: ImageSrc, x?: number, y?: number, options?: ImageOption): this;
444
+ image(src: ImageSrc, options?: ImageOption): this;
445
+ }
446
+
447
+ interface CellStyle {
448
+ /** The text stroke (default 0) */
449
+ textStroke?: number | boolean;
450
+ /** Sets the text stroke color of the cells text (default black) */
451
+ textStrokeColor?: ColorValue;
452
+ /** Sets the text color of the cells text (default black) */
453
+ textColor?: ColorValue;
454
+ /** The border for the cell (default 1pt) */
455
+ border?: PartialSides<Wideness> | undefined;
456
+ /** The border colors for the cell (default black) */
457
+ borderColor?: PartialSides<ColorValue>;
458
+ /** Set the background color of the cell */
459
+ backgroundColor?: ColorValue;
460
+ /** The padding for the cell (default 0.25em) */
461
+ padding?: Sides<Wideness>;
462
+ /** The alignment of the cell text (default {x: 'left', y: 'top'}) */
463
+ align?: "center" | ExpandedAlign;
464
+ /** Sets any text options you wish to provide (such as rotation) */
465
+ textOptions?: TextOptions;
466
+ /** Whether to show the debug lines for the cell (default false) */
467
+ debug?: boolean;
468
+ }
469
+
470
+ interface TableOptions {
471
+ /** The position of the table (default {x: doc.x, y: doc.y}) */
472
+ position?: { x?: number; y?: number };
473
+ /** The maximum width the table can expand to (defaults to the remaining content width (offset from the tables position)) */
474
+ maxWidth?: number;
475
+ /** Column definitions of the table. (default auto) */
476
+ columnStyles?:
477
+ | number
478
+ | Array<number | string | ColumnStyle>
479
+ | ColumnStyle
480
+ | ((row: number) => number | ColumnStyle | undefined);
481
+ /** Row definitions of the table. (default *) */
482
+ rowStyles?:
483
+ | number
484
+ | Array<number | string | RowStyle>
485
+ | RowStyle
486
+ | ((row: number) => number | RowStyle | undefined);
487
+ /** Defaults to apply to every cell */
488
+ defaultStyle?:
489
+ & (
490
+ | number
491
+ | Array<number | string>
492
+ | CellStyle
493
+ | ((row: number) => number | CellStyle | undefined)
494
+ )
495
+ & { width?: number };
496
+ /** Whether to show the debug lines for all the cells (default false) */
497
+ debug?: boolean;
498
+ }
499
+
500
+ interface TableOptionsWithData extends TableOptions {
501
+ /** The data to render (not required, you can call .row()). This can be an iterable (async or sync) */
502
+ data: Array<Array<string | CellOptions>>;
503
+ }
504
+
505
+ interface ExpandedAlign {
506
+ x?: "left" | "center" | "right" | "justify";
507
+ y?: "top" | "center" | "bottom";
508
+ }
509
+
510
+ interface CellOptions extends CellStyle {
511
+ /** The value, will be cast to a string (null and undefined are not rendered but the cell is still outlined) */
512
+ text?: string | undefined | null;
513
+ /** How many rows this cell covers, follows the same logic as HTML rowspan */
514
+ rowSpan?: number;
515
+ /** How many columns this cell covers, follows the same logic as HTML colspan */
516
+ colSpan?: number;
517
+ /** Font options for the cell */
518
+ font?: { src?: PDFFontSource; family?: string; size?: number };
519
+ /** Sets the cell type (for accessibility) (default TD) */
520
+ type?: "TD" | "TH";
521
+ }
522
+
523
+ interface ColumnStyle extends CellStyle {
524
+ /** The width of the column (default *) */
525
+ width?: string | number;
526
+ /** The minimum width of the column (default 0) */
527
+ minWidth?: string | number;
528
+ /** The maximum width of the column (default Infinity) */
529
+ maxWidth?: string | number;
530
+ }
531
+
532
+ interface RowBase {
533
+ /** The height of the row (default auto) */
534
+ height?: string | number;
535
+ /** The minimum height of the row (default 0) */
536
+ minHeight?: string | number;
537
+ /** The maximum height of the row (default Infinity) */
538
+ maxHeight?: string | number;
539
+ }
540
+
541
+ interface RowStyle extends CellStyle, RowBase {}
542
+
543
+ interface RowOptions extends CellOptions, RowBase {}
544
+
545
+ interface PDFTableObject {
546
+ /** Add a row of data (null and undefined are not rendered) */
547
+ row(data: Array<string | undefined | null | RowOptions>): this;
548
+ /** Indicates to the table that it is finished, allowing the table to flush its cell buffer (which should be empty unless there is rowSpans) */
549
+ end(): PDFDocument;
550
+ }
551
+
552
+ interface PDFTable {
553
+ /** Draw a table in PDFKit document. */
554
+ table(options?: TableOptions): PDFTableObject;
555
+ /** Draw a table in PDFKit document. */
556
+ table(options: TableOptionsWithData): PDFDocument;
557
+ }
558
+
559
+ interface TextOptions {
560
+ /** Set to false to disable line wrapping all together */
561
+ lineBreak?: boolean | undefined;
562
+ /** The width that text should be wrapped to (by default, the page width minus the left and right margin) */
563
+ width?: number | undefined;
564
+ /** The maximum height that text should be clipped to */
565
+ height?: number | undefined;
566
+ /** The character to display at the end of the text when it is too long. Set to true to use the default character. */
567
+ ellipsis?: boolean | string | undefined;
568
+ /** The number of columns to flow the text into */
569
+ columns?: number | undefined;
570
+ /** The amount of space between each column (1/4 inch by default) */
571
+ columnGap?: number | undefined;
572
+ /** The amount in PDF points (72 per inch) to indent each paragraph of text */
573
+ indent?: number | undefined;
574
+ /** Whether to indent all lines of a paragraph */
575
+ indentAllLines?: boolean | undefined;
576
+ /** The amount of space between each paragraph of text */
577
+ paragraphGap?: number | undefined;
578
+ /** The amount of space between each line of text */
579
+ lineGap?: number | undefined;
580
+ /** The amount of space between each word in the text */
581
+ wordSpacing?: number | undefined;
582
+ /** The amount of space between each character in the text */
583
+ characterSpacing?: number | undefined;
584
+ /** Whether to fill the text (true by default) */
585
+ fill?: boolean | undefined;
586
+ /** Whether to stroke the text */
587
+ stroke?: boolean | undefined;
588
+ /** A URL to link this text to (shortcut to create an annotation) */
589
+ link?: string | null | undefined;
590
+ /** Whether to underline the text */
591
+ underline?: boolean | undefined;
592
+ /** Whether to strike out the text */
593
+ strike?: boolean | undefined;
594
+ /** Whether the text segment will be followed immediately by another segment. Useful for changing styling in the middle of a paragraph. */
595
+ continued?: boolean | undefined;
596
+ /** Whether to slant the text (angle in degrees or true) */
597
+ oblique?: boolean | number | undefined;
598
+ /** The alignment of the text (center, justify, left, right) */
599
+ align?: "center" | "justify" | "left" | "right" | undefined;
600
+ /** The vertical alignment of the text with respect to its insertion point */
601
+ baseline?:
602
+ | number
603
+ | "svg-middle"
604
+ | "middle"
605
+ | "svg-central"
606
+ | "bottom"
607
+ | "ideographic"
608
+ | "alphabetic"
609
+ | "mathematical"
610
+ | "hanging"
611
+ | "top"
612
+ | undefined;
613
+ /** An array of OpenType feature tags to apply. If not provided, a set of defaults is used. */
614
+ features?: OpenTypeFeatures[] | undefined;
615
+ /** Sets a list as unordered, ordered or lettered */
616
+ listType?: "bullet" | "numbered" | "lettered" | undefined;
617
+ /** The radius of bullet points in a list. Works only with listType: 'bullet' */
618
+ bulletRadius?: number | undefined;
619
+ /** The indent of bullet points in a list */
620
+ bulletIndent?: number | undefined;
621
+ /** The indent of text in a list */
622
+ textIndent?: number | undefined;
623
+ destination?: string | undefined;
624
+ goTo?: string | undefined;
625
+ /** The parent structure element to add this child element to, for usage with text() and list() */
626
+ structParent?: PDFStructureElement | undefined;
627
+ /** The marking type used by text(), defaults to 'P' */
628
+ structType?: string | undefined;
629
+ /** The marking types used by items of list(), defaults to [ 'LI', 'Lbl', 'LBody' ] */
630
+ structTypes?: [string | null, string | null, string | null] | undefined;
631
+ }
632
+
633
+ interface TextBounds {
634
+ x: number;
635
+ y: number;
636
+ width: number;
637
+ height: number;
638
+ }
639
+
640
+ interface PDFText {
641
+ lineGap(lineGap: number): this;
642
+ moveDown(line?: number): this;
643
+ moveUp(line?: number): this;
644
+ text(text: string, x?: number, y?: number, options?: TextOptions): this;
645
+ text(text: string, options?: TextOptions): this;
646
+ widthOfString(text: string, options?: TextOptions): number;
647
+ heightOfString(text: string, options?: TextOptions): number;
648
+ boundsOfString(text: string, x?: number, y?: number, options?: TextOptions): TextBounds;
649
+ boundsOfString(text: string, options?: TextOptions): TextBounds;
650
+ list(list: Array<string | any>, x?: number, y?: number, options?: TextOptions): this;
651
+ list(list: Array<string | any>, options?: TextOptions): this;
652
+ }
653
+
654
+ interface PDFVector {
655
+ save(): this;
656
+ restore(): this;
657
+ closePath(): this;
658
+ lineWidth(w: number): this;
659
+ lineCap(c: string): this;
660
+ lineJoin(j: string): this;
661
+ miterLimit(m: any): this;
662
+ dash(length: number, option: any): this;
663
+ undash(): this;
664
+ moveTo(x: number, y: number): this;
665
+ lineTo(x: number, y: number): this;
666
+ bezierCurveTo(cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number, y: number): this;
667
+ quadraticCurveTo(cpx: number, cpy: number, x: number, y: number): this;
668
+ rect(x: number, y: number, w: number, h: number): this;
669
+ roundedRect(x: number, y: number, w: number, h: number, r?: number): this;
670
+ ellipse(x: number, y: number, r1: number, r2?: number): this;
671
+ circle(x: number, y: number, radius: number): this;
672
+ polygon(...points: number[][]): this;
673
+ path(path: string): this;
674
+ fill(color?: ColorValue, rule?: RuleValue): this;
675
+ fill(rule: RuleValue): this;
676
+ stroke(color?: ColorValue): this;
677
+ fillAndStroke(fillColor?: ColorValue, strokeColor?: ColorValue, rule?: RuleValue): this;
678
+ fillAndStroke(fillColor: ColorValue, rule?: RuleValue): this;
679
+ fillAndStroke(rule: RuleValue): this;
680
+ clip(rule?: RuleValue): this;
681
+ transform(m11: number, m12: number, m21: number, m22: number, dx: number, dy: number): this;
682
+ translate(x: number, y: number): this;
683
+ rotate(angle: number, options?: { origin?: number[] | undefined }): this;
684
+ scale(xFactor: number, yFactor?: number, options?: { origin?: number[] | undefined }): this;
685
+ }
686
+
687
+ interface PDFAcroForm {
688
+ /**
689
+ * Must call if adding AcroForms to a document. Must also call font() before
690
+ * this method to set the default font.
691
+ */
692
+ initForm(): this;
693
+
694
+ /**
695
+ * Called automatically by document.js
696
+ */
697
+ endAcroForm(): this;
698
+
699
+ /**
700
+ * Creates and adds a form field to the document. Form fields are intermediate
701
+ * nodes in a PDF form that are used to specify form name hierarchy and form
702
+ * value defaults.
703
+ * @param name - field name (T attribute in field dictionary)
704
+ * @param options - other attributes to include in the field dictionary
705
+ */
706
+ formField(name: string, options?: Record<string, any>): PDFKitReference;
707
+
708
+ /**
709
+ * Creates and adds a Form Annotation to the document. Form annotations are
710
+ * called Widget annotations internally within a PDF file.
711
+ * @param name - form field name (T attribute of widget annotation
712
+ * dictionary)
713
+ */
714
+ formAnnotation(name: string, type: string, x: number, y: number, w: number, h: number, options?: object): this;
715
+
716
+ formText(name: string, x: number, y: number, w: number, h: number, options?: object): this;
717
+ formPushButton(name: string, x: number, y: number, w: number, h: number, options?: object): this;
718
+ formCombo(name: string, x: number, y: number, w: number, h: number, options?: object): this;
719
+ formList(name: string, x: number, y: number, w: number, h: number, options?: object): this;
720
+ formRadioButton(name: string, x: number, y: number, w: number, h: number, options?: object): this;
721
+ formCheckbox(name: string, x: number, y: number, w: number, h: number, options?: object): this;
722
+ }
723
+
724
+ interface PDFMarking {
725
+ markContent(tag: string, options?: MarkingOptions): this;
726
+ endMarkedContent(): this;
727
+ struct(
728
+ tag: string,
729
+ options?: StructureElementOptions,
730
+ children?: PDFStructureElementChild | PDFStructureElementChild[],
731
+ ): PDFStructureElement;
732
+ addStructure(structElem: PDFStructureElement): this;
733
+ initMarkings(options?: { tagged?: boolean }): void;
734
+ initPageMarkings(pageMarkings: PageMarking[]): void;
735
+ endPageMarkings(page: PDFPage): PageMarking[];
736
+ markStructureContent(tag: string, options?: MarkingOptions): PDFStructureContent;
737
+ getMarkingsDictionary(): PDFKitReference;
738
+ getStructTreeRoot(): PDFKitReference;
739
+ createStructParentTreeNextKey(): number;
740
+ endMarkings(): void;
741
+ }
742
+ interface MarkingOptions {
743
+ type?: "Pagination" | "Layout" | "Page";
744
+ bbox?: [number, number, number, number];
745
+ attached?: string[];
746
+ lang?: string;
747
+ alt?: string;
748
+ expanded?: string;
749
+ actual?: string;
750
+ }
751
+ interface StructureElementOptions {
752
+ title?: string;
753
+ lang?: string;
754
+ alt?: string;
755
+ expanded?: string;
756
+ actual?: string;
757
+ }
758
+ interface PageMarking {
759
+ tag: string;
760
+ structContent?: PDFStructureContent;
761
+ options?: MarkingOptions;
762
+ }
763
+
764
+ interface PDFMetadata {
765
+ /** Called automatically */
766
+ initMetadata(): void;
767
+ appendXML(XMLxml: string, newLine?: boolean): void;
768
+ /** Called automatically */
769
+ endMetadata(): void;
770
+ }
771
+
772
+ type PDFSubsets = `PDF/A-1${"" | "a" | "b"}` | `PDF/A-2${"" | "a" | "b"}` | `PDF/A-3${"" | "a" | "b"}`;
773
+ interface PDFSubset {
774
+ // TODO: Add more types if needed. I do not understand this enought...
775
+ initSubset(options: { subset: PDFSubsets }): void;
776
+ endSubset(): void;
777
+ }
778
+
779
+ interface PDFOutline {
780
+ /**
781
+ * The root outline
782
+ */
783
+ outline: PDFKit.PDFOutline;
784
+ initOutline(): void;
785
+ endOutline(): void;
786
+ }
787
+
788
+ interface PDFColorSpace {
789
+ iccProfile(label:string, data: Uint8Array | ArrayBuffer, channels: number, alternate: string|string[]): this;
790
+ }
791
+
792
+ interface PDFOutputIntent {
793
+ outputIntent(type: string, s:string, info:string, outputConditionIdentifier: string, destOutputProfileLabel:string): this;
794
+ }
795
+ }
796
+
797
+ declare namespace PDFKit {
798
+ /**
799
+ * PDFKit data
800
+ */
801
+ interface PDFData {
802
+ new(data: any[]): PDFData;
803
+ readByte(): any;
804
+ writeByte(byte: any): void;
805
+ byteAt(index: number): any;
806
+ readBool(): boolean;
807
+ writeBool(val: boolean): boolean;
808
+ readUInt32(): number;
809
+ writeUInt32(val: number): void;
810
+ readInt32(): number;
811
+ writeInt32(val: number): void;
812
+ readUInt16(): number;
813
+ writeUInt16(val: number): void;
814
+ readInt16(): number;
815
+ writeInt16(val: number): void;
816
+ readString(length: number): string;
817
+ writeString(val: string): void;
818
+ stringAt(pos: number, length: number): string;
819
+ readShort(): number;
820
+ writeShort(val: number): void;
821
+ readLongLong(): number;
822
+ writeLongLong(val: number): void;
823
+ readInt(): number;
824
+ writeInt(val: number): void;
825
+ slice(start: number, end: number): any[];
826
+ read(length: number): any[];
827
+ write(bytes: any[]): void;
828
+ }
829
+ }
830
+
831
+ declare module "pdfkit/js/data" {
832
+ var PDFKitData: PDFKit.PDFData;
833
+ export = PDFKitData;
834
+ }
835
+
836
+ declare namespace PDFKit {
837
+ interface DocumentInfo {
838
+ Producer?: string;
839
+ Creator?: string;
840
+ CreationDate?: Date;
841
+ Title?: string;
842
+ Author?: string;
843
+ Subject?: string;
844
+ Keywords?: string;
845
+ ModDate?: Date;
846
+ }
847
+
848
+ interface DocumentPermissions {
849
+ modifying?: boolean | undefined;
850
+ copying?: boolean | undefined;
851
+ annotating?: boolean | undefined;
852
+ fillingForms?: boolean | undefined;
853
+ contentAccessibility?: boolean | undefined;
854
+ documentAssembly?: boolean | undefined;
855
+ printing?: "lowResolution" | "highResolution" | undefined;
856
+ }
857
+
858
+ interface PDFDocumentOptions {
859
+ compress?: boolean | undefined;
860
+ info?: DocumentInfo | undefined;
861
+ userPassword?: string | undefined;
862
+ ownerPassword?: string | undefined;
863
+ permissions?: DocumentPermissions | undefined;
864
+ pdfVersion?: "1.3" | "1.4" | "1.5" | "1.6" | "1.7" | "1.7ext3" | undefined;
865
+ autoFirstPage?: boolean | undefined;
866
+ size?: number[] | string | undefined;
867
+ margin?: PDFKit.Mixins.Size | undefined;
868
+ margins?: PDFKit.Mixins.ExpandedSides<PDFKit.Mixins.Size> | undefined;
869
+ layout?: "portrait" | "landscape" | undefined;
870
+ font?: string | undefined | null;
871
+
872
+ bufferPages?: boolean | undefined;
873
+ tagged?: boolean;
874
+ lang?: string;
875
+ displayTitle?: boolean;
876
+ subset?: Mixins.PDFSubsets;
877
+ fontLayoutCache?: boolean;
878
+ }
879
+
880
+ class PDFDocument {
881
+ /**
882
+ * PDF Version
883
+ */
884
+ version: number;
885
+ /**
886
+ * Whenever streams should be compressed
887
+ */
888
+ compress: boolean;
889
+ /**
890
+ * PDF document Metadata
891
+ */
892
+ info: DocumentInfo;
893
+ /**
894
+ * Options for the document
895
+ */
896
+ options: PDFDocumentOptions;
897
+ /**
898
+ * Represent the current page.
899
+ */
900
+ page: PDFPage;
901
+ outline: PDFKit.PDFOutline;
902
+
903
+ x: number;
904
+ y: number;
905
+
906
+ constructor(options?: PDFDocumentOptions);
907
+
908
+ addPage(options?: PDFDocumentOptions): PDFDocument;
909
+ continueOnNewPage(options?: PDFDocumentOptions): PDFDocument;
910
+ bufferedPageRange(): { start: number; count: number };
911
+ switchToPage(n?: number): PDFPage;
912
+ flushPages(): void;
913
+
914
+ // See https://opensource.adobe.com/dc-acrobat-sdk-docs/library/pdfmark/pdfmark_Actions.html#view-destinations.
915
+ // If `fitType` is missing, this method wll be invoked with (name, 'XYZ', null, null, null).
916
+ addNamedDestination(name: string): void;
917
+ addNamedDestination(name: string, fitType: "Fit"): void;
918
+ addNamedDestination(name: string, fitType: "FitB"): void;
919
+ addNamedDestination(name: string, fitType: "FitBH", top: number): void;
920
+ addNamedDestination(name: string, fitType: "FitBV", left: number): void;
921
+ addNamedDestination(name: string, fitType: "FitH", top: number): void;
922
+ addNamedDestination(name: string, fitType: "FitR", x1: number, y1: number, x2: number, y2: number): void;
923
+ addNamedDestination(name: string, fitType: "FitV", left: number): void;
924
+ addNamedDestination(
925
+ name: string,
926
+ fitType: "XYZ",
927
+ left: number | null,
928
+ top: number | null,
929
+ zoom: number | null,
930
+ ): void;
931
+ addNamedDestination(name: string, fitType: string, ...args: number[]): void;
932
+
933
+ addNamedEmbeddedFile(name: string, ref: PDFKitReference): void;
934
+ addNamedJavaScript(name: string, js: string): void;
935
+
936
+ ref(data: Record<string, unknown>): PDFKitReference;
937
+ addContent(data: unknown): PDFDocument;
938
+ end(): void;
939
+ toString(): string;
940
+ }
941
+
942
+ interface PDFDocument
943
+ extends
944
+ NodeJS.ReadableStream,
945
+ Mixins.PDFMetadata,
946
+ Mixins.PDFAnnotation,
947
+ Mixins.PDFColor,
948
+ Mixins.PDFImage,
949
+ Mixins.PDFTable,
950
+ Mixins.PDFText,
951
+ Mixins.PDFVector,
952
+ Mixins.PDFFont,
953
+ Mixins.PDFAcroForm,
954
+ Mixins.PDFMarking,
955
+ Mixins.PDFAttachment,
956
+ Mixins.PDFSubset,
957
+ Mixins.PDFOutline,
958
+ Mixins.PDFColorSpace,
959
+ Mixins.PDFOutputIntent {}
960
+ }
961
+
962
+ declare const PDFDocument: typeof PDFKit.PDFDocument;
963
+
964
+ export default PDFDocument;
965
+
966
+ declare module "pdfkit/js/pdfkit.standalone" {
967
+ const PDFDocument: typeof PDFKit.PDFDocument;
968
+ export default PDFDocument;
969
+ }
970
+
971
+ declare module "pdfkit/js/gradient" {
972
+ var gradient: {
973
+ PDFGradient: PDFKit.PDFGradient;
974
+ PDFLinearGradient: PDFKit.PDFLinearGradient;
975
+ PDFRadialGradiant: PDFKit.PDFRadialGradient;
976
+ };
977
+
978
+ export = gradient;
979
+ }
980
+
981
+ declare module "pdfkit/js/pattern" {
982
+ var pattern: {
983
+ PDFTilingPattern: PDFKit.PDFTilingPattern;
984
+ };
985
+
986
+ export = pattern;
987
+ }
988
+
989
+ declare namespace PDFKit {
990
+ /**
991
+ * Represent a single page in the PDF document
992
+ */
993
+ interface PDFPage {
994
+ size: string;
995
+ layout: string;
996
+ margins: PDFKit.Mixins.ExpandedSides<number>;
997
+ width: number;
998
+ height: number;
999
+ document: PDFDocument;
1000
+ content: PDFKitReference;
1001
+
1002
+ /**
1003
+ * The page dictionary
1004
+ */
1005
+ dictionary: PDFKitReference;
1006
+
1007
+ fonts: any;
1008
+ xobjects: any;
1009
+ ext_gstates: any;
1010
+ patterns: any;
1011
+ annotations: any;
1012
+
1013
+ maxY(): number;
1014
+ write(chunk: any): void;
1015
+ end(): void;
1016
+ }
1017
+ }
1018
+
1019
+ declare module "pdfkit/js/page" {
1020
+ var PDFKitPage: PDFKit.PDFPage;
1021
+
1022
+ export = PDFKitPage;
1023
+ }
1024
+
1025
+ declare namespace PDFKit {
1026
+ /** PDFReference - represents a reference to another object in the PDF object hierarchy */
1027
+ class PDFKitReference {
1028
+ id: number;
1029
+ gen: number;
1030
+ deflate: any;
1031
+ compress: boolean;
1032
+ uncompressedLength: number;
1033
+ chunks: any[];
1034
+ data: { Font?: any; XObject?: any; ExtGState?: any; Pattern: any; Annots: any };
1035
+ document: PDFDocument;
1036
+
1037
+ constructor(document: PDFDocument, id: number, data: {});
1038
+ initDeflate(): void;
1039
+ write(chunk: any): void;
1040
+ end(chunk: any): void;
1041
+ finalize(): void;
1042
+ toString(): string;
1043
+ }
1044
+ }
1045
+
1046
+ declare module "pdfkit/js/reference" {
1047
+ var PDFKitReference: PDFKit.PDFKitReference;
1048
+
1049
+ export = PDFKitReference;
1050
+ }
1051
+ declare namespace PDFKit {
1052
+ /** PDFStructureContent */
1053
+ class PDFStructureContent {
1054
+ constructor(pageRef: PDFKitReference, mcid: number);
1055
+ push(structContent: PDFStructureContent): void;
1056
+ }
1057
+ }
1058
+
1059
+ declare module "pdfkit/js/structure_content" {
1060
+ var PDFStructureContent: PDFKit.PDFStructureContent;
1061
+ export = PDFStructureContent;
1062
+ }
1063
+
1064
+ declare namespace PDFKit {
1065
+ type PDFStructureElementChild =
1066
+ | (() => any)
1067
+ | PDFStructureElement
1068
+ | PDFStructureContent;
1069
+
1070
+ /** PDFStructureElement */
1071
+ class PDFStructureElement {
1072
+ constructor(
1073
+ document: PDFDocument,
1074
+ type: string,
1075
+ options?: { title?: string; lang?: string; alt?: string; expanded?: string; actual?: string },
1076
+ children?: PDFStructureElementChild | PDFStructureElementChild[],
1077
+ );
1078
+ constructor(
1079
+ document: PDFDocument,
1080
+ type: string,
1081
+ children?: PDFStructureElementChild | PDFStructureElementChild[],
1082
+ );
1083
+ add(el: PDFStructureElementChild): PDFStructureElement;
1084
+ setParent(parentRef: PDFKitReference): void;
1085
+ setAttached(): void;
1086
+ end(): void;
1087
+ }
1088
+ }
1089
+
1090
+ declare namespace PDFKit {
1091
+ /**
1092
+ * PDFKit data
1093
+ */
1094
+ interface PDFOutline {
1095
+ document: PDFDocument;
1096
+ children: PDFOutline[];
1097
+ addItem(title: string, options?: { expanded?: boolean }): PDFOutline;
1098
+ endOutline(): void;
1099
+ }
1100
+ }
1101
+
1102
+ declare module "pdfkit/js/structure_element" {
1103
+ var PDFStructureElement: PDFKit.PDFStructureElement;
1104
+ export = PDFStructureElement;
1105
+ }
1106
+
1107
+ declare module "pdfkit/js/mixins/annotations" {
1108
+ var PDFKitAnnotation: PDFKit.Mixins.PDFAnnotation;
1109
+ export = PDFKitAnnotation;
1110
+ }
1111
+
1112
+ declare module "pdfkit/js/mixins/color" {
1113
+ var PDFKitColor: PDFKit.Mixins.PDFColor;
1114
+ export = PDFKitColor;
1115
+ }
1116
+
1117
+ declare module "pdfkit/js/mixins/fonts" {
1118
+ var PDFKitFont: PDFKit.Mixins.PDFFont;
1119
+ export = PDFKitFont;
1120
+ }
1121
+
1122
+ declare module "pdfkit/js/mixins/images" {
1123
+ var PDFKitImage: PDFKit.Mixins.PDFImage;
1124
+ export = PDFKitImage;
1125
+ }
1126
+
1127
+ declare module "pdfkit/js/mixins/table" {
1128
+ var PDFKitTable: PDFKit.Mixins.PDFTable;
1129
+ export = PDFKitTable;
1130
+ }
1131
+
1132
+ declare module "pdfkit/js/mixins/text" {
1133
+ var PDFKitText: PDFKit.Mixins.PDFText;
1134
+ export = PDFKitText;
1135
+ }
1136
+
1137
+ declare module "pdfkit/js/mixins/vector" {
1138
+ var PDFKitVector: PDFKit.Mixins.PDFVector;
1139
+ export = PDFKitVector;
1140
+ }
1141
+
1142
+ declare module "pdfkit/js/mixins/markings" {
1143
+ var PDFKitMarking: PDFKit.Mixins.PDFMarking;
1144
+ export = PDFKitMarking;
1145
+ }
1146
+
1147
+ declare module "pdfkit/js/mixins/outline" {
1148
+ var PDFKitOutline: PDFKit.Mixins.PDFOutline;
1149
+ export = PDFKitOutline;
1150
+ }
1151
+
1152
+ declare module "pdfkit/js/mixins/color_space" {
1153
+ var PDFKitColorSpace: PDFKit.Mixins.PDFColorSpace;
1154
+ export = PDFKitColorSpace;
1155
+ }
1156
+
1157
+ declare module "pdfkit/js/mixins/output_intent" {
1158
+ var PDFKitOutputIntent: PDFKit.Mixins.PDFOutputIntent;
1159
+ export = PDFKitOutputIntent;
1160
+ }