-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
Copy pathstyling_inlines.js
63 lines (59 loc) · 1.97 KB
/
styling_inlines.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
var pdfmake = require('../js/index'); // only during development, otherwise use the following line
//var pdfmake = require('pdfmake');
var Roboto = require('../fonts/Roboto');
pdfmake.addFonts(Roboto);
var docDefinition = {
content: [
{
text: 'This is a header (whole paragraph uses the same header style)\n\n',
style: 'header'
},
{
text: [
'It is however possible to provide an array of texts ',
'to the paragraph (instead of a single string) and have ',
{ text: 'a better ', fontSize: 15, bold: true },
'control over it. \nEach inline can be ',
{ text: 'styled ', fontSize: 20 },
{ text: 'independently ', italics: true, fontSize: 40 },
'then.\n\n'
]
},
{ text: 'Mixing named styles and style-overrides', style: 'header' },
{
style: 'bigger',
italics: false,
text: [
'We can also mix named-styles and style-overrides at both paragraph and inline level. ',
'For example, this paragraph uses the "bigger" style, which changes fontSize to 15 and sets italics to true. ',
'Texts are not italics though. It\'s because we\'ve overriden italics back to false at ',
'the paragraph level. \n\n',
'We can also change the style of a single inline. Let\'s use a named style called header: ',
{ text: 'like here.\n', style: 'header' },
'It got bigger and bold.\n\n',
'OK, now we\'re going to mix named styles and style-overrides at the inline level. ',
'We\'ll use header style (it makes texts bigger and bold), but we\'ll override ',
'bold back to false: ',
{ text: 'wow! it works!', style: 'header', bold: false },
'\n\nMake sure to take a look into the sources to understand what\'s going on here.'
]
}
],
styles: {
header: {
fontSize: 18,
bold: true
},
bigger: {
fontSize: 15,
italics: true
}
}
};
var now = new Date();
var pdf = pdfmake.createPdf(docDefinition);
pdf.write('pdfs/styling_inlines.pdf').then(() => {
console.log(new Date() - now);
}, err => {
console.error(err);
});