forked from bpampuch/pdfmake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vectors.js
114 lines (109 loc) · 2.02 KB
/
vectors.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
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('../src/printer');
var printer = new PdfPrinter(fonts);
var fs = require('fs');
var docDefinition = {
content: [
{
text: [
'This ',
{text: 'is', color: 'green'},
' the first ',
{text: 'paragraph', color: 'red'}
]
},
{
canvas: [
{
type: 'rect',
x: 0,
y: 0,
w: 310,
h: 260,
r: 5,
dash: {length: 5},
// lineWidth: 10,
lineColor: 'blue',
},
{
type: 'rect',
x: 1,
y: 1,
w: 308,
h: 258,
r: 4,
lineColor: 'red',
color: '#ffffe0',
},
{
type: 'polyline',
lineWidth: 3,
closePath: true,
points: [{x: 10, y: 10}, {x: 35, y: 40}, {x: 100, y: 40}, {x: 125, y: 10}]
},
{
type: 'polyline',
lineWidth: 2,
color: 'blue',
lineColor: 'red',
points: [{x: 10, y: 110}, {x: 35, y: 140}, {x: 100, y: 140}, {x: 125, y: 110}, {x: 10, y: 110}]
},
{
type: 'line',
x1: 40, y1: 60,
x2: 260, y2: 60,
lineWidth: 3
},
{
type: 'ellipse',
x: 150, y: 140,
color: 'red',
fillOpacity: 0.5,
r1: 80, r2: 60
},
{
type: 'rect',
x: 150,
y: 200,
w: 150,
h: 50,
},
{
type: 'rect',
x: 10, y: 200, w: 100, h: 10,
linearGradient: ['red', 'blue']
},
{
type: 'rect',
x: 10, y: 215, w: 100, h: 10,
linearGradient: ['red', 'green', 'blue']
},
{
type: 'rect',
x: 10, y: 230, w: 100, h: 10,
linearGradient: ['red', 'yellow', 'green', 'blue']
}
]
},
'This text should be rendered under canvas',
{
color: 'black',
text: [
'This should be black ',
]
}
],
defaultStyle: {
color: 'gray',
}
};
var pdfDoc = printer.createPdfKitDocument(docDefinition);
pdfDoc.pipe(fs.createWriteStream('pdfs/vectors.pdf'));
pdfDoc.end();