forked from bpampuch/pdfmake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstyling_properties.js
81 lines (76 loc) · 2.26 KB
/
styling_properties.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
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: 'Paragraphs can also by styled without using named-styles (this one sets fontSize to 25)',
fontSize: 25
},
'Another paragraph, using default style, this time a little bit longer to make sure, this line will be divided into at least two lines\n\n',
{
text: 'This paragraph does not use a named-style and sets fontSize to 8 and italics to true',
fontSize: 8,
italics: true
},
'\n\nFor preserving leading spaces use preserveLeadingSpaces property:',
{ text: ' This is a paragraph with preserved leading spaces.', preserveLeadingSpaces: true },
{ text: '{', preserveLeadingSpaces: true },
{ text: ' "sample": {', preserveLeadingSpaces: true },
{ text: ' "json": "nested"', preserveLeadingSpaces: true },
{ text: ' }', preserveLeadingSpaces: true },
{ text: '}', preserveLeadingSpaces: true },
'\n\nfontFeatures property:',
{ text: 'Hello World 1234567890', fontFeatures: ['smcp'] },
{ text: 'Hello World 1234567890', fontFeatures: ['c2sc'] },
{ text: 'Hello World 1234567890', fontFeatures: ['onum'] },
{ text: 'Hello World 1234567890', fontFeatures: ['onum', 'c2sc'] },
'\n\nText opacity:',
{ text: 'Hello World', opacity: 0.8 },
{ text: 'Hello World', opacity: 0.6 },
{ text: 'Hello World', opacity: 0.4 },
{ text: 'Hello World', opacity: 0.2 },
{ text: 'Hello World', opacity: 0.1 },
'\n\n Subscript, superscript:',
{
text: [
'Hello World.',
{
text: '1, 2',
sup: true,
},
' Let\'s continue our sentence. Notice the leading space.'
]
},
{
text: [
'Hello',
{
text: '1, 2',
sub: true,
},
' World'
]
},
'\n\n',
{
text: 'Text background pattern', background: ['stripe45d', 'gray']
}
],
patterns: {
stripe45d: {
boundingBox: [1, 1, 4, 4],
xStep: 3,
yStep: 3,
pattern: '1 w 0 1 m 4 5 l s 2 0 m 5 3 l s'
}
}
};
var now = new Date();
var pdf = pdfmake.createPdf(docDefinition);
pdf.write('pdfs/styling_properties.pdf').then(() => {
console.log(new Date() - now);
}, err => {
console.error(err);
});