pdfmake-acroforms 0.3.4-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/LICENSE +21 -0
  3. package/README.md +75 -0
  4. package/build/fonts/Roboto/Roboto-Italic.ttf +0 -0
  5. package/build/fonts/Roboto/Roboto-Medium.ttf +0 -0
  6. package/build/fonts/Roboto/Roboto-MediumItalic.ttf +0 -0
  7. package/build/fonts/Roboto/Roboto-Regular.ttf +0 -0
  8. package/build/fonts/Roboto.js +27 -0
  9. package/build/pdfmake.js +67806 -0
  10. package/build/pdfmake.js.map +1 -0
  11. package/build/pdfmake.min.js +3 -0
  12. package/build/pdfmake.min.js.map +1 -0
  13. package/build/standard-fonts/Courier.js +27 -0
  14. package/build/standard-fonts/Helvetica.js +27 -0
  15. package/build/standard-fonts/Symbol.js +21 -0
  16. package/build/standard-fonts/Times.js +27 -0
  17. package/build/standard-fonts/ZapfDingbats.js +21 -0
  18. package/build/vfs_fonts.js +6 -0
  19. package/build-vfs.js +44 -0
  20. package/fonts/Roboto/Roboto-Italic.ttf +0 -0
  21. package/fonts/Roboto/Roboto-Medium.ttf +0 -0
  22. package/fonts/Roboto/Roboto-MediumItalic.ttf +0 -0
  23. package/fonts/Roboto/Roboto-Regular.ttf +0 -0
  24. package/fonts/Roboto.js +8 -0
  25. package/index.d.ts +40 -0
  26. package/interfaces.d.ts +2610 -0
  27. package/js/3rd-party/svg-to-pdfkit/source.js +3823 -0
  28. package/js/3rd-party/svg-to-pdfkit.js +7 -0
  29. package/js/DocMeasure.js +675 -0
  30. package/js/DocPreprocessor.js +258 -0
  31. package/js/DocumentContext.js +310 -0
  32. package/js/ElementWriter.js +399 -0
  33. package/js/LayoutBuilder.js +1202 -0
  34. package/js/Line.js +101 -0
  35. package/js/OutputDocument.js +64 -0
  36. package/js/OutputDocumentServer.js +29 -0
  37. package/js/PDFDocument.js +145 -0
  38. package/js/PageElementWriter.js +164 -0
  39. package/js/PageSize.js +74 -0
  40. package/js/Printer.js +288 -0
  41. package/js/Renderer.js +513 -0
  42. package/js/SVGMeasure.js +92 -0
  43. package/js/StyleContextStack.js +191 -0
  44. package/js/TableProcessor.js +562 -0
  45. package/js/TextBreaker.js +179 -0
  46. package/js/TextDecorator.js +152 -0
  47. package/js/TextInlines.js +212 -0
  48. package/js/URLResolver.js +43 -0
  49. package/js/base.js +59 -0
  50. package/js/browser-extensions/OutputDocumentBrowser.js +82 -0
  51. package/js/browser-extensions/fonts/Roboto.js +38 -0
  52. package/js/browser-extensions/index.js +53 -0
  53. package/js/browser-extensions/pdfMake.js +3 -0
  54. package/js/browser-extensions/standard-fonts/Courier.js +38 -0
  55. package/js/browser-extensions/standard-fonts/Helvetica.js +38 -0
  56. package/js/browser-extensions/standard-fonts/Symbol.js +23 -0
  57. package/js/browser-extensions/standard-fonts/Times.js +38 -0
  58. package/js/browser-extensions/standard-fonts/ZapfDingbats.js +23 -0
  59. package/js/browser-extensions/virtual-fs-cjs.js +3 -0
  60. package/js/columnCalculator.js +148 -0
  61. package/js/helpers/node.js +122 -0
  62. package/js/helpers/tools.js +46 -0
  63. package/js/helpers/variableType.js +59 -0
  64. package/js/index.d.ts +40 -0
  65. package/js/index.js +15 -0
  66. package/js/interfaces.d.ts +2610 -0
  67. package/js/qrEnc.js +721 -0
  68. package/js/standardPageSizes.js +56 -0
  69. package/js/tableLayouts.js +98 -0
  70. package/js/virtual-fs.js +60 -0
  71. package/package.json +95 -0
  72. package/src/3rd-party/svg-to-pdfkit/LICENSE +9 -0
  73. package/src/3rd-party/svg-to-pdfkit/source.js +2745 -0
  74. package/src/3rd-party/svg-to-pdfkit.js +3 -0
  75. package/src/DocMeasure.js +768 -0
  76. package/src/DocPreprocessor.js +289 -0
  77. package/src/DocumentContext.js +345 -0
  78. package/src/ElementWriter.js +468 -0
  79. package/src/LayoutBuilder.js +1366 -0
  80. package/src/Line.js +108 -0
  81. package/src/OutputDocument.js +64 -0
  82. package/src/OutputDocumentServer.js +32 -0
  83. package/src/PDFDocument.js +178 -0
  84. package/src/PageElementWriter.js +191 -0
  85. package/src/PageSize.js +53 -0
  86. package/src/Printer.js +306 -0
  87. package/src/Renderer.js +546 -0
  88. package/src/SVGMeasure.js +109 -0
  89. package/src/StyleContextStack.js +208 -0
  90. package/src/TableProcessor.js +620 -0
  91. package/src/TextBreaker.js +181 -0
  92. package/src/TextDecorator.js +175 -0
  93. package/src/TextInlines.js +229 -0
  94. package/src/URLResolver.js +43 -0
  95. package/src/base.js +70 -0
  96. package/src/browser-extensions/OutputDocumentBrowser.js +80 -0
  97. package/src/browser-extensions/fonts/Roboto.js +27 -0
  98. package/src/browser-extensions/index.js +55 -0
  99. package/src/browser-extensions/pdfMake.js +1 -0
  100. package/src/browser-extensions/standard-fonts/Courier.js +27 -0
  101. package/src/browser-extensions/standard-fonts/Helvetica.js +27 -0
  102. package/src/browser-extensions/standard-fonts/Symbol.js +21 -0
  103. package/src/browser-extensions/standard-fonts/Times.js +27 -0
  104. package/src/browser-extensions/standard-fonts/ZapfDingbats.js +21 -0
  105. package/src/browser-extensions/virtual-fs-cjs.js +1 -0
  106. package/src/columnCalculator.js +154 -0
  107. package/src/helpers/node.js +134 -0
  108. package/src/helpers/tools.js +44 -0
  109. package/src/helpers/variableType.js +50 -0
  110. package/src/index.js +16 -0
  111. package/src/qrEnc.js +796 -0
  112. package/src/standardPageSizes.js +52 -0
  113. package/src/tableLayouts.js +100 -0
  114. package/src/virtual-fs.js +66 -0
  115. package/standard-fonts/Courier.js +8 -0
  116. package/standard-fonts/Helvetica.js +8 -0
  117. package/standard-fonts/Symbol.js +5 -0
  118. package/standard-fonts/Times.js +8 -0
  119. package/standard-fonts/ZapfDingbats.js +5 -0
@@ -0,0 +1,2610 @@
1
+ /// <reference lib="dom" />
2
+ /// <reference types="node" />
3
+ /// <reference types="pdfkit" />
4
+
5
+ /**
6
+ * Size of a page.
7
+ */
8
+ export type PageSize = PredefinedPageSize | CustomPageSize;
9
+
10
+ /**
11
+ * A page size using custom dimensions.
12
+ */
13
+ export interface CustomPageSize {
14
+ /**
15
+ * Page width in `pt`.
16
+ */
17
+ width: number;
18
+
19
+ /**
20
+ * Page height in `pt`, or `auto` to adapt the page height to the document's content
21
+ * (the document will always have a single page).
22
+ */
23
+ height: number | "auto";
24
+ }
25
+
26
+ /**
27
+ * A position applied to an element.
28
+ */
29
+ export interface Position {
30
+ /**
31
+ * Horizontal position from the left edge of the page in `pt`.
32
+ *
33
+ * Defaults to `0`.
34
+ */
35
+ x?: number | undefined;
36
+
37
+ /**
38
+ * Vertical position from the top of the page in `pt`.
39
+ *
40
+ * Defaults to `0`.
41
+ */
42
+ y?: number | undefined;
43
+ }
44
+
45
+ /**
46
+ * Available predefined page sizes:
47
+ * - ISO 216 standard sizes (e.g. `A4`)
48
+ * - ISO 217 raw sizes (e.g. `RA4`)
49
+ * - American loose sizes (e.g. `TABLOID`)
50
+ */
51
+ export type PredefinedPageSize =
52
+ | "4A0"
53
+ | "2A0"
54
+ | "A0"
55
+ | "A1"
56
+ | "A2"
57
+ | "A3"
58
+ | "A4"
59
+ | "A5"
60
+ | "A6"
61
+ | "A7"
62
+ | "A8"
63
+ | "A9"
64
+ | "A10"
65
+ | "B0"
66
+ | "B1"
67
+ | "B2"
68
+ | "B3"
69
+ | "B4"
70
+ | "B5"
71
+ | "B6"
72
+ | "B7"
73
+ | "B8"
74
+ | "B9"
75
+ | "B10"
76
+ | "C0"
77
+ | "C1"
78
+ | "C2"
79
+ | "C3"
80
+ | "C4"
81
+ | "C5"
82
+ | "C6"
83
+ | "C7"
84
+ | "C8"
85
+ | "C9"
86
+ | "C10"
87
+ | "RA1"
88
+ | "RA2"
89
+ | "RA3"
90
+ | "RA4"
91
+ | "SRA1"
92
+ | "SRA2"
93
+ | "SRA3"
94
+ | "SRA4"
95
+ | "EXECUTIVE"
96
+ | "FOLIO"
97
+ | "LEGAL"
98
+ | "LETTER"
99
+ | "TABLOID";
100
+
101
+ /**
102
+ * Orientation of a page:
103
+ * - `portrait` uses the shorter dimension as width and the longer one as height
104
+ * - `landscape` uses the longer dimension as width and the shorter one as height
105
+ *
106
+ * A page's orientation does not rotate its content; it is always rendered top to bottom.
107
+ */
108
+ export type PageOrientation = "portrait" | "landscape";
109
+
110
+ /**
111
+ * Different types of page breaks:
112
+ * - `before`/`after` add a page break before or after an element
113
+ * - `beforeEven`/`afterEven` adds one or two page breaks before/after an element
114
+ * so that the content after the page break is on an even page
115
+ * - `beforeOdd`/`afterOdd` adds one or two page breaks before/after an element
116
+ * so that the content after the page break is on an odd page
117
+ */
118
+ export type PageBreak = "before" | "beforeEven" | "beforeOdd" | "after" | "afterEven" | "afterOdd";
119
+
120
+ /**
121
+ * Sizes for the width of stand-alone columns and table columns.
122
+ *
123
+ * Available options are:
124
+ * - A number to define an absolute width in `pt`
125
+ * - A percentage string such as `50%` to fill a portion of the available space
126
+ * - `auto` to set the width based on the content
127
+ * - `*` to fill the remaining available space, distributed equally among
128
+ * all star-sized columns
129
+ */
130
+ export type Size =
131
+ | number
132
+ | "auto"
133
+ | "*"
134
+ | string;
135
+
136
+ /**
137
+ * Combination of a pattern defined in {@link TDocumentDefinitions.patterns} and a color.
138
+ *
139
+ * Tuple consisting of two elements:
140
+ * - The name of the pattern
141
+ * - The color to apply to the pattern.
142
+ * Supports well-known color names like `blue` or hexadecimal color strings like `#ccffcc`.
143
+ */
144
+ export type PatternFill = [string, string];
145
+
146
+ /**
147
+ * Dictionary of font families that can be referenced by their key.
148
+ */
149
+ export interface TFontDictionary {
150
+ [fontName: string]: TFontFamilyTypes;
151
+ }
152
+
153
+ /**
154
+ * Dictionary of a virtual file system, mapping file paths to base64 file contents.
155
+ */
156
+ export interface TVirtualFileSystem {
157
+ [filePath: string]: string;
158
+ }
159
+
160
+ /**
161
+ * Container combining a virtual file system and its contained font definitions.
162
+ */
163
+ export interface TFontContainer {
164
+ vfs: TVirtualFileSystem;
165
+ fonts: TFontDictionary;
166
+ }
167
+
168
+ /**
169
+ * Definition of a font family.
170
+ */
171
+ export interface TFontFamilyTypes {
172
+ /** Font variant that is neither bold nor italic. */
173
+ normal?: PDFKit.Mixins.PDFFontSource | undefined;
174
+
175
+ /** Font variant that is bold. */
176
+ bold?: PDFKit.Mixins.PDFFontSource | undefined;
177
+
178
+ /** Font variant that is italic. */
179
+ italics?: PDFKit.Mixins.PDFFontSource | undefined;
180
+
181
+ /** Font variant that is bold and italic. */
182
+ bolditalics?: PDFKit.Mixins.PDFFontSource | undefined;
183
+ }
184
+
185
+ /**
186
+ * Metadata to embed into the document.
187
+ */
188
+ export interface TDocumentInformation {
189
+ /** Document title. */
190
+ title?: string | undefined;
191
+
192
+ /** Name of the author. */
193
+ author?: string | undefined;
194
+
195
+ /** Subject of the document. */
196
+ subject?: string | undefined;
197
+
198
+ /**
199
+ * Keywords associated with the document.
200
+ *
201
+ * A PDF file stores all keywords as a single string, as given here.
202
+ * For optimal compatibility, separate keywords using commas or spaces.
203
+ */
204
+ keywords?: string | undefined;
205
+
206
+ /**
207
+ * Name of the creator.
208
+ *
209
+ * Defaults to `pdfmake`.
210
+ */
211
+ creator?: string | undefined;
212
+
213
+ /**
214
+ * Name of the producer.
215
+ *
216
+ * Defaults to `pdfmake`.
217
+ */
218
+ producer?: string | undefined;
219
+
220
+ /**
221
+ * Date the document was created.
222
+ *
223
+ * Defaults to the current date and time.
224
+ */
225
+ creationDate?: Date | undefined;
226
+
227
+ /** Date the document was last modified. */
228
+ modDate?: Date | undefined;
229
+
230
+ /** Indicates whether the document has been corrected for color misregistrations. */
231
+ trapped?: "True" | "False" | "Unknown" | undefined;
232
+ }
233
+
234
+ /**
235
+ * Callback that returns content depending on the current page number,
236
+ * the total number of pages, or the size of the current page.
237
+ */
238
+ export type DynamicContent = (
239
+ currentPage: number,
240
+ pageCount: number,
241
+ pageSize: ContextPageSize,
242
+ ) => Content | null | undefined;
243
+
244
+ /**
245
+ * Callback that returns content depending on the current page number
246
+ * or the size of the current page.
247
+ */
248
+ export type DynamicBackground = (currentPage: number, pageSize: ContextPageSize) => Content | null | undefined;
249
+
250
+ /**
251
+ * Margin in `pt`. Allows
252
+ * - a single number which applies the same margin on all sides
253
+ * - a tuple of two values `[horizontal, vertical]`
254
+ * - a tuple of four values `[left, top, right, bottom]`
255
+ *
256
+ * Margins of adjacent elements do not collapse.
257
+ *
258
+ * Negative values can lead to elements overlapping each other.
259
+ */
260
+ export type Margins = number | [number, number] | [number, number, number, number];
261
+
262
+ /**
263
+ * Available types of decorations.
264
+ * Can be combined with a {@link DecorationStyle}.
265
+ */
266
+ export type Decoration = "underline" | "lineThrough" | "overline";
267
+
268
+ /**
269
+ * Available {@link Decoration} styles.
270
+ */
271
+ export type DecorationStyle = "solid" | "dashed" | "dotted" | "double" | "wavy";
272
+
273
+ /**
274
+ * Available horizontal alignment options.
275
+ */
276
+ export type Alignment = "left" | "right" | "justify" | "center";
277
+
278
+ /**
279
+ * Callback to define a height in `pt` for a table row based on its row number
280
+ * (starting from 0).
281
+ *
282
+ * `auto` sets the height based on the row's content.
283
+ */
284
+ export type DynamicRowSize = (rowIndex: number) => number | "auto";
285
+
286
+ /**
287
+ * Custom layout to control borders, cell padding, and cell background of a table.
288
+ */
289
+ export interface CustomTableLayout {
290
+ /**
291
+ * Width of horizontal lines in `pt` depending on the row number
292
+ * (0 = line above the first row).
293
+ *
294
+ * **Note**: Does not allow an explicit value of `undefined`.
295
+ *
296
+ * Defaults to `1`.
297
+ */
298
+ hLineWidth?: DynamicLayout<number>;
299
+
300
+ /**
301
+ * Width of vertical lines in `pt` depending on the column number
302
+ * (0 = line to the left of the left-most column).
303
+ *
304
+ * **Note**: Does not allow an explicit value of `undefined`.
305
+ *
306
+ * Defaults to `1`.
307
+ */
308
+ vLineWidth?: VerticalDynamicLayout<number>;
309
+
310
+ /**
311
+ * Color of horizontal lines, optionally depending on the row (0 = line above
312
+ * the top row) and column number (0 = left-most column).
313
+ *
314
+ * Can be overridden for each cell via {@link TableCellProperties.borderColor}.
315
+ *
316
+ * Defaults to `black`.
317
+ */
318
+ hLineColor?: string | DynamicCellLayout<string> | undefined;
319
+
320
+ /**
321
+ * Color of vertical lines, optionally depending on the column (0 = line left
322
+ * of the left-most column) and row number (0 = top row).
323
+ *
324
+ * Can be overridden for each cell via {@link TableCellProperties.borderColor}.
325
+ *
326
+ * Defaults to `black`.
327
+ */
328
+ vLineColor?: string | VerticalDynamicCellLayout<string> | undefined;
329
+
330
+ /**
331
+ * Style of horizontal lines depending on the row number
332
+ * (0 = line above the top row).
333
+ *
334
+ * **Note**: Does not allow an explicit value of `undefined`.
335
+ *
336
+ * Defaults to a solid line.
337
+ */
338
+ hLineStyle?: DynamicLayout<LineStyle>;
339
+
340
+ /**
341
+ * Style of vertical lines depending on the column number
342
+ * (0 = line to the left of the left-most column).
343
+ *
344
+ * **Note**: Does not allow an explicit value of `undefined`.
345
+ *
346
+ * Defaults to a solid line.
347
+ */
348
+ vLineStyle?: VerticalDynamicLayout<LineStyle>;
349
+
350
+ /**
351
+ * Padding in `pt` to the left of each column
352
+ * (0 = left-most column).
353
+ *
354
+ * **Note**: Does not allow an explicit value of `undefined`.
355
+ *
356
+ * Defaults to `4`.
357
+ */
358
+ paddingLeft?: VerticalDynamicLayout<number>;
359
+
360
+ /**
361
+ * Padding in `pt` to the right of each column
362
+ * (0 = left-most column).
363
+ *
364
+ * **Note**: Does not allow an explicit value of `undefined`.
365
+ *
366
+ * Defaults to `4`.
367
+ */
368
+ paddingRight?: VerticalDynamicLayout<number>;
369
+
370
+ /**
371
+ * Padding in `pt` at the top of each cell of a row
372
+ * (0 = top row).
373
+ *
374
+ * **Note**: Does not allow an explicit value of `undefined`.
375
+ *
376
+ * Defaults to `2`.
377
+ */
378
+ paddingTop?: DynamicLayout<number>;
379
+
380
+ /**
381
+ * Padding in `pt` at the bottom of each cell of a row
382
+ * (0 = top row).
383
+ *
384
+ * **Note**: Does not allow an explicit value of `undefined`.
385
+ *
386
+ * Defaults to `2`.
387
+ */
388
+ paddingBottom?: DynamicLayout<number>;
389
+
390
+ /**
391
+ * Background color the table's cells are filled with.
392
+ *
393
+ * Supports well-known color names like `blue` or hexadecimal color strings like `#ccffcc`,
394
+ * as well as a reference to a pattern.
395
+ */
396
+ fillColor?: string | PatternFill | DynamicCellLayout<string | PatternFill> | undefined;
397
+
398
+ /**
399
+ * Opacity of the {@link fillColor}.
400
+ * Must be between 0 (fully transparent) and 1 (fully opaque).
401
+ *
402
+ * Defaults to `1`.
403
+ */
404
+ fillOpacity?: number | DynamicCellLayout<number> | undefined;
405
+
406
+ /**
407
+ * Controls whether the table has any borders by default.
408
+ *
409
+ * If set to `false`, borders can only be added to cells via their `border` property.
410
+ *
411
+ * Defaults to `true`.
412
+ */
413
+ defaultBorder?: boolean | undefined;
414
+ }
415
+
416
+ /**
417
+ * Callback to control a property of the {@link CustomTableLayout} depending on the row number,
418
+ * starting from 0.
419
+ */
420
+ export type DynamicLayout<T> = (rowIndex: number, node: ContentTable) => T | null;
421
+
422
+ /**
423
+ * Callback to control a property of the {@link CustomTableLayout} depending on the column number,
424
+ * starting from 0.
425
+ */
426
+ export type VerticalDynamicLayout<T> = (columnIndex: number, node: ContentTable) => T | null;
427
+
428
+ /**
429
+ * Callback to control a property of the {@link CustomTableLayout} depending on the row and column number,
430
+ * both starting from 0.
431
+ */
432
+ export type DynamicCellLayout<T> = (
433
+ rowIndex: number,
434
+ node: ContentTable,
435
+ columnIndex: number,
436
+ ) => T | null;
437
+
438
+ /**
439
+ * Callback to control a property of the {@link CustomTableLayout} depending on the column and row number,
440
+ * both starting from 0.
441
+ */
442
+ export type VerticalDynamicCellLayout<T> = (
443
+ columnIndex: number,
444
+ node: ContentTable,
445
+ rowIndex: number,
446
+ ) => T | null;
447
+
448
+ /**
449
+ * Style of a dashed line.
450
+ */
451
+ export interface Dash {
452
+ /** Length of each dash in `pt`. */
453
+ length: number;
454
+
455
+ /**
456
+ * Space between dashes in `pt`.
457
+ *
458
+ * Defaults to the same value as {@link length}.
459
+ */
460
+ space?: number | undefined;
461
+ }
462
+
463
+ /**
464
+ * Style of a line.
465
+ */
466
+ export interface LineStyle {
467
+ /**
468
+ * Makes the line dashed.
469
+ *
470
+ * Defaults to a solid line.
471
+ */
472
+ dash?: Dash | undefined;
473
+ }
474
+
475
+ /**
476
+ * Additional properties of {@link Content} objects that are used as table cells.
477
+ */
478
+ export interface TableCellProperties {
479
+ /**
480
+ * Number of rows the cell spans.
481
+ *
482
+ * Cells covered by this cell still need to be declared. They should be
483
+ * filled with an empty object placeholder (`{}`).
484
+ *
485
+ * Defaults to `1`.
486
+ */
487
+ rowSpan?: number | undefined;
488
+
489
+ /**
490
+ * Number of columns the cell spans.
491
+ *
492
+ * Cells covered by this cell still need to be declared. They should be
493
+ * filled with an empty object placeholder (`{}`).
494
+ *
495
+ * Defaults to `1`.
496
+ */
497
+ colSpan?: number | undefined;
498
+
499
+ /**
500
+ * Controls on which sides the cell has borders.
501
+ *
502
+ * Tuple order: `[left, top, right, bottom]`
503
+ *
504
+ * Defaults to `[true, true, true, true]`.
505
+ */
506
+ border?: [boolean, boolean, boolean, boolean] | undefined;
507
+
508
+ /**
509
+ * Color of the border on each side of the cell.
510
+ *
511
+ * Tuple order: `[left, top, right, bottom]`
512
+ *
513
+ * Supports well-known color names like `blue` or hexadecimal color strings like `#ccffcc`.
514
+ *
515
+ * Defaults to the border color defined by the given table layout, or `black` on all sides.
516
+ */
517
+ borderColor?: [string, string, string, string] | undefined;
518
+
519
+ /**
520
+ * Overlays the cell with the given pattern.
521
+ */
522
+ overlayPattern?: PatternFill | undefined;
523
+
524
+ /**
525
+ * Opacity of the given {@link overlayPattern}.
526
+ * Must be between 0 (fully transparent) and 1 (fully opaque).
527
+ *
528
+ * Defaults to `1`.
529
+ */
530
+ overlayOpacity?: number | null | undefined;
531
+ }
532
+
533
+ /**
534
+ * A cell of a {@link Table}.
535
+ * - Can be any valid content. Content objects provide additional properties to control
536
+ * the cell's appearance.
537
+ * - Use empty objects (`{}`) as placeholders for cells that are covered by other cells
538
+ * spanning multiple rows or columns.
539
+ */
540
+ export type TableCell = Record<PropertyKey, never> | (Content & TableCellProperties);
541
+
542
+ /**
543
+ * A table.
544
+ */
545
+ export interface Table {
546
+ /**
547
+ * Two-dimensional array that defines the table's rows and their cells.
548
+ *
549
+ * Given a row and column number (both starting from 0), each cell is addressed as
550
+ * `body[rowIndex][columnIndex]`.
551
+ */
552
+ body: TableCell[][];
553
+
554
+ /**
555
+ * Column widths of the table.
556
+ * - `*` distributes the width equally, filling the whole available space.
557
+ * - `auto` sets the widths based on the content, filling only the necessary space.
558
+ * - Use an array to control the width of each column individually.
559
+ * The array must contain widths for all columns.
560
+ *
561
+ * A column width smaller than a cell's content will break the text into multiple lines.
562
+ *
563
+ * Defaults to `auto`.
564
+ */
565
+ widths?: "*" | "auto" | Size[] | undefined;
566
+
567
+ /**
568
+ * Row heights of the table.
569
+ * - A number sets an absolute height in `pt` for every row.
570
+ * - `auto` sets the heights based on the content.
571
+ * - Use an array or a callback function to control the height of each row individually.
572
+ *
573
+ * The given values are ignored for rows whose content is higher.
574
+ *
575
+ * Defaults to `auto`.
576
+ */
577
+ heights?: number | "auto" | Array<number | "auto"> | DynamicRowSize | undefined;
578
+
579
+ /**
580
+ * Number of rows from the top that make up the table's header.
581
+ *
582
+ * If the table spans across multiple pages, the header is repeated on every page.
583
+ *
584
+ * Defaults to `0`.
585
+ */
586
+ headerRows?: number | undefined;
587
+
588
+ /**
589
+ * Controls whether the contents of a table row should be kept together on the same page.
590
+ *
591
+ * Defaults to `false`.
592
+ */
593
+ dontBreakRows?: boolean | undefined;
594
+
595
+ /**
596
+ * Number of rows after the given {@link headerRows} that should be kept together with
597
+ * the header rows, without a page break in between.
598
+ *
599
+ * Defaults to `0`.
600
+ */
601
+ keepWithHeaderRows?: number | undefined;
602
+ }
603
+
604
+ /**
605
+ * Built-in predefined table layouts:
606
+ * - `noBorders` renders the table without borders and without horizontal padding for the left- and right-most cell
607
+ * - `headerLineOnly` only renders a horizontal border below the rows marked as header
608
+ * - `lightHorizontalLines` renders gray horizontal borders
609
+ */
610
+ export type PredefinedTableLayout = "noBorders" | "headerLineOnly" | "lightHorizontalLines";
611
+
612
+ /**
613
+ * A table layout.
614
+ *
615
+ * Available options are:
616
+ * - the name of a built-in predefined table layout
617
+ * - the name of a global custom table layout
618
+ * - a custom table layout object
619
+ */
620
+ export type TableLayout = string | PredefinedTableLayout | CustomTableLayout;
621
+
622
+ /**
623
+ * Style definition.
624
+ *
625
+ * Most properties are passed down to an element's children.
626
+ *
627
+ * The properties can also be applied to element objects directly.
628
+ */
629
+ export interface Style {
630
+ /**
631
+ * Name of the font.
632
+ *
633
+ * Only built-in and globally declared fonts are available, regardless of the fonts
634
+ * installed on the system.
635
+ *
636
+ * Defaults to `Roboto`.
637
+ */
638
+ font?: string | undefined;
639
+
640
+ /**
641
+ * Font size in `pt`.
642
+ *
643
+ * Defaults to `12`.
644
+ */
645
+ fontSize?: number | undefined;
646
+
647
+ /**
648
+ * OpenType font features to apply.
649
+ */
650
+ fontFeatures?: PDFKit.Mixins.OpenTypeFeatures[] | undefined;
651
+
652
+ /**
653
+ * Line height as a factor of the {@link fontSize}.
654
+ *
655
+ * Defaults to `1`.
656
+ */
657
+ lineHeight?: number | undefined;
658
+
659
+ /**
660
+ * Controls whether the text is bold.
661
+ *
662
+ * Defaults to `false`.
663
+ */
664
+ bold?: boolean | undefined;
665
+
666
+ /**
667
+ * Controls whether the text is italic.
668
+ *
669
+ * Defaults to `false`.
670
+ */
671
+ italics?: boolean | undefined;
672
+
673
+ /**
674
+ * Text alignment.
675
+ *
676
+ * Defaults to `left`.
677
+ */
678
+ alignment?: Alignment | undefined;
679
+
680
+ /**
681
+ * Text color.
682
+ *
683
+ * Supports well-known color names like `blue` or hexadecimal color strings like `#ccffcc`.
684
+ *
685
+ * Defaults to `black`.
686
+ */
687
+ color?: string | undefined;
688
+
689
+ /**
690
+ * Background color of the text.
691
+ *
692
+ * Supports well-known color names like `blue` or hexadecimal color strings like `#ccffcc`,
693
+ * as well as a reference to a pattern.
694
+ *
695
+ * To set the background of table cells, use {@link fillColor} instead.
696
+ */
697
+ background?: string | PatternFill | undefined;
698
+
699
+ /**
700
+ * Color of list markers (i.e. bullet points or numbers).
701
+ *
702
+ * Supports well-known color names like `blue` or hexadecimal color strings like `#ccffcc`.
703
+ *
704
+ * Defaults to the text's {@link color}.
705
+ */
706
+ markerColor?: string | undefined;
707
+
708
+ /**
709
+ * Text decoration to apply.
710
+ */
711
+ decoration?: Decoration | Decoration[] | undefined;
712
+
713
+ /**
714
+ * Style to apply to the given {@link decoration}.
715
+ *
716
+ * Defaults to `solid`.
717
+ */
718
+ decorationStyle?: DecorationStyle | undefined;
719
+
720
+ /**
721
+ * Color to apply to the given {@link decoration}.
722
+ *
723
+ * Supports well-known color names like `blue` or hexadecimal color strings like `#ccffcc`.
724
+ *
725
+ * Defaults to the text's {@link color}.
726
+ */
727
+ decorationColor?: string | undefined;
728
+
729
+ /**
730
+ * Line thickness of the {@link decoration} in `pt`.
731
+ *
732
+ * If used in combination with a {@link decorationStyle}, this value is only used as a baseline
733
+ * for the computation of the actual line width.
734
+ *
735
+ * Defaults to a value derived from the {@link fontSize}.
736
+ */
737
+ decorationThickness?: number | undefined;
738
+
739
+ /**
740
+ * Margins to apply.
741
+ *
742
+ * Overrides the single-side `marginXXX` properties, unless this value is inherited
743
+ * from another style.
744
+ *
745
+ * Ignored for content within an inline text array
746
+ * (`{ text: [{ ... }] }`).
747
+ */
748
+ margin?: Margins | undefined;
749
+
750
+ /**
751
+ * Margin in `pt` to apply above the content.
752
+ *
753
+ * If {@link margin} is set, this value is ignored, unless the margin was inherited
754
+ * from another style.
755
+ */
756
+ marginTop?: number | undefined;
757
+
758
+ /**
759
+ * Margin in `pt` to apply to the right of the content.
760
+ *
761
+ * If {@link margin} is set, this value is ignored, unless the margin was inherited
762
+ * from another style.
763
+ */
764
+ marginRight?: number | undefined;
765
+
766
+ /**
767
+ * Margin in `pt` to apply below the content.
768
+ *
769
+ * If {@link margin} is set, this value is ignored, unless the margin was inherited
770
+ * from another style.
771
+ */
772
+ marginBottom?: number | undefined;
773
+
774
+ /**
775
+ * Margin in `pt` to apply to the left of the content.
776
+ *
777
+ * If {@link margin} is set, this value is ignored, unless the margin was inherited
778
+ * from another style.
779
+ */
780
+ marginLeft?: number | undefined;
781
+
782
+ /**
783
+ * Controls whether to preserve spaces at the beginning of a paragraph.
784
+ *
785
+ * Defaults to `false`.
786
+ */
787
+ preserveLeadingSpaces?: boolean | undefined;
788
+
789
+ /**
790
+ * Controls whether to preserve spaces at the end of a paragraph.
791
+ *
792
+ * Defaults to `false`.
793
+ */
794
+ preserveTrailingSpaces?: boolean | undefined;
795
+
796
+ /**
797
+ * Opacity of the content.
798
+ * Must be between 0 (fully transparent) and 1 (fully opaque).
799
+ *
800
+ * Defaults to `1`.
801
+ */
802
+ opacity?: number | undefined;
803
+
804
+ /**
805
+ * Spacing between characters in `pt`.
806
+ *
807
+ * Defaults to `0`.
808
+ */
809
+ characterSpacing?: number | undefined;
810
+
811
+ /**
812
+ * Indent at the beginning of a paragraph in `pt`.
813
+ *
814
+ * Defaults to `0`.
815
+ */
816
+ leadingIndent?: number | undefined;
817
+
818
+ /**
819
+ * Controls whether the text is rendered as superscript.
820
+ *
821
+ * Defaults to `false`.
822
+ */
823
+ sup?: boolean | undefined;
824
+
825
+ /**
826
+ * Controls whether the text is rendered as subscript.
827
+ *
828
+ * Defaults to `false`.
829
+ */
830
+ sub?: boolean | undefined;
831
+
832
+ /**
833
+ * Background fill color for table cells.
834
+ *
835
+ * Supports well-known color names like `blue` or hexadecimal color strings like `#ccffcc`,
836
+ * as well as a reference to a pattern.
837
+ *
838
+ * Only applies to {@link TableCell} elements.
839
+ * For the background color of text, use {@link background} instead.
840
+ */
841
+ fillColor?: string | PatternFill | undefined;
842
+
843
+ /**
844
+ * Opacity of the given {@link fillColor}.
845
+ * Must be between 0 (fully transparent) and 1 (fully opaque).
846
+ *
847
+ * Only applies to {@link TableCell} elements.
848
+ *
849
+ * Defaults to `1`.
850
+ */
851
+ fillOpacity?: number | undefined;
852
+
853
+ /**
854
+ * Controls whether text paragraphs inside table cells should be rendered as
855
+ * a single line.
856
+ * If the column has a fixed width, long text lines will overflow the column;
857
+ * otherwise, the column will grow in width.
858
+ *
859
+ * Only applies to {@link TableCell} elements.
860
+ *
861
+ * defaults to `false`.
862
+ */
863
+ noWrap?: boolean | undefined;
864
+
865
+ /**
866
+ * Controls the line breaking behavior.
867
+ *
868
+ * - `normal` breaks lines at spaces
869
+ * - `break-all` breaks lines anywhere
870
+ *
871
+ * Defaults to `normal`.
872
+ */
873
+ wordBreak?: "normal" | "break-all" | undefined;
874
+
875
+ /**
876
+ * Space between columns in `pt`.
877
+ *
878
+ * Only applies to {@link ContentColumns} elements.
879
+ *
880
+ * Defaults to `0`.
881
+ */
882
+ columnGap?: number | undefined;
883
+ }
884
+
885
+ /**
886
+ * Named style defined in {@link TDocumentDefinitions.styles}.
887
+ */
888
+ export interface NamedStyle extends Style {
889
+ /**
890
+ * Names of other styles in {@link TDocumentDefinitions.styles} to extend.
891
+ *
892
+ * An array applies the styles in the given order, later styles overriding
893
+ * properties from the earlier ones.
894
+ *
895
+ * Extended styles are overridden by the properties on this style.
896
+ */
897
+ extends?: string | string[] | undefined;
898
+ }
899
+
900
+ /**
901
+ * Applies one or more styles.
902
+ *
903
+ * - A string references a named style from {@link TDocumentDefinitions.styles}
904
+ * - An object sets the given style properties
905
+ * - An array of strings or objects applies the styles in the given order,
906
+ * later styles overriding properties from the earlier ones
907
+ *
908
+ * Styles defined this way can be overridden by the {@link Style} properties on an element itself.
909
+ */
910
+ export type StyleReference = string | Style | Array<string | Style>;
911
+
912
+ /**
913
+ * Common type for all available content elements.
914
+ *
915
+ * Special content types:
916
+ * - A string is rendered like a {@link ContentText}
917
+ * - An array is rendered like a {@link ContentStack}
918
+ */
919
+ export type Content =
920
+ | string
921
+ | number
922
+ | Content[]
923
+ | ContentText
924
+ | ContentColumns
925
+ | ContentStack
926
+ | ContentUnorderedList
927
+ | ContentOrderedList
928
+ | ContentTable
929
+ | ContentAnchor
930
+ | ContentPageReference
931
+ | ContentTextReference
932
+ | ContentToc
933
+ | ContentTocItem
934
+ | ContentImage
935
+ | ContentSvg
936
+ | ContentQr
937
+ | ContentCanvas
938
+ // Even though only allowed on the document root level, sections can be nested e.g. in stacks,
939
+ // so we treat them like normal content elements
940
+ | ContentSection
941
+ | ContentAttachment;
942
+
943
+ /**
944
+ * Internal helper type to prevent TypeScript from allowing
945
+ * invalid element definitions.
946
+ *
947
+ * Content element types should not use this type directly, but extend
948
+ * {@link ForbidOtherElementProperties} instead.
949
+ */
950
+ interface ForbiddenElementProperties {
951
+ text?: never;
952
+ columns?: never;
953
+ stack?: never;
954
+ ul?: never;
955
+ ol?: never;
956
+ table?: never;
957
+ pageReference?: never;
958
+ textReference?: never;
959
+ toc?: never;
960
+ image?: never;
961
+ svg?: never;
962
+ qr?: never;
963
+ canvas?: never;
964
+ section?: never;
965
+ attachment?: never;
966
+ }
967
+
968
+ /**
969
+ * Internal helper type to prevent TypeScript from allowing element definitions
970
+ * that contain multiple element types at once.
971
+ *
972
+ * Advantages:
973
+ * - Does not allow setting multiple element properties together (e.g. `ol` + `ul`)
974
+ * - Does not allow using optional properties from other element types
975
+ *
976
+ * Disadvantages:
977
+ * - `property in content` does not narrow the type any longer
978
+ * - Autocompletion does not sort the primary element properties at the top
979
+ * - Error messages are not very good
980
+ */
981
+ type ForbidOtherElementProperties<TProperty extends keyof ForbiddenElementProperties> = Omit<
982
+ ForbiddenElementProperties,
983
+ TProperty
984
+ >;
985
+
986
+ /**
987
+ * Document attachment.
988
+ *
989
+ * For linking an attachment to a custom image, use {@link ContentImage.linkToFile} instead.
990
+ */
991
+ export interface ContentAttachment extends ForbidOtherElementProperties<"attachment"> {
992
+ /**
993
+ * Attachment to the document, either declared inline or referenced by name from
994
+ * {@link TDocumentDefinitions.attachments} or {@link TDocumentDefinitions.files}.
995
+ */
996
+ attachment: Attachment | string;
997
+
998
+ /**
999
+ * Icon for the attachment.
1000
+ *
1001
+ * Defaults to `Push`.
1002
+ */
1003
+ icon?: "Push" | "GraphPush" | "Paperclip" | undefined;
1004
+ }
1005
+
1006
+ /**
1007
+ * Text element.
1008
+ *
1009
+ * For simple text without other properties, a string can be used instead of this element.
1010
+ */
1011
+ export interface ContentText extends ContentLink, ContentBase, ForbidOtherElementProperties<"text"> {
1012
+ /**
1013
+ * Text content.
1014
+ *
1015
+ * Makes its contents inline: Arrays are no longer rendered like {@link ContentStack}
1016
+ * below one another, but as inline text in a single paragraph.
1017
+ */
1018
+ text: Content;
1019
+ }
1020
+
1021
+ /**
1022
+ * Element that divides its children into multiple columns.
1023
+ */
1024
+ export interface ContentColumns extends ContentBase, ForbidOtherElementProperties<"columns"> {
1025
+ /** Divides the given elements into multiple columns. */
1026
+ columns: Column[];
1027
+ }
1028
+
1029
+ /**
1030
+ * Stack that renders its children as multiple paragraphs.
1031
+ *
1032
+ * For simple stacks without properties, a content array can be used instead.
1033
+ */
1034
+ export interface ContentStack extends ContentBase, ForbidOtherElementProperties<"stack"> {
1035
+ /**
1036
+ * Stack that renders the given elements as multiple paragraphs.
1037
+ *
1038
+ * For simple stacks without properties, a content array can be used instead.
1039
+ */
1040
+ stack: Content[];
1041
+ }
1042
+
1043
+ /**
1044
+ * Element that renders an ordered / numbered list.
1045
+ */
1046
+ export interface ContentOrderedList extends ContentBase, ForbidOtherElementProperties<"ol"> {
1047
+ /**
1048
+ * Renders the given elements as an ordered / numbered list.
1049
+ */
1050
+ ol: OrderedListElement[];
1051
+
1052
+ /**
1053
+ * List marker type determining the numbering scheme, such as decimal, alphabetic, or Roman.
1054
+ *
1055
+ * Defaults to `decimal`.
1056
+ */
1057
+ type?: OrderedListType | undefined;
1058
+
1059
+ /**
1060
+ * Separator between the list markers and the list item content.
1061
+ *
1062
+ * - A string is inserted after the marker
1063
+ * - A tuple of two strings is inserted before and after the marker
1064
+ *
1065
+ * Defaults to `.`
1066
+ */
1067
+ separator?: string | [string, string] | undefined;
1068
+
1069
+ /**
1070
+ * Controls whether the markers should be rendered in descending order.
1071
+ *
1072
+ * Defaults to `false`.
1073
+ */
1074
+ reversed?: boolean | undefined;
1075
+
1076
+ /**
1077
+ * Number of the first marker.
1078
+ *
1079
+ * For a non-decimal {@link type}, the number is mapped to the corresponding
1080
+ * marker string (e.g. `1` => `A` for `upper-alpha`).
1081
+ *
1082
+ * Defaults to `1`, or the number of items if {@link reversed} is set.
1083
+ */
1084
+ start?: number | undefined;
1085
+ }
1086
+
1087
+ /**
1088
+ * Element that renders an unordered / bulleted list element.
1089
+ */
1090
+ export interface ContentUnorderedList extends ContentBase, ForbidOtherElementProperties<"ul"> {
1091
+ /**
1092
+ * Renders the given elements as an unordered / bulleted list.
1093
+ */
1094
+ ul: UnorderedListElement[];
1095
+
1096
+ /**
1097
+ * List marker type.
1098
+ *
1099
+ * Defaults to `disc`.
1100
+ */
1101
+ type?: UnorderedListType | undefined;
1102
+ }
1103
+
1104
+ /**
1105
+ * Canvas / vector element.
1106
+ */
1107
+ export interface ContentCanvas extends ContentBase, ForbidOtherElementProperties<"canvas"> {
1108
+ /**
1109
+ * Renders the given vector elements on a canvas.
1110
+ *
1111
+ * Complex vectors can be rendered from an SVG image using the `svg` property instead.
1112
+ */
1113
+ canvas: CanvasElement[];
1114
+ }
1115
+
1116
+ /**
1117
+ * SVG image element.
1118
+ *
1119
+ * For images other than SVG, use a {@link ContentImage} instead.
1120
+ */
1121
+ export interface ContentSvg extends ContentBase, ContentLink, ForbidOtherElementProperties<"svg"> {
1122
+ /**
1123
+ * Renders the given SVG element or content string as an image.
1124
+ *
1125
+ * For images other than SVG, use the `image` property instead.
1126
+ *
1127
+ * Simple vectors can also be rendered using the `canvas` property instead.
1128
+ */
1129
+ svg: string | SVGElement;
1130
+
1131
+ /**
1132
+ * Width of the image in `pt`.
1133
+ *
1134
+ * Unlike JPEG or PNG images, SVG images always keep their aspect ratio.
1135
+ * If the given width is larger than the image's width scaled to the given {@link height},
1136
+ * the image is centered horizontally.
1137
+ * To prevent this behavior, either specify only one of the two properties, or use {@link fit}
1138
+ * instead.
1139
+ *
1140
+ * Defaults to the SVG image's native width, or scales it down
1141
+ * proportionally if a {@link height} is given.
1142
+ */
1143
+ width?: number | undefined;
1144
+
1145
+ /**
1146
+ * Height of the image in `pt`.
1147
+ *
1148
+ * Unlike JPEG or PNG images, SVG images always keep their aspect ratio.
1149
+ * If the given height is larger than the image's height scaled to the given {@link width},
1150
+ * the image is centered vertically.
1151
+ * To prevent this behavior, either specify only one of the two properties, or use {@link fit}
1152
+ * instead.
1153
+ *
1154
+ * Defaults to the SVG image's native height, or scales it down
1155
+ * proportionally if a {@link width} is given.
1156
+ */
1157
+ height?: number | undefined;
1158
+
1159
+ /**
1160
+ * Box the image is scaled to fit inside, preserving its aspect ratio.
1161
+ *
1162
+ * The image only occupies the space of its own size after scaling,
1163
+ * even if one side of the box is larger.
1164
+ *
1165
+ * Tuple elements: `[width, height]`.
1166
+ */
1167
+ fit?: [number, number] | undefined;
1168
+ }
1169
+
1170
+ /**
1171
+ * Raster image element.
1172
+ *
1173
+ * For SVG images, use a {@link ContentSvg} element instead.
1174
+ */
1175
+ export interface ContentImage extends ContentLink, ContentBase, ForbidOtherElementProperties<"image"> {
1176
+ /**
1177
+ * Renders the given value as image.
1178
+ *
1179
+ * Available options:
1180
+ * - A reference by name to an image defined in {@link TDocumentDefinitions.images}
1181
+ * - A data URL
1182
+ * - A remote URL via http:// or https://
1183
+ *
1184
+ * Supported image formats: JPEG, PNG
1185
+ *
1186
+ * For SVG images, use the `svg` property instead.
1187
+ */
1188
+ image: string;
1189
+
1190
+ /**
1191
+ * Width of the image in `pt`.
1192
+ *
1193
+ * If a {@link height} is given as well, the image is stretched to
1194
+ * the given dimensions without preserving its aspect ratio.
1195
+ * To prevent this behavior, either specify only one of the two properties, or use {@link fit}
1196
+ * instead.
1197
+ *
1198
+ * Defaults to the image's native width, or scales it down
1199
+ * proportionally if a {@link height} is given.
1200
+ */
1201
+ width?: number | undefined;
1202
+
1203
+ /**
1204
+ * Height of the image in `pt`.
1205
+ *
1206
+ * If a {@link width} is given as well, the image is stretched to
1207
+ * the given dimensions without preserving its aspect ratio.
1208
+ * To prevent this behavior, either specify only one of the two properties, or use {@link fit}
1209
+ * instead.
1210
+ *
1211
+ * Defaults to the image's native height, or scales it down
1212
+ * proportionally if a {@link width} is given.
1213
+ */
1214
+ height?: number | undefined;
1215
+
1216
+ /**
1217
+ * Box the image is scaled to fit inside, preserving its aspect ratio.
1218
+ *
1219
+ * The image only occupies the space of its own size after scaling,
1220
+ * even if one side of the box is larger.
1221
+ *
1222
+ * Tuple elements: `[width, height]`.
1223
+ */
1224
+ fit?: [number, number] | undefined;
1225
+
1226
+ /**
1227
+ * Container to completely cover with an image, possibly cutting it off horizontally
1228
+ * or vertically.
1229
+ */
1230
+ cover?: ImageCover | undefined;
1231
+
1232
+ /**
1233
+ * Links the image to an attachment, either declared inline or referenced by name from
1234
+ * {@link TDocumentDefinitions.attachments} or {@link TDocumentDefinitions.files}.
1235
+ */
1236
+ linkToFile?: Attachment | string | undefined;
1237
+ }
1238
+
1239
+ /**
1240
+ * Table element.
1241
+ */
1242
+ export interface ContentTable extends ContentBase, ForbidOtherElementProperties<"table"> {
1243
+ /**
1244
+ * Renders a table.
1245
+ *
1246
+ * Use the {@link layout} property to control its layout.
1247
+ */
1248
+ table: Table;
1249
+
1250
+ /**
1251
+ * Layout for the table, or a reference to a predefined or global layout.
1252
+ *
1253
+ * Defaults to a layout with black borders.
1254
+ */
1255
+ layout?: TableLayout | undefined;
1256
+ }
1257
+
1258
+ /**
1259
+ * Anchor text element that can be referenced by cross references or
1260
+ * used in a table of contents.
1261
+ *
1262
+ * Anchors can contain text content only.
1263
+ */
1264
+ export interface ContentAnchor extends ContentBase, ForbidOtherElementProperties<"text"> {
1265
+ /**
1266
+ * Text content of the anchor.
1267
+ */
1268
+ text: string | ContentAnchor | Array<string | ContentAnchor>;
1269
+
1270
+ /**
1271
+ * ID of the anchor that can be used to reference it.
1272
+ *
1273
+ * IDs must be unique within the document.
1274
+ */
1275
+ id: string;
1276
+ }
1277
+
1278
+ /**
1279
+ * Text element to be displayed in a table of contents.
1280
+ */
1281
+ export interface ContentTocItem extends ContentBase, ForbidOtherElementProperties<"text"> {
1282
+ /**
1283
+ * Text content of the element.
1284
+ *
1285
+ * Limited to text only; other content cannot be rendered inside a
1286
+ * table of contents.
1287
+ */
1288
+ text: string | ContentTocItem | Array<string | ContentTocItem>;
1289
+
1290
+ /**
1291
+ * References to the tables of contents the element should be displayed in.
1292
+ *
1293
+ * - `true` will display the element in all {@link ContentToc} elements that
1294
+ * do not have an `id` set
1295
+ * - a string will display the element in the {@link ContentToc} with matching `id`
1296
+ * - an array will display the element in all {@link ContentToc}
1297
+ * elements with matching `id` properties (`true` for the default one
1298
+ * without an `id`)
1299
+ */
1300
+ tocItem: boolean | string | Array<string | boolean>;
1301
+
1302
+ /**
1303
+ * Style or style reference that is applied to the reference for this element
1304
+ * in the table of contents.
1305
+ */
1306
+ tocStyle?: StyleReference | undefined;
1307
+
1308
+ /**
1309
+ * Style or style reference that is applied to the page number for this element
1310
+ * in the table of contents.
1311
+ */
1312
+ tocNumberStyle?: StyleReference | undefined;
1313
+
1314
+ /**
1315
+ * Margin that is applied to the reference for this element in the table of
1316
+ * contents.
1317
+ */
1318
+ tocMargin?: Margins | undefined;
1319
+ }
1320
+
1321
+ /**
1322
+ * Reference to an anchor element, displaying its page number.
1323
+ */
1324
+ export interface ContentPageReference extends ContentBase, ForbidOtherElementProperties<"pageReference"> {
1325
+ /**
1326
+ * `id` of a {@link ContentAnchor} to reference.
1327
+ *
1328
+ * Displays the target element's page number.
1329
+ * - To display the element's text content, use `textReference` instead.
1330
+ * - To display arbitrary content, use `linkToDestination` instead.
1331
+ *
1332
+ * To link to a fixed page number (without a reference target), use `linkToPage` instead.
1333
+ */
1334
+ pageReference: string;
1335
+ }
1336
+
1337
+ /**
1338
+ * Reference to an anchor element, displaying its text content.
1339
+ */
1340
+ export interface ContentTextReference extends ContentBase, ForbidOtherElementProperties<"textReference"> {
1341
+ /**
1342
+ * `id` of a {@link ContentAnchor} to reference.
1343
+ *
1344
+ * Displays the target element's text content.
1345
+ * - To display its page number, use `pageReference` instead.
1346
+ * - To display arbitrary content, use `linkToDestination` instead.
1347
+ */
1348
+ textReference: string;
1349
+ }
1350
+
1351
+ /**
1352
+ * Table of contents element.
1353
+ */
1354
+ export interface ContentToc extends ContentBase, ForbidOtherElementProperties<"toc"> {
1355
+ /**
1356
+ * Renders a table of contents.
1357
+ *
1358
+ * One document may contain more than one table of contents.
1359
+ * In this case, you should assign each additional table of contents a unique `id`.
1360
+ * This allows you to add items to it using the {@link ContentTocItem.tocItem} property.
1361
+ */
1362
+ toc: TableOfContent;
1363
+ }
1364
+
1365
+ /**
1366
+ * QR code element.
1367
+ */
1368
+ export interface ContentQr extends ContentBase, ForbidOtherElementProperties<"qr"> {
1369
+ /**
1370
+ * Renders the given string as a QR code.
1371
+ */
1372
+ qr: string;
1373
+
1374
+ /**
1375
+ * Foreground color of the QR code.
1376
+ *
1377
+ * Supports well-known color names like `blue` or hexadecimal color strings like `#ccffcc`.
1378
+ *
1379
+ * Defaults to `black`.
1380
+ */
1381
+ foreground?: string | undefined;
1382
+
1383
+ /**
1384
+ * Background color of the QR code.
1385
+ *
1386
+ * Supports well-known color names like `blue` or hexadecimal color strings like `#ccffcc`.
1387
+ *
1388
+ * Defaults to `white`.
1389
+ */
1390
+ background?: string | undefined;
1391
+
1392
+ /**
1393
+ * Size in `pt` to fit the QR code in.
1394
+ *
1395
+ * As QR codes are square, this essentially sets both the width and height.
1396
+ *
1397
+ * Defaults to a heuristic depending on the pixel size of the QR code (see {@link version})
1398
+ * so that every pixel is `5pt` large.
1399
+ */
1400
+ fit?: number | undefined;
1401
+
1402
+ /**
1403
+ * QR code version.
1404
+ *
1405
+ * The "version" of a QR code controls the number of its pixels and thus the maximum amount of
1406
+ * data it can hold.
1407
+ *
1408
+ * Possible values are between 1 (21x21 pixels) and 40 (177x177 pixels).
1409
+ *
1410
+ * Defaults to the lowest possible version capable of holding the given {@link qr} data
1411
+ * with the specified {@link mode} and {@link eccLevel}.
1412
+ */
1413
+ version?: number | undefined;
1414
+
1415
+ /**
1416
+ * QR code error correction level that controls how many errors can be corrected.
1417
+ *
1418
+ * Possible values:
1419
+ * - `L` = low (7%)
1420
+ * - `M` = medium (15%)
1421
+ * - `Q` = quartile (25%)
1422
+ * - `H` = high (30%)
1423
+ *
1424
+ * Defaults to `L`.
1425
+ */
1426
+ eccLevel?: "L" | "M" | "Q" | "H" | undefined;
1427
+
1428
+ /**
1429
+ * QR code encoding mode.
1430
+ *
1431
+ * Defaults to the mode that produces the smallest payload for the given {@link qr} data.
1432
+ */
1433
+ mode?: "numeric" | "alphanumeric" | "octet" | undefined;
1434
+
1435
+ /**
1436
+ * QR code mask pattern from 0-7.
1437
+ *
1438
+ * Defaults to choosing a mask based on the given {@link qr} data that tries to
1439
+ * avoid problematic patterns in the resulting QR code.
1440
+ */
1441
+ mask?: number | undefined;
1442
+
1443
+ /**
1444
+ * Padding on all sides of the QR code, specified as multiples of the size of a QR code pixel.
1445
+ *
1446
+ * The padding does not affect the size of the QR code itself, even if {@link fit} is specified.
1447
+ *
1448
+ * Defaults to `0`.
1449
+ */
1450
+ padding?: number | undefined;
1451
+ }
1452
+
1453
+ /**
1454
+ * Base type for most content elements.
1455
+ */
1456
+ export interface ContentBase extends Style {
1457
+ /**
1458
+ * Style or style reference to apply.
1459
+ */
1460
+ style?: StyleReference | undefined;
1461
+
1462
+ /**
1463
+ * Absolute position of the element from the top-left corner of the current page.
1464
+ *
1465
+ * If set, the element does not occupy any space in the normal content layout.
1466
+ *
1467
+ * In this case, the element is rendered above elements defined earlier in the
1468
+ * document content, but below elements defined later.
1469
+ */
1470
+ absolutePosition?: Position | undefined;
1471
+
1472
+ /**
1473
+ * Relative position of the element from the position it would normally be rendered in.
1474
+ *
1475
+ * If set, the element does not occupy any space in the normal content layout.
1476
+ *
1477
+ * In this case, the element is rendered above elements defined earlier in the
1478
+ * document content, but below elements defined later.
1479
+ */
1480
+ relativePosition?: Position | undefined;
1481
+
1482
+ /**
1483
+ * Controls whether to insert a page break before or after the element.
1484
+ *
1485
+ * For more complex page break logic, use {@link TDocumentDefinitions.pageBreakBefore}.
1486
+ */
1487
+ pageBreak?: PageBreak | undefined;
1488
+
1489
+ /**
1490
+ * Sets the page orientation.
1491
+ *
1492
+ * Only relevant when used in combination with {@link pageBreak}.
1493
+ */
1494
+ pageOrientation?: PageOrientation | undefined;
1495
+
1496
+ /**
1497
+ * Sets the headline level for the current element.
1498
+ *
1499
+ * This value is not currently used by pdfmake itself.
1500
+ * It is, however, passed to the {@link TDocumentDefinitions.pageBreakBefore} callback, where you
1501
+ * can use it to automatically insert page breaks before elements with certain headline levels.
1502
+ */
1503
+ headlineLevel?: number | undefined;
1504
+
1505
+ /**
1506
+ * Controls whether the element should be kept together on the same page.
1507
+ *
1508
+ * Defaults to `false`.
1509
+ */
1510
+ unbreakable?: boolean | undefined;
1511
+ }
1512
+
1513
+ /**
1514
+ * Link element.
1515
+ * Extended by {@link ContentText} and {@link ContentImage}.
1516
+ */
1517
+ export interface ContentLink {
1518
+ /**
1519
+ * URL to open when the element is clicked on.
1520
+ *
1521
+ * Use in combination with a `text` or `image` property.
1522
+ */
1523
+ link?: string | undefined;
1524
+
1525
+ /**
1526
+ * Page to jump to when the element is clicked on.
1527
+ *
1528
+ * Use in combination with a `text` or `image` property.
1529
+ *
1530
+ * To link to another element, use {@link linkToDestination}, `textReference`
1531
+ * or `pageReference` instead.
1532
+ */
1533
+ linkToPage?: number | undefined;
1534
+
1535
+ /**
1536
+ * `id` of an element to jump to when the element is clicked on.
1537
+ *
1538
+ * Use in combination with a `text` or `image` property.
1539
+ *
1540
+ * - To display the target element's content, use `textReference` instead.
1541
+ * - To display the target element's page number, use `pageReference` instead.
1542
+ *
1543
+ * To link to a fixed page number (without a reference target), use `linkToPage` instead.
1544
+ */
1545
+ linkToDestination?: string | undefined;
1546
+ }
1547
+
1548
+ /**
1549
+ * Document section. Only allowed at the root level of the document.
1550
+ */
1551
+ export interface ContentSection extends ForbidOtherElementProperties<"section"> {
1552
+ /**
1553
+ * Content within the document section.
1554
+ */
1555
+ section: Content;
1556
+
1557
+ /**
1558
+ * Size of the section's pages.
1559
+ *
1560
+ * Defaults to the document-wide value.
1561
+ */
1562
+ pageSize?: TDocumentDefinitions["pageSize"] | "inherit" | null;
1563
+
1564
+ /**
1565
+ * Orientation of the section's pages.
1566
+ *
1567
+ * Defaults to the document-wide value.
1568
+ */
1569
+ pageOrientation?: TDocumentDefinitions["pageOrientation"] | "inherit" | null;
1570
+
1571
+ /**
1572
+ * Margins around the content on each page of the section.
1573
+ *
1574
+ * Defaults to the document-wide value.
1575
+ */
1576
+ pageMargins?: TDocumentDefinitions["pageMargins"] | "inherit" | null;
1577
+
1578
+ /**
1579
+ * Header content that is repeated on every page of the section.
1580
+ *
1581
+ * Defaults to the document-wide value.
1582
+ */
1583
+ header?: TDocumentDefinitions["header"] | "inherit" | null;
1584
+
1585
+ /**
1586
+ * Footer content that is repeated on every page of the section.
1587
+ *
1588
+ * Defaults to the document-wide value.
1589
+ */
1590
+ footer?: TDocumentDefinitions["footer"] | "inherit" | null;
1591
+
1592
+ /**
1593
+ * Content that is rendered behind the section's content, and repeated for every page.
1594
+ *
1595
+ * Defaults to the document-wide value.
1596
+ */
1597
+ background?: TDocumentDefinitions["background"] | "inherit" | null;
1598
+
1599
+ /**
1600
+ * Watermark that is rendered on top of each page of the section.
1601
+ *
1602
+ * Defaults to the document-wide value.
1603
+ */
1604
+ watermark?: TDocumentDefinitions["watermark"] | "inherit" | null;
1605
+ }
1606
+
1607
+ /**
1608
+ * Table of contents.
1609
+ *
1610
+ * One document may contain more than one table of contents.
1611
+ * In this case, you should assign each additional table of contents a unique `id`.
1612
+ * This allows you to add items to it using the {@link ContentTocItem.tocItem} property.
1613
+ */
1614
+ export interface TableOfContent {
1615
+ /**
1616
+ * Title displayed at the top of the table of contents.
1617
+ */
1618
+ title?: Content | undefined;
1619
+
1620
+ /**
1621
+ * Margin around each item in `pt`.
1622
+ *
1623
+ * Can be overridden per item using {@link ContentTocItem.tocMargin}.
1624
+ *
1625
+ * Defaults to `0`.
1626
+ */
1627
+ textMargin?: Margins | undefined;
1628
+
1629
+ /**
1630
+ * Style or style reference to apply to each item.
1631
+ *
1632
+ * Can be overridden per item using {@link ContentTocItem.tocStyle}.
1633
+ */
1634
+ textStyle?: StyleReference | undefined;
1635
+
1636
+ /**
1637
+ * Style or style reference to apply to the page numbers.
1638
+ *
1639
+ * Can be overridden per item using {@link ContentTocItem.tocNumberStyle}.
1640
+ */
1641
+ numberStyle?: StyleReference | undefined;
1642
+
1643
+ /**
1644
+ * ID to differentiate multiple tables of contents:
1645
+ * - Without an ID set, a table of content contains all items setting
1646
+ * {@link ContentTocItem.tocItem} to `true`
1647
+ * - With an ID set, a table of content contains all items setting
1648
+ * {@link ContentTocItem.tocItem} to its ID
1649
+ */
1650
+ id?: string | undefined;
1651
+
1652
+ /**
1653
+ * If set to `true`, the table of contents is hidden when it contains no items.
1654
+ */
1655
+ hideEmpty?: boolean | undefined;
1656
+
1657
+ /**
1658
+ * Controls how the items are sorted.
1659
+ *
1660
+ * Defaults to `page`.
1661
+ */
1662
+ sortBy?: "page" | "title" | undefined;
1663
+
1664
+ /**
1665
+ * Specifies the locale used for sorting as BCP 47 language tag, e.g. `en-US`.
1666
+ *
1667
+ * Only relevant if {@link sortBy} is set to `title`.
1668
+ *
1669
+ * Defaults to the system locale.
1670
+ */
1671
+ sortLocale?: string | undefined;
1672
+ }
1673
+
1674
+ /**
1675
+ * Additional properties of {@link Content} objects that are used as columns.
1676
+ */
1677
+ export interface ColumnProperties {
1678
+ /**
1679
+ * Column width.
1680
+ *
1681
+ * Defaults to `*`.
1682
+ */
1683
+ width?: Size | undefined;
1684
+ }
1685
+
1686
+ /**
1687
+ * Column used as part of {@link ContentColumns}.
1688
+ */
1689
+ export type Column = Content & ColumnProperties;
1690
+
1691
+ /**
1692
+ * List marker type of a {@link ContentOrderedList}:
1693
+ * - `decimal`: 1, 2, 3
1694
+ * - `lower-alpha`: a, b, c
1695
+ * - `upper-alpha`: A, B, C
1696
+ * - `lower-roman`: i, ii, iii
1697
+ * - `upper-roman`: I, II, III
1698
+ * - `none`: no marker
1699
+ */
1700
+ export type OrderedListType =
1701
+ | "decimal"
1702
+ | "lower-alpha"
1703
+ | "upper-alpha"
1704
+ | "lower-roman"
1705
+ | "upper-roman"
1706
+ | "none";
1707
+
1708
+ /**
1709
+ * Additional properties of {@link Content} objects that are used as items
1710
+ * of an ordered list.
1711
+ */
1712
+ export interface OrderedListElementProperties {
1713
+ /**
1714
+ * Overrides the counter for this list item.
1715
+ *
1716
+ * For a non-decimal {@link listType}, the number is mapped to the corresponding
1717
+ * marker string (e.g. `1` => `A` for `upper-alpha`).
1718
+ *
1719
+ * Does not influence the counters for the other list items.
1720
+ */
1721
+ counter?: number | undefined;
1722
+
1723
+ /**
1724
+ * Overrides the list marker type for this list item.
1725
+ *
1726
+ * Defaults to the list's {@link ContentOrderedList.type}.
1727
+ */
1728
+ listType?: OrderedListType | undefined;
1729
+
1730
+ /**
1731
+ * Color of the list marker (i.e. number).
1732
+ *
1733
+ * Supports well-known color names like `blue` or hexadecimal color strings like `#ccffcc`.
1734
+ *
1735
+ * Defaults to the list's marker color.
1736
+ */
1737
+ markerColor?: string | undefined;
1738
+ }
1739
+
1740
+ /**
1741
+ * Item of a {@link ContentOrderedList}.
1742
+ */
1743
+ export type OrderedListElement = Content & OrderedListElementProperties;
1744
+
1745
+ /**
1746
+ * List marker type of a {@link ContentUnorderedList}:
1747
+ * - `disc`: a solid circle
1748
+ * - `square`: a solid square
1749
+ * - `circle`: an outlined circle
1750
+ * - `none`: no marker
1751
+ */
1752
+ export type UnorderedListType = "disc" | "square" | "circle" | "none";
1753
+
1754
+ /**
1755
+ * Additional properties of {@link Content} objects that are used as items
1756
+ * of an unordered list.
1757
+ */
1758
+ export interface UnorderedListElementProperties {
1759
+ /**
1760
+ * Overrides the list marker type for this list item.
1761
+ *
1762
+ * Defaults to the list's {@link ContentUnorderedList.type}.
1763
+ */
1764
+ listType?: UnorderedListType | undefined;
1765
+
1766
+ /**
1767
+ * Color of the list marker (i.e. bullet point).
1768
+ *
1769
+ * Supports well-known color names like `blue` or hexadecimal color strings like `#ccffcc`.
1770
+ *
1771
+ * Defaults to the list's marker color.
1772
+ */
1773
+ markerColor?: string | undefined;
1774
+ }
1775
+
1776
+ /**
1777
+ * Item of a {@link ContentUnorderedList}.
1778
+ */
1779
+ export type UnorderedListElement = Content & UnorderedListElementProperties;
1780
+
1781
+ /**
1782
+ * Child elements of a {@link ContentCanvas}.
1783
+ */
1784
+ export type CanvasElement = CanvasRect | CanvasPolyline | CanvasLine | CanvasEllipse;
1785
+
1786
+ /**
1787
+ * Type to render the ends of lines in a canvas:
1788
+ * - `butt` renders a short square line end
1789
+ * - `square` renders a long square line end
1790
+ * - `round` renders a long round line end
1791
+ */
1792
+ export type CanvasLineCap = "butt" | "round" | "square";
1793
+
1794
+ /**
1795
+ * Type to render joints between lines of different angles in a canvas:
1796
+ * - `miter` renders sharp edges
1797
+ * - `round` renders round edges
1798
+ * - `bevel` adds diagonal edges
1799
+ */
1800
+ export type CanvasLineJoin = "miter" | "round" | "bevel";
1801
+
1802
+ /**
1803
+ * A rectangle as part of a {@link ContentCanvas}.
1804
+ */
1805
+ export interface CanvasRect extends CanvasLineElement, CanvasFilledElement {
1806
+ type: "rect";
1807
+
1808
+ /** Horizontal position from the left edge of the canvas element in `pt`. */
1809
+ x: number;
1810
+
1811
+ /** Vertical position from the top of the canvas element in `pt`. */
1812
+ y: number;
1813
+
1814
+ /** Width in `pt`. */
1815
+ w: number;
1816
+
1817
+ /** Height in `pt`. */
1818
+ h: number;
1819
+
1820
+ /**
1821
+ * Corner radius in `pt`.
1822
+ *
1823
+ * Defaults to `0`.
1824
+ */
1825
+ r?: number | undefined;
1826
+ }
1827
+
1828
+ /**
1829
+ * Point of a {@link CanvasPolyline}.
1830
+ */
1831
+ export interface Point {
1832
+ /** Horizontal position from the left edge of the canvas element in `pt`. */
1833
+ x: number;
1834
+
1835
+ /** Vertical position from the top of the canvas element in `pt`. */
1836
+ y: number;
1837
+ }
1838
+
1839
+ /**
1840
+ * A line or shape consisting of multiple points as part of a {@link ContentCanvas}.
1841
+ */
1842
+ export interface CanvasPolyline extends CanvasLineElement, CanvasFilledElement {
1843
+ type: "polyline";
1844
+
1845
+ /**
1846
+ * The points that make up the line.
1847
+ */
1848
+ points: Point[];
1849
+
1850
+ /**
1851
+ * Controls whether to draw a line between the last and the first specified {@link points}.
1852
+ *
1853
+ * Defaults to `false`.
1854
+ */
1855
+ closePath?: boolean | undefined;
1856
+
1857
+ /**
1858
+ * Line end type.
1859
+ *
1860
+ * Defaults to `butt`.
1861
+ */
1862
+ lineCap?: CanvasLineCap | undefined;
1863
+ }
1864
+
1865
+ /**
1866
+ * A simple line as part of a {@link ContentCanvas}.
1867
+ */
1868
+ export interface CanvasLine extends CanvasLineElement {
1869
+ type: "line";
1870
+
1871
+ /** Horizontal line start position from the left in `pt`. */
1872
+ x1: number;
1873
+
1874
+ /** Vertical line start position from the top in `pt`. */
1875
+ y1: number;
1876
+
1877
+ /** Horizontal line end position from the left in `pt`. */
1878
+ x2: number;
1879
+
1880
+ /** Vertical line end position from the top in `pt`. */
1881
+ y2: number;
1882
+
1883
+ /**
1884
+ * Line end type.
1885
+ *
1886
+ * Defaults to `butt`.
1887
+ */
1888
+ lineCap?: CanvasLineCap | undefined;
1889
+ }
1890
+
1891
+ /**
1892
+ * An ellipse or circle as part of a {@link ContentCanvas}.
1893
+ */
1894
+ export interface CanvasEllipse extends CanvasLineElement, CanvasFilledElement {
1895
+ type: "ellipse";
1896
+
1897
+ /** Horizontal position from the left edge of the canvas element in `pt`. */
1898
+ x: number;
1899
+
1900
+ /** Vertical position from the top edge of the canvas element in `pt`. */
1901
+ y: number;
1902
+
1903
+ /** Horizontal radius in `pt`. */
1904
+ r1: number;
1905
+
1906
+ /**
1907
+ * Vertical radius in `pt`.
1908
+ *
1909
+ * Defaults to the same value as {@link r1}.
1910
+ */
1911
+ r2?: number | undefined;
1912
+ }
1913
+
1914
+ /**
1915
+ * Base interface for all {@link ContentCanvas} child elements that can be filled.
1916
+ */
1917
+ export interface CanvasFilledElement {
1918
+ /**
1919
+ * Background color the element is filled with.
1920
+ *
1921
+ * Supports well-known color names like `blue` or hexadecimal color strings like `#ccffcc`,
1922
+ * as well as a reference to a pattern.
1923
+ *
1924
+ * To fill the element with a gradient, use {@link linearGradient} instead.
1925
+ */
1926
+ color?: string | PatternFill | undefined;
1927
+
1928
+ /**
1929
+ * Opacity of the {@link color} or {@link linearGradient}.
1930
+ * Must be between 0 (fully transparent) and 1 (fully opaque).
1931
+ *
1932
+ * Defaults to `1`.
1933
+ */
1934
+ fillOpacity?: number | undefined;
1935
+
1936
+ /**
1937
+ * Linear horizontal gradient the element is filled with.
1938
+ *
1939
+ * The given stops are distributed equally from left to right.
1940
+ *
1941
+ * Supports well-known color names like `blue` or hexadecimal color strings like `#ccffcc`.
1942
+ *
1943
+ * To fill the element with a solid color, use {@link color} instead.
1944
+ */
1945
+ linearGradient?: string[] | undefined;
1946
+ }
1947
+
1948
+ /**
1949
+ * Base interface for all {@link ContentCanvas} child elements that have a line.
1950
+ */
1951
+ export interface CanvasLineElement {
1952
+ /**
1953
+ * Line width in `pt`.
1954
+ *
1955
+ * Defaults to `1`.
1956
+ */
1957
+ lineWidth?: number | undefined;
1958
+
1959
+ /**
1960
+ * Line color.
1961
+ *
1962
+ * Supports well-known color names like `blue` or hexadecimal color strings like `#ccffcc`.
1963
+ *
1964
+ * Defaults to `black` if the element has no `color` set; defaults to no line otherwise.
1965
+ */
1966
+ lineColor?: string | undefined;
1967
+
1968
+ /**
1969
+ * Opacity of the {@link lineColor}.
1970
+ * Must be between 0 (fully transparent) and 1 (fully opaque).
1971
+ *
1972
+ * Defaults to `1`.
1973
+ */
1974
+ strokeOpacity?: number | undefined;
1975
+
1976
+ /**
1977
+ * Makes the line dashed.
1978
+ *
1979
+ * Defaults to a solid line.
1980
+ */
1981
+ dash?: Dash | undefined;
1982
+
1983
+ /**
1984
+ * Rendering of joints between lines of different angles.
1985
+ *
1986
+ * Defaults to `miter`.
1987
+ */
1988
+ lineJoin?: CanvasLineJoin | undefined;
1989
+ }
1990
+
1991
+ /**
1992
+ * Horizontal image alignment within its container.
1993
+ */
1994
+ export type ImageAlignment = "left" | "right" | "center";
1995
+
1996
+ /**
1997
+ * Vertical image alignment within its container.
1998
+ */
1999
+ export type ImageVerticalAlignment = "top" | "bottom" | "center";
2000
+
2001
+ /**
2002
+ * Container to completely cover with an image, possibly cutting it off horizontally
2003
+ * or vertically.
2004
+ */
2005
+ export interface ImageCover {
2006
+ /**
2007
+ * Container width in `pt`.
2008
+ *
2009
+ * Defaults to the image's (specified or native) width.
2010
+ */
2011
+ width?: number | undefined;
2012
+
2013
+ /**
2014
+ * Container height in `pt`.
2015
+ *
2016
+ * Defaults to the image's (specified or native) width.
2017
+ */
2018
+ height?: number | undefined;
2019
+
2020
+ /**
2021
+ * Horizontal alignment of the image inside the cover container if it is wider.
2022
+ *
2023
+ * Defaults to `center`.
2024
+ */
2025
+ align?: ImageAlignment | undefined;
2026
+
2027
+ /**
2028
+ * Vertical alignment of the image inside the cover container if it is higher.
2029
+ *
2030
+ * Defaults to `center`.
2031
+ */
2032
+ valign?: ImageVerticalAlignment | undefined;
2033
+ }
2034
+
2035
+ /**
2036
+ * Dictionary of reusable style definitions that can be referenced by their key.
2037
+ */
2038
+ export interface StyleDictionary {
2039
+ [name: string]: NamedStyle;
2040
+ }
2041
+
2042
+ /**
2043
+ * Supported PDF versions.
2044
+ */
2045
+ export type PDFVersion = "1.3" | "1.4" | "1.5" | "1.6" | "1.7" | "1.7ext3";
2046
+
2047
+ /**
2048
+ * Supported PDF subsets.
2049
+ */
2050
+ export type PDFSubset =
2051
+ | "PDF/A-1"
2052
+ | "PDF/A-1a"
2053
+ | "PDF/A-1b"
2054
+ | "PDF/A-2"
2055
+ | "PDF/A-2a"
2056
+ | "PDF/A-2b"
2057
+ | "PDF/A-3"
2058
+ | "PDF/A-3a"
2059
+ | "PDF/A-3b"
2060
+ | "PDF/UA";
2061
+
2062
+ /**
2063
+ * Watermark that is rendered on top of each page.
2064
+ */
2065
+ export interface Watermark {
2066
+ /** Text of the watermark. */
2067
+ text: string;
2068
+
2069
+ /**
2070
+ * Opacity of the {@link text}.
2071
+ * Must be between 0 (fully transparent) and 1 (fully opaque).
2072
+ *
2073
+ * Defaults to `0.6`.
2074
+ */
2075
+ opacity?: number | undefined;
2076
+
2077
+ /**
2078
+ * Clock-wise rotation angle of the {@link text}, with `0` being normal text
2079
+ * from left to right, and `90` being vertical text from top to bottom.
2080
+ *
2081
+ * Defaults to an angle from the bottom left to the top right depending on the page size
2082
+ * (~ `305` for A4).
2083
+ */
2084
+ angle?: number | undefined;
2085
+
2086
+ /**
2087
+ * Name of the font.
2088
+ *
2089
+ * Only built-in and globally declared fonts are available, regardless of the fonts
2090
+ * installed on the system.
2091
+ *
2092
+ * Defaults to `Roboto`.
2093
+ */
2094
+ font?: string | undefined;
2095
+
2096
+ /**
2097
+ * Font size in `pt`.
2098
+ *
2099
+ * Defaults to a heuristic depending on the length of {@link text} to cover most of the page.
2100
+ */
2101
+ fontSize?: number | undefined;
2102
+
2103
+ /**
2104
+ * Color of the {@link text}.
2105
+ *
2106
+ * Supports well-known color names like `blue` or hexadecimal color strings like `#ccffcc`.
2107
+ *
2108
+ * Defaults to `black`.
2109
+ */
2110
+ color?: string | undefined;
2111
+
2112
+ /**
2113
+ * Controls whether the {@link text} is bold.
2114
+ *
2115
+ * Defaults to `false`.
2116
+ */
2117
+ bold?: boolean | undefined;
2118
+
2119
+ /**
2120
+ * Controls whether the {@link text} is italic.
2121
+ *
2122
+ * Defaults to `false`.
2123
+ */
2124
+ italics?: boolean | undefined;
2125
+ }
2126
+
2127
+ /**
2128
+ * PDF tiling pattern definition.
2129
+ */
2130
+ export interface Pattern {
2131
+ /** Bounding box that defines the dimensions of the pattern in `pt`. */
2132
+ boundingBox: [number, number, number, number];
2133
+
2134
+ /** Horizontal step size in `pt`. */
2135
+ xStep: number;
2136
+
2137
+ /** Vertical step size in `pt`. */
2138
+ yStep: number;
2139
+
2140
+ /** PDF tiling pattern string. */
2141
+ pattern: string;
2142
+ }
2143
+
2144
+ /**
2145
+ * Definition of an image to be embedded into the document.
2146
+ */
2147
+ export interface ImageDefinition {
2148
+ /**
2149
+ * Image URL.
2150
+ *
2151
+ * Available options:
2152
+ * - Data URLs
2153
+ * - Remote URLs via http:// or https://
2154
+ *
2155
+ * Supported image formats: JPEG, PNG
2156
+ *
2157
+ * SVG images can only be used in the document content using the `svg` property.
2158
+ */
2159
+ url: string;
2160
+
2161
+ /**
2162
+ * HTTP headers to include in the image request, if {@link url} is a remote URL.
2163
+ */
2164
+ headers?: Record<string, string>;
2165
+ }
2166
+
2167
+ /**
2168
+ * Document attachment.
2169
+ */
2170
+ export interface Attachment {
2171
+ /**
2172
+ * Attachment source.
2173
+ *
2174
+ * Available options:
2175
+ * - Data URLs
2176
+ * - Remote URLs via http:// or https://
2177
+ * - File paths (on the server)
2178
+ */
2179
+ src: string;
2180
+
2181
+ /**
2182
+ * File name of the attachment.
2183
+ */
2184
+ name?: string | undefined;
2185
+
2186
+ /**
2187
+ * Description of the attachment.
2188
+ */
2189
+ description?: string | undefined;
2190
+ }
2191
+
2192
+ /**
2193
+ * Complete definition of a PDF document.
2194
+ */
2195
+ export interface TDocumentDefinitions {
2196
+ /**
2197
+ * Main content of the document.
2198
+ *
2199
+ * Rendered inside the configured {@link pageMargins}.
2200
+ */
2201
+ content: Content;
2202
+
2203
+ /**
2204
+ * Content that is rendered behind the document's {@link content}, and repeated for every page.
2205
+ *
2206
+ * Independent of the configured {@link pageMargins}.
2207
+ */
2208
+ background?: DynamicBackground | Content | undefined;
2209
+
2210
+ /**
2211
+ * Controls whether to compress the resulting PDF document.
2212
+ *
2213
+ * Regardless of this value, any image files added to the document are embedded without
2214
+ * recompression. This flag merely applies a lossless compression (similar to ZIP compression)
2215
+ * to the whole finished PDF document.
2216
+ *
2217
+ * To control the size of the resulting PDF file and the quality of its images, optimize your
2218
+ * image files before adding them:
2219
+ * - For line art, try to find an SVG file, which often offers better quality at smaller file sizes.
2220
+ * - Downscale large raster images to the smallest size that still looks good.
2221
+ * - Use the file format (JPEG/PNG) and compression settings that yield the best compromise
2222
+ * between file size and quality.
2223
+ *
2224
+ * Defaults to `true`.
2225
+ */
2226
+ compress?: boolean | undefined;
2227
+
2228
+ /**
2229
+ * Default styles that apply to the complete document.
2230
+ */
2231
+ defaultStyle?: Style | undefined;
2232
+
2233
+ /**
2234
+ * Footer content that is repeated on every page.
2235
+ *
2236
+ * **Note:** If the footer's content exceeds the available space as defined by
2237
+ * {@link pageMargins}, it is not rendered at all.
2238
+ */
2239
+ footer?: DynamicContent | Content | undefined;
2240
+
2241
+ /**
2242
+ * Header content that is repeated on every page.
2243
+ *
2244
+ * **Note:** If the header's content exceeds the available space as defined by
2245
+ * {@link pageMargins}, it is not rendered at all.
2246
+ */
2247
+ header?: DynamicContent | Content | undefined;
2248
+
2249
+ /**
2250
+ * Dictionary of images to be embedded into the document.
2251
+ *
2252
+ * The specified images can be referenced from content elements by their key.
2253
+ *
2254
+ * Available options:
2255
+ * - A data URL
2256
+ * - A remote URL via http:// or https://
2257
+ * - An object including a URL and additional HTTP headers
2258
+ *
2259
+ * Supported image formats: JPEG, PNG
2260
+ *
2261
+ * SVG images can only be used in the document content using the `svg` property.
2262
+ */
2263
+ images?: Record<string, string | ImageDefinition> | undefined;
2264
+
2265
+ /**
2266
+ * Metadata to embed into the document.
2267
+ */
2268
+ info?: TDocumentInformation | undefined;
2269
+
2270
+ /**
2271
+ * Callback to determine where to break pages.
2272
+ * Called repeatedly until no more page breaks are added.
2273
+ *
2274
+ * Not called for nodes that have `pageBreak: 'before'` set.
2275
+ *
2276
+ * @param currentNode - The current content node to check.
2277
+ * @param nodeQueries - container to request additional information about the node.
2278
+ *
2279
+ * @returns whether to insert a page break before the current node.
2280
+ */
2281
+ pageBreakBefore?:
2282
+ | ((currentNode: Node, nodeQueries: NodeQueries) => boolean)
2283
+ | undefined;
2284
+
2285
+ /**
2286
+ * Margins around the {@link content} on each page.
2287
+ *
2288
+ * If a {@link header} or {@link footer} is specified, the page margins must
2289
+ * leave sufficient room for it to be rendered at all.
2290
+ *
2291
+ * Defaults to `40`.
2292
+ */
2293
+ pageMargins?: Margins | undefined;
2294
+
2295
+ /**
2296
+ * Orientation of the document's pages.
2297
+ *
2298
+ * Defaults to `portrait` for standard page sizes; if a custom {@link pageSize} is given,
2299
+ * it defaults to the orientation set through its width and height.
2300
+ */
2301
+ pageOrientation?: PageOrientation | undefined;
2302
+
2303
+ /**
2304
+ * Size of the document's pages.
2305
+ *
2306
+ * Defaults to `A4`.
2307
+ */
2308
+ pageSize?: PageSize | undefined;
2309
+
2310
+ /**
2311
+ * Dictionary for reusable styles to be referenced by their key throughout the document.
2312
+ *
2313
+ * To define styles that should apply by default, use {@link defaultStyle} instead.
2314
+ */
2315
+ styles?: StyleDictionary | undefined;
2316
+
2317
+ /**
2318
+ * Password required to open the document.
2319
+ *
2320
+ * If set, the document is encrypted.
2321
+ * Setting the {@link version} influences the encryption method used.
2322
+ *
2323
+ * An empty string is treated as "no password".
2324
+ */
2325
+ userPassword?: string | undefined;
2326
+
2327
+ /**
2328
+ * Password required to get full access to the document.
2329
+ *
2330
+ * Use in combination with {@link permissions}.
2331
+ *
2332
+ * An empty string is treated as "no password".
2333
+ *
2334
+ * Does not encrypt the document; use {@link userPassword} for that.
2335
+ */
2336
+ ownerPassword?: string | undefined;
2337
+
2338
+ /**
2339
+ * Permissions for accessing or modifying the document in different ways.
2340
+ *
2341
+ * The PDF file cannot enforce these permissions by itself.
2342
+ * It relies on PDF viewer applications to respect them.
2343
+ *
2344
+ * Only relevant if {@link ownerPassword} is set.
2345
+ *
2346
+ * Defaults to `{}` (everything is forbidden)
2347
+ */
2348
+ permissions?: PDFKit.DocumentPermissions | undefined;
2349
+
2350
+ /**
2351
+ * Version of the PDF specification the document is created with.
2352
+ *
2353
+ * Influences the encryption method used in combination with {@link userPassword}.
2354
+ * The PDF content is always created with version 1.3.
2355
+ *
2356
+ * Defaults to `1.3`.
2357
+ */
2358
+ version?: PDFVersion | undefined;
2359
+
2360
+ /**
2361
+ * Subset of the PDF specification the document is created with.
2362
+ */
2363
+ subset?: PDFSubset | undefined;
2364
+
2365
+ /**
2366
+ * Controls whether the document is marked as a tagged PDF.
2367
+ *
2368
+ * Defaults to `false`.
2369
+ */
2370
+ tagged?: boolean | undefined;
2371
+
2372
+ /**
2373
+ * Controls whether the document title should be displayed in the window title of the PDF viewer.
2374
+ *
2375
+ * Defaults to `false`.
2376
+ */
2377
+ displayTitle?: boolean | undefined;
2378
+
2379
+ /**
2380
+ * Watermark that is rendered on top of each page.
2381
+ */
2382
+ watermark?: string | Watermark | undefined;
2383
+
2384
+ /**
2385
+ * Dictionary of reusable pattern definitions that can be referenced by their key.
2386
+ */
2387
+ patterns?: Record<string, Pattern> | undefined;
2388
+
2389
+ /**
2390
+ * Document language as BCP 47 language tag, e.g. `en-US`.
2391
+ */
2392
+ language?: string | undefined;
2393
+
2394
+ /**
2395
+ * Document attachments that can be referenced by their key.
2396
+ *
2397
+ * To embed attachment files, use {@link files} instead.
2398
+ */
2399
+ attachments?: Record<string, Attachment> | undefined;
2400
+
2401
+ /**
2402
+ * Document attachment files to embed into the document, that can be referenced by their key.
2403
+ */
2404
+ files?: Record<string, Attachment> | undefined;
2405
+ }
2406
+
2407
+ /**
2408
+ * Start position of a node in the document.
2409
+ */
2410
+ export interface NodeStartPosition {
2411
+ /** Page number (starting from 1) the node starts on. */
2412
+ pageNumber: number;
2413
+
2414
+ /** Orientation of the page the node starts on. */
2415
+ pageOrientation: PageOrientation;
2416
+
2417
+ /** Height of the page in `pt`, with the vertical page margins subtracted. */
2418
+ pageInnerHeight: number;
2419
+
2420
+ /** Width of the page in `pt`, with the horizontal page margins subtracted. */
2421
+ pageInnerWidth: number;
2422
+
2423
+ /** Horizontal start position from the left edge of the page in `pt`. */
2424
+ left: number;
2425
+
2426
+ /** Vertical start position from the top of the page in `pt`. */
2427
+ top: number;
2428
+
2429
+ /**
2430
+ * Same as {@link top}, but as a relative value between the top and bottom page margin:
2431
+ * 0 corresponds with the top page margin, 1 corresponds with the bottom page margin.
2432
+ */
2433
+ verticalRatio: number;
2434
+
2435
+ /**
2436
+ * Same as {@link left}, but as a relative value between the left and right page margin:
2437
+ * 0 corresponds with the left page margin, 1 corresponds with the right page margin.
2438
+ */
2439
+ horizontalRatio: number;
2440
+ }
2441
+
2442
+ /**
2443
+ * Information about a node that is being rendered.
2444
+ */
2445
+ export interface Node {
2446
+ /** Text content. */
2447
+ text?: Content | undefined;
2448
+
2449
+ /** Unordered list elements. */
2450
+ ul?: UnorderedListElement[] | undefined;
2451
+
2452
+ /** Ordered list elements. */
2453
+ ol?: OrderedListElement[] | undefined;
2454
+
2455
+ /** Table content. */
2456
+ table?: Table | undefined;
2457
+
2458
+ /** Image URL or reference. */
2459
+ image?: string | undefined;
2460
+
2461
+ /** QR code content. */
2462
+ qr?: string | undefined;
2463
+
2464
+ /** Canvas / vector elements. */
2465
+ canvas?: CanvasElement[] | undefined;
2466
+
2467
+ /** SVG image content. */
2468
+ svg?: string | undefined;
2469
+
2470
+ /** Column elements. */
2471
+ columns?: Column[] | undefined;
2472
+
2473
+ /** The node's ID. */
2474
+ id?: string | undefined;
2475
+
2476
+ /** Headline level specified on the node's content element. */
2477
+ headlineLevel?: number | undefined;
2478
+
2479
+ /** Styles or style references applied to the node. */
2480
+ style?: StyleReference | undefined;
2481
+
2482
+ /** The node's specified page break. */
2483
+ pageBreak?: PageBreak | undefined;
2484
+
2485
+ /** Page orientation at the node's start position. */
2486
+ pageOrientation?: PageOrientation | undefined;
2487
+
2488
+ /** Array containing all page numbers (starting from 1) the node spans across. */
2489
+ pageNumbers: number[];
2490
+
2491
+ /** Total number of pages in the document. */
2492
+ pages: number;
2493
+
2494
+ /** Indicates whether the node is a {@link ContentStack}. */
2495
+ stack: boolean;
2496
+
2497
+ /** Start position of the node. */
2498
+ startPosition: NodeStartPosition;
2499
+ }
2500
+
2501
+ /**
2502
+ * Container to request additional information about a {@link Node}.
2503
+ */
2504
+ export interface NodeQueries {
2505
+ /**
2506
+ * Returns the nodes after the current one on the same page.
2507
+ */
2508
+ getFollowingNodesOnPage: () => Node[];
2509
+
2510
+ /**
2511
+ * Returns the nodes on the next page.
2512
+ */
2513
+ getNodesOnNextPage: () => Node[];
2514
+
2515
+ /**
2516
+ * Returns the nodes before the current one on the same page.
2517
+ */
2518
+ getPreviousNodesOnPage: () => Node[];
2519
+ }
2520
+
2521
+ /**
2522
+ * Information about the effective page size.
2523
+ */
2524
+ export interface ContextPageSize {
2525
+ /** Page height in `pt`. */
2526
+ height: number;
2527
+
2528
+ /** Page width in `pt`. */
2529
+ width: number;
2530
+
2531
+ /** Page orientation. */
2532
+ orientation: PageOrientation;
2533
+ }
2534
+
2535
+ export interface BufferOptions {
2536
+ fontLayoutCache?: boolean | undefined;
2537
+ bufferPages?: boolean | undefined;
2538
+ autoPrint?: boolean | undefined;
2539
+ }
2540
+
2541
+ export interface TCreatedPdf {
2542
+ /**
2543
+ * Returns a promise to the streamable PDFKit document.
2544
+ */
2545
+ getStream(): Promise<PDFKit.PDFDocument>;
2546
+
2547
+ /**
2548
+ * Generates the PDF as a binary buffer.
2549
+ */
2550
+ getBuffer(): Promise<Buffer>;
2551
+
2552
+ /**
2553
+ * Generates the PDF as a base64 string.
2554
+ */
2555
+ getBase64(): Promise<string>;
2556
+
2557
+ /**
2558
+ * Generates the PDF as a data URL.
2559
+ */
2560
+ getDataUrl(): Promise<string>;
2561
+
2562
+ /**
2563
+ * Writes the PDF on disk.
2564
+ *
2565
+ * **Note:** Only supported on the server.
2566
+ */
2567
+ write(fileName: string): Promise<void>;
2568
+
2569
+ /**
2570
+ * Generates the PDF as a blob object.
2571
+ *
2572
+ * **Note:** Only supported in the browser.
2573
+ */
2574
+ getBlob(): Promise<Blob>;
2575
+
2576
+ /**
2577
+ * Downloads the generated PDF.
2578
+ *
2579
+ * **Note:** Only supported in the browser.
2580
+ */
2581
+ download(defaultFileName?: string): Promise<void>;
2582
+
2583
+ /**
2584
+ * Opens the generated PDF.
2585
+ *
2586
+ * @param window defaults to opening a new window.
2587
+ *
2588
+ * **Note:** Only supported in the browser.
2589
+ */
2590
+ open(win?: Window | null): Promise<void>;
2591
+
2592
+ /**
2593
+ * Prints the generated PDF.
2594
+ *
2595
+ * @param window defaults to opening a new window.
2596
+ *
2597
+ * **Note:** Only supported in the browser.
2598
+ */
2599
+ print(win?: Window | null): Promise<void>;
2600
+ }
2601
+
2602
+ /**
2603
+ * Callback to track the document generation process.
2604
+ *
2605
+ * @param progress Current progress between 0 and 1.
2606
+ */
2607
+ export type ProgressCallback = (progress: number) => void;
2608
+
2609
+ // disable automatic exporting
2610
+ export {};