-
Notifications
You must be signed in to change notification settings - Fork 1
/
custom_tables.js
41 lines (36 loc) · 999 Bytes
/
custom_tables.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
var fonts = {
Roboto: {
normal: 'fonts/Roboto-Regular.ttf',
bold: 'fonts/Roboto-Medium.ttf',
italics: 'fonts/Roboto-Italic.ttf',
bolditalics: 'fonts/Roboto-MediumItalic.ttf'
}
};
var PdfPrinter = require('pdfmake');
var printer = new PdfPrinter(fonts);
var fs = require('fs');
// Create a document definition
const docDefinition = {
content: [
{ text: 'Adding Images and Tables', fontSize: 16, bold: true },
{ text: 'This is an image:', margin: [0, 10] },
{ image: 'images/image.png', width: 200 },
{ text: 'This is a table:', margin: [0, 10] },
{
table: {
widths: [100, '*', 200],
body: [
['Column 1', 'Column 2', 'Column 3'],
['Row 1', 'Row 1 Data', 'Row 1 Data'],
['Row 2', 'Row 2 Data', 'Row 2 Data'],
],
},
},
],
}
var options = {
// ...
}
var pdfDoc = printer.createPdfKitDocument(docDefinition, options);
pdfDoc.pipe(fs.createWriteStream('myFirstPDF.pdf'));
pdfDoc.end();