|
1 | 1 | import PDFDocument = require("pdfkit"); |
2 | 2 |
|
| 3 | +/** |
| 4 | + * Insert SVG into a PDF document created with PDFKit. |
| 5 | + * |
| 6 | + * @param doc the PDF document created with PDFKit |
| 7 | + * @param svg the SVG object or XML code |
| 8 | + * @param x the x position where the SVG will be added |
| 9 | + * @param y the y position where the SVG will be added |
| 10 | + * @param options See {@link SVGtoPDF.Options} |
| 11 | + */ |
3 | 12 | declare function SVGtoPDF( |
4 | 13 | doc: typeof PDFDocument, |
5 | 14 | svg: SVGElement | string, |
6 | 15 | x?: number, |
7 | 16 | y?: number, |
8 | | - options?: SVGtoPDF.SVGtoPDFOptions, |
| 17 | + options?: SVGtoPDF.Options, |
9 | 18 | ): void; |
10 | 19 |
|
11 | 20 | declare namespace SVGtoPDF { |
12 | | - interface SVGtoPDFOptions { |
| 21 | + type Color = [[number, number, number], number]; |
| 22 | + interface Options { |
| 23 | + /** initial viewport width, by default it's the page width */ |
13 | 24 | width?: number; |
| 25 | + |
| 26 | + /** initial viewport width, by default it's the page height */ |
14 | 27 | height?: number; |
| 28 | + |
| 29 | + /** override alignment of the SVG content inside its viewport */ |
15 | 30 | preserveAspectRatio?: string; |
| 31 | + |
| 32 | + /** use the CSS styles computed by the browser (for SVGElement only) */ |
16 | 33 | useCSS?: boolean; |
| 34 | + |
| 35 | + /** function called to get the fonts, see source code */ |
17 | 36 | fontCallback?: ( |
18 | 37 | family: string, |
19 | 38 | bold: boolean, |
20 | 39 | italic: boolean, |
21 | 40 | fontOptions: { fauxItalic: boolean; fauxBold: boolean }, |
22 | 41 | ) => string; |
| 42 | + |
| 43 | + /** same as above for the images (for Node.js) */ |
23 | 44 | imageCallback?: (link: string) => string; |
24 | | - documentCallback?: (file: string) => string; |
25 | | - colorCallback?: (result: string, raw: string) => [[number, number, number], number]; |
26 | | - warningCallback?: (str: string) => void; |
| 45 | + |
| 46 | + /** same as above for the external SVG documents */ |
| 47 | + documentCallback?: ( |
| 48 | + file: string, |
| 49 | + ) => SVGElement | string | (SVGElement | string)[]; |
| 50 | + |
| 51 | + /** function called to get color, making mapping to CMYK possible */ |
| 52 | + colorCallback?: (color: Color) => Color; |
| 53 | + |
| 54 | + /** function called when there is a warning */ |
| 55 | + warningCallback?: (warning: string) => void; |
| 56 | + |
| 57 | + /** assume that units are PDF points instead of SVG pixels */ |
27 | 58 | assumePt?: boolean; |
| 59 | + |
| 60 | + /** precision factor for approximate calculations (default = 3) */ |
28 | 61 | precision?: number; |
29 | 62 | } |
30 | 63 | } |
|
0 commit comments