-
-
Notifications
You must be signed in to change notification settings - Fork 89
/
example.js
284 lines (267 loc) · 15.9 KB
/
example.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
var pdfMake = require("pdfmake/build/pdfmake");
var pdfFonts = require("pdfmake/build/vfs_fonts");
pdfMake.vfs = pdfFonts.pdfMake.vfs;
var fs = require("fs");
var jsdom = require("jsdom");
var { JSDOM } = jsdom;
var { window } = new JSDOM("");
var htmlToPdfMake = require("./index.js");
//var util = require("util");
var html = htmlToPdfMake(`
Simple text
<div>
<h1>Title Level 1</h1>
<h2 style="color:green;margin-bottom:10px">Title Level 2</h2>
<h3>Title Level 3</h3>
<h4>Title Level 4</h4>
<h5>Title Level 5</h5>
<h6>Title Level 6</h6>
</div>
<p>
This is a sentence with a <strong>bold and purple word</strong>, <em>one in italic</em>, and <u>one with underline</u>. And finally <a href="https://somewhere">a link</a>.
</p>
<span style="color:orange;font-weight:bold;margin:10px 5px">An orange bold span with margins.</span>
<p>
Below is a unordered list:
<ul>
<li>First item</li>
<li>Second item</li>
<li>
With a sub unordered list:
<ul>
<li>Sub First <b>bolded</b> item</li>
<li>Sub Second <u>underlined</u> item</li>
<li>With a sub sub unordered list:
<ul style="background-color:yellow">
<li>Sub Sub First item</li>
<li>Sub Sub Second item</li>
</ul>
</li>
</ul>
</li>
<li>
With a sub order list:
<ol>
<li>Sub Item 1</li>
<li>Sub Item 2</li>
<li>With a sub sub ordered list
<ol>
<li>Sub Sub Item 1</li>
<li>Sub Sub Item 2</li>
</ol>
</ol>
</li>
</ul>
<br>This sentence is surrended by BR<br>
</p>
<p>
A first level ordered list with type "I":
<ol type="I">
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ol>
</p>
<div>
<p class="bold">
Text in bold.
<span class="red">This is a red span</span>
</p>
</div>
<span><HR> with the default style:</span>
<hr>
<span class="pdf-pagebreak-before">Below, another <HR> but with different style: left=120, width=300, color='red', margin=[0,20,0,20], thickness=2</span>
<hr data-pdfmake="{"left":120, "width":300, "color":"red", "margin":[0,20,0,20], "thickness":2}">
<table>
<thead>
<tr>
<th>Region</th>
<th>Result Q1</th>
<th>Result Q2</th>
</tr>
</thead>
<tbody>
<tr>
<th>Americas</th>
<td>+3%</td>
<td>+6%</td>
</tr>
<tr>
<th>Europe</th>
<td>+3.9%</td>
<td>+5%</td>
</tr>
<tr>
<th>Asia</th>
<td>+1.5%</td>
<td>+0.9%</td>
</tr>
</tbody>
</table>
<table>
<tr>
<th>Header Column 1</th>
<th>Header Column 2</th>
</tr>
<tr>
<td>Value Column 1</td>
<td>Value Column 2</td>
</tr>
</table>
<table>
<tr>
<th>Col A</th>
<th>Col B</th>
<th>Col C</th>
<th>Col D</th>
</tr>
<tr>
<td>Cell A1</td>
<td rowspan="2">
Cell B1 & B2
</td>
<td>Cell C1</td>
<td rowspan="2">
Cell D1 & D2
</td>
</tr>
<tr>
<td>Cell A2</td>
<td>Cell C2</td>
</tr>
<tr>
<td>Cell A3</td>
<td colspan="2">Cell B3 & C3</td>
<td>Cell D3</td>
</tr>
<tr>
<td rowspan="2" colspan="3">
Cell A4 & A5 & B4 & B5 & C4 & C5
</td>
<td>Cell D4</td>
</tr>
<tr>
<td>Cell D5</td>
</tr>
</table>
<table data-pdfmake="{"widths":[100,"*","auto"],"heights":40}">
<tr>
<td colspan="3">Table with <b>widths=[100,"*","auto"]</b> and <b>heights=40</b> using "data-pdfmake" attribute</th>
</tr>
<tr>
<td>Cell1</td>
<td style="text-align:center">Cell2</td>
<td style="text-align:right">Cell3</td>
</tr>
</table>
<table>
<tr>
<td style="background-color:red">Cell with red background</td>
<td>Cell</td>
<td style="border:1px solid red">Cell with red borders</td>
</tr>
</table>
<p>Table autosized based on style "height" and "width" using "tableAutoSize:true" option:</p>
<table>
<tr style="height:100px">
<td style="width:250px">height:100px / width:250px</td>
<td>height:100px / width:'auto'</td>
</tr>
<tr>
<td style="width:100px">Here "<td width="100">" will use 250px for the width because we have to use the largest col's width</td>
<td style="height:200px">height:200px / width:'auto'</td>
</tr>
</table>
<p>Change the table's layout (header with red border, body with blue border):</p>
<table data-pdfmake="{"layout":"exampleLayout"}">
<tr>
<th>Header A</th>
<th>Header B</td>
</tr>
<tr>
<td>A1</td>
<td>B1</td>
</tr>
<tr>
<td>A2</td>
<td>B2</td>
</tr>
<tr>
<td>A3</td>
<td>B3</td>
</tr>
</table>
<div style="display:none">display:none</div>
<svg version="1.1" baseProfile="full" width="300" height="200" xmlns="http://www.w3.org/2000/svg">
<rect width="100%" height="100%" fill="red" />
<circle cx="150" cy="100" r="80" fill="green" />
</svg>
<div style="margin-top:20px">
An image: <img width="54" style="height:70px" src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEBLAEsAAD/7QPQUGhvdG9zaG9wIDMuMAA4QklNA+kKUHJpbnQgSW5mbwAAAAB4AAMAAABIAEgAAAAAAtgCKP/h/+IC+QJGA0cFKAP8AAIAAABIAEgAAAAAAtgCKAABAAAAZAAAAAEAAwMDAAAAAScPAAEAAQAAAAAAAAAAAAAAAGAIABkBkAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOEJJTQPtClJlc29sdXRpb24AAAAAEAEsAAAAAQABASwAAAABAAE4QklNBA0YRlggR2xvYmFsIExpZ2h0aW5nIEFuZ2xlAAAAAAQAAAAeOEJJTQQZEkZYIEdsb2JhbCBBbHRpdHVkZQAAAAAEAAAAHjhCSU0D8wtQcmludCBGbGFncwAAAAkAAAAAAAAAAAEAOEJJTQQKDkNvcHlyaWdodCBGbGFnAAAAAAEAADhCSU0nEBRKYXBhbmVzZSBQcmludCBGbGFncwAAAAAKAAEAAAAAAAAAAjhCSU0D9RdDb2xvciBIYWxmdG9uZSBTZXR0aW5ncwAAAEgAL2ZmAAEAbGZmAAYAAAAAAAEAL2ZmAAEAoZmaAAYAAAAAAAEAMgAAAAEAWgAAAAYAAAAAAAEANQAAAAEALQAAAAYAAAAAAAE4QklNA/gXQ29sb3IgVHJhbnNmZXIgU2V0dGluZ3MAAABwAAD/////////////////////////////A+gAAAAA/////////////////////////////wPoAAAAAP////////////////////////////8D6AAAAAD/////////////////////////////A+gAADhCSU0ECAZHdWlkZXMAAAAAEAAAAAEAAAJAAAACQAAAAAA4QklNBB4NVVJMIG92ZXJyaWRlcwAAAAQAAAAAOEJJTQQaBlNsaWNlcwAAAABtAAAABgAAAAAAAAAAAAALiAAACMMAAAAGADYAMgAuADYAOAA0AAAAAQAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAjDAAALiAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA4QklNBBQXTGF5ZXIgSUQgR2VuZXJhdG9yIEJhc2UAAAAEAAAAAThCSU0EIRpWZXJzaW9uIGNvbXBhdGliaWxpdHkgaW5mbwAAAABVAAAAAQEAAAAPAEEAZABvAGIAZQAgAFAAaABvAHQAbwBzAGgAbwBwAAAAEwBBAGQAbwBiAGUAIABQAGgAbw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text-align: center;"> <span style="font-size: 14px;"><em><strong>Bold italic centered text</strong></em></span> </p>
<span class="a">text "bold" <span class="b">text "bold & italic" <span class="c">text "bold & italic & red"</span> text "bold & italic"</span> text "bold"</span>
<div style="margin-top:20px">
Below we preserve the spaces:
<p class="with-spaces"> this is just an example.</p>
</div>
<div>And support for <font color="blue" size="3">FONT</font> tag.</div>
`, {window:window, tableAutoSize:true});
/*var html = htmlToPdfMake(``, {window:window});
console.log(JSON.stringify(html))*/
var docDefinition = {
content: [
html
],
pageBreakBefore: function(currentNode) {
// we add a page break before elements with the classname "pdf-pagebreak-before"
return currentNode.style && currentNode.style.indexOf('pdf-pagebreak-before') > -1;
},
styles:{
red:{
color:'red'
},
blue:{
color:'blue'
},
bold:{
bold:true
},
'html-h6':{
color:'purple'
},
'html-strong':{
color:'purple'
},
'a':{
bold:true
},
'b':{
italics: true
},
'c':{
color:'red',
italics: false
},
'with-spaces':{
preserveLeadingSpaces: true
}
}
};
var pdfDocGenerator = pdfMake.createPdf(docDefinition, {
// see https://pdfmake.github.io/docs/0.1/document-definition-object/tables/
exampleLayout: {
hLineColor: function (rowIndex, node, colIndex) {
if (rowIndex === node.table.body.length) return 'blue';
return rowIndex <= 1 ? 'red' : '#dddddd';
},
vLineColor: function (colIndex, node, rowIndex) {
if (rowIndex === 0) return 'red';
return rowIndex > 0 && (colIndex === 0 || colIndex === node.table.body[0].length) ? 'blue' : 'black';
}
}
});
pdfDocGenerator.getBuffer(function(buffer) {
fs.writeFileSync('example.pdf', buffer);
console.log('--> example.pdf')
});