forked from bpampuch/pdfmake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtables.js
799 lines (792 loc) · 25.8 KB
/
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
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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
/*eslint no-unused-vars: ["error", {"args": "none"}]*/
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: 'Tables', style: 'header' },
'Official documentation is in progress, this document is just a glimpse of what is possible with pdfmake and its layout engine.',
{ text: 'A simple table (no headers, no width specified, no spans, no styling)', style: 'subheader' },
'The following table has nothing more than a body array',
{
style: 'tableExample',
table: {
body: [
['Column 1', 'Column 2', 'Column 3'],
['One value goes here', 'Another one here', 'OK?']
]
}
},
{ text: 'A simple table with nested elements', style: 'subheader' },
'It is of course possible to nest any other type of nodes available in pdfmake inside table cells',
{
style: 'tableExample',
table: {
body: [
['Column 1', 'Column 2', 'Column 3'],
[
{
stack: [
'Let\'s try an unordered list',
{
ul: [
'item 1',
'item 2'
]
}
]
},
[
'or a nested table',
{
table: {
body: [
['Col1', 'Col2', 'Col3'],
['1', '2', '3'],
['1', '2', '3']
]
},
}
],
{
text: [
'Inlines can be ',
{ text: 'styled\n', italics: true },
{ text: 'easily as everywhere else', fontSize: 10 }]
}
]
]
}
},
{ text: 'Defining column widths', style: 'subheader' },
'Tables support the same width definitions as standard columns:',
{
bold: true,
ul: [
'auto',
'star',
'fixed value'
]
},
{
style: 'tableExample',
table: {
widths: [100, '*', 200, '*'],
body: [
['width=100', 'star-sized', 'width=200', 'star-sized'],
['fixed-width cells have exactly the specified width', { text: 'nothing interesting here', italics: true, color: 'gray' }, { text: 'nothing interesting here', italics: true, color: 'gray' }, { text: 'nothing interesting here', italics: true, color: 'gray' }]
]
}
},
{
style: 'tableExample',
table: {
widths: ['*', 'auto'],
body: [
['This is a star-sized column. The next column over, an auto-sized column, will wrap to accomodate all the text in this cell.', 'I am auto sized.'],
]
}
},
{
style: 'tableExample',
table: {
widths: ['*', 'auto'],
body: [
['This is a star-sized column. The next column over, an auto-sized column, will not wrap to accomodate all the text in this cell, because it has been given the noWrap style.', { text: 'I am auto sized.', noWrap: true }],
]
}
},
{ text: 'Defining row heights', style: 'subheader' },
{
style: 'tableExample',
table: {
heights: [20, 50, 70],
body: [
['row 1 with height 20', 'column B'],
['row 2 with height 50', 'column B'],
['row 3 with height 70', 'column B']
]
}
},
'With same height:',
{
style: 'tableExample',
table: {
heights: 40,
body: [
['row 1', 'column B'],
['row 2', 'column B'],
['row 3', 'column B']
]
}
},
'With height from function:',
{
style: 'tableExample',
table: {
heights: function (row) {
return (row + 1) * 25;
},
body: [
['row 1', 'column B'],
['row 2', 'column B'],
['row 3', 'column B']
]
}
},
{ text: 'Column/row spans', pageBreak: 'before', style: 'subheader' },
'Each cell-element can set a rowSpan or colSpan',
{
style: 'tableExample',
color: '#444',
table: {
widths: [200, 'auto', 'auto'],
headerRows: 2,
// keepWithHeaderRows: 1,
body: [
[{ text: 'Header with Colspan = 2', style: 'tableHeader', colSpan: 2, alignment: 'center' }, {}, { text: 'Header 3', style: 'tableHeader', alignment: 'center' }],
[{ text: 'Header 1', style: 'tableHeader', alignment: 'center' }, { text: 'Header 2', style: 'tableHeader', alignment: 'center' }, { text: 'Header 3', style: 'tableHeader', alignment: 'center' }],
['Sample value 1', 'Sample value 2', 'Sample value 3'],
[{ rowSpan: 3, text: 'rowSpan set to 3\nLorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor' }, 'Sample value 2', 'Sample value 3'],
['', 'Sample value 2', 'Sample value 3'],
['Sample value 1', 'Sample value 2', 'Sample value 3'],
['Sample value 1', { colSpan: 2, rowSpan: 2, text: 'Both:\nrowSpan and colSpan\ncan be defined at the same time' }, ''],
['Sample value 1', '', ''],
]
}
},
{ text: 'Headers', pageBreak: 'before', style: 'subheader' },
'You can declare how many rows should be treated as a header. Headers are automatically repeated on the following pages',
{ text: ['It is also possible to set keepWithHeaderRows to make sure there will be no page-break between the header and these rows. Take a look at the document-definition and play with it. If you set it to one, the following table will automatically start on the next page, since there\'s not enough space for the first row to be rendered here'], color: 'gray', italics: true },
{
style: 'tableExample',
table: {
headerRows: 1,
// dontBreakRows: true,
// keepWithHeaderRows: 1,
body: [
[{ text: 'Header 1', style: 'tableHeader' }, { text: 'Header 2', style: 'tableHeader' }, { text: 'Header 3', style: 'tableHeader' }],
[
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.',
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.',
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.',
]
]
}
},
{ text: 'Styling tables', style: 'subheader' },
'You can provide a custom styler for the table. Currently it supports:',
{
ul: [
'line widths',
'line colors',
'cell paddings',
]
},
'with more options coming soon...\n\npdfmake currently has a few predefined styles (see them on the next page)',
{ text: 'noBorders:', fontSize: 14, bold: true, pageBreak: 'before', margin: [0, 0, 0, 8] },
{
style: 'tableExample',
table: {
headerRows: 1,
body: [
[{ text: 'Header 1', style: 'tableHeader' }, { text: 'Header 2', style: 'tableHeader' }, { text: 'Header 3', style: 'tableHeader' }],
['Sample value 1', 'Sample value 2', 'Sample value 3'],
['Sample value 1', 'Sample value 2', 'Sample value 3'],
['Sample value 1', 'Sample value 2', 'Sample value 3'],
['Sample value 1', 'Sample value 2', 'Sample value 3'],
['Sample value 1', 'Sample value 2', 'Sample value 3'],
]
},
layout: 'noBorders'
},
{ text: 'headerLineOnly:', fontSize: 14, bold: true, margin: [0, 20, 0, 8] },
{
style: 'tableExample',
table: {
headerRows: 1,
body: [
[{ text: 'Header 1', style: 'tableHeader' }, { text: 'Header 2', style: 'tableHeader' }, { text: 'Header 3', style: 'tableHeader' }],
['Sample value 1', 'Sample value 2', 'Sample value 3'],
['Sample value 1', 'Sample value 2', 'Sample value 3'],
['Sample value 1', 'Sample value 2', 'Sample value 3'],
['Sample value 1', 'Sample value 2', 'Sample value 3'],
['Sample value 1', 'Sample value 2', 'Sample value 3'],
]
},
layout: 'headerLineOnly'
},
{ text: 'lightHorizontalLines:', fontSize: 14, bold: true, margin: [0, 20, 0, 8] },
{
style: 'tableExample',
table: {
headerRows: 1,
body: [
[{ text: 'Header 1', style: 'tableHeader' }, { text: 'Header 2', style: 'tableHeader' }, { text: 'Header 3', style: 'tableHeader' }],
['Sample value 1', 'Sample value 2', 'Sample value 3'],
['Sample value 1', 'Sample value 2', 'Sample value 3'],
['Sample value 1', 'Sample value 2', 'Sample value 3'],
['Sample value 1', 'Sample value 2', 'Sample value 3'],
['Sample value 1', 'Sample value 2', 'Sample value 3'],
]
},
layout: 'lightHorizontalLines'
},
{ text: 'but you can provide a custom styler as well', margin: [0, 20, 0, 8] },
{
style: 'tableExample',
table: {
headerRows: 1,
body: [
[{ text: 'Header 1', style: 'tableHeader' }, { text: 'Header 2', style: 'tableHeader' }, { text: 'Header 3', style: 'tableHeader' }],
['Sample value 1', 'Sample value 2', 'Sample value 3'],
['Sample value 1', 'Sample value 2', 'Sample value 3'],
['Sample value 1', 'Sample value 2', 'Sample value 3'],
['Sample value 1', 'Sample value 2', 'Sample value 3'],
['Sample value 1', 'Sample value 2', 'Sample value 3'],
]
},
layout: {
hLineWidth: function (i, node) {
return (i === 0 || i === node.table.body.length) ? 2 : 1;
},
vLineWidth: function (i, node) {
return (i === 0 || i === node.table.widths.length) ? 2 : 1;
},
hLineColor: function (i, node) {
return (i === 0 || i === node.table.body.length) ? 'black' : 'gray';
},
vLineColor: function (i, node) {
return (i === 0 || i === node.table.widths.length) ? 'black' : 'gray';
},
// hLineStyle: function (i, node) { return {dash: { length: 10, space: 4 }}; },
// vLineStyle: function (i, node) { return {dash: { length: 10, space: 4 }}; },
// paddingLeft: function(i, node) { return 4; },
// paddingRight: function(i, node) { return 4; },
// paddingTop: function(i, node) { return 2; },
// paddingBottom: function(i, node) { return 2; },
// fillColor: function (rowIndex, node, columnIndex) { return null; }
}
},
{ text: 'zebra style', margin: [0, 20, 0, 8] },
{
style: 'tableExample',
table: {
body: [
['Sample value 1', 'Sample value 2', 'Sample value 3'],
['Sample value 1', 'Sample value 2', 'Sample value 3'],
['Sample value 1', 'Sample value 2', 'Sample value 3'],
['Sample value 1', 'Sample value 2', 'Sample value 3'],
['Sample value 1', 'Sample value 2', 'Sample value 3'],
]
},
layout: {
fillColor: function (rowIndex, node, columnIndex) {
return (rowIndex % 2 === 0) ? '#CCCCCC' : null;
}
}
},
{ text: 'handling fill color opacity...', margin: [0, 20, 0, 8] },
{ text: '... just hardcoding values in the second, third and fourth row', margin: [0, 20, 0, 8] },
{
style: 'tableExample',
table: {
body: [
['Sample value 1', 'Sample value 2', 'Sample value 3'],
[
{text: 'Sample value 1',fillOpacity:0.15,fillColor:'blue'},
{text: 'Sample value 2',fillOpacity:0.60,fillColor:'blue'},
{text: 'Sample value 3',fillOpacity:0.85,fillColor:'blue'},
],
[
{text: 'Sample value 1', fillOpacity: 0.15, fillColor: ['stripe45d', 'blue']},
{text: 'Sample value 2', fillOpacity: 0.60, fillColor: ['stripe45d', 'blue']},
{text: 'Sample value 3', fillOpacity: 0.85, fillColor: ['stripe45d', 'blue']},
],
[
{text: 'Sample value 1', fillOpacity: 0.15, fillColor: 'blue', overlayPattern: ['stripe45d', 'gray'], overlayOpacity: 0.15},
{text: 'Sample value 2', fillOpacity: 0.60, fillColor: 'blue', overlayPattern: ['stripe45d', 'gray'], overlayOpacity: 0.5},
{text: 'Sample value 3', fillOpacity: 0.85, fillColor: 'blue', overlayPattern: ['stripe45d', 'gray'], overlayOpacity: 0.9},
],
['Sample value 1', 'Sample value 2', 'Sample value 3']
]
},
},
{ text: '... using a custom styler and overriding it in the second row', margin: [0, 20, 0, 8] },
{
style: 'tableOpacityExample',
table: {
body: [
['Sample value 1', 'Sample value 2', 'Sample value 3'],
[
{text: 'Sample value 1',fillOpacity:0.15},
{text: 'Sample value 2',fillOpacity:0.60},
{text: 'Sample value 3',fillOpacity:0.85},
],
['Sample value 1', 'Sample value 2', 'Sample value 3']
]
},
},
{ text: '... with a function (opacity at 0 means fully transparent, i.e no color)', margin: [0, 20, 0, 8] },
{
style: 'tableExample',
table: {
body: [
['Sample value 1', 'Sample value 2', 'Sample value 3'],
['Sample value 1', 'Sample value 2', 'Sample value 3'],
['Sample value 1', 'Sample value 2', 'Sample value 3'],
['Sample value 1', 'Sample value 2', 'Sample value 3'],
['Sample value 1', 'Sample value 2', 'Sample value 3'],
['Sample value 1', 'Sample value 2', 'Sample value 3'],
['Sample value 1', 'Sample value 2', 'Sample value 3'],
['Sample value 1', 'Sample value 2', 'Sample value 3'],
]
},
layout: {
fillColor: 'blue',
fillOpacity: function (rowIndex, node, columnIndex) {
return (rowIndex/8+columnIndex/3);
}
}
},
{ text: 'and can be used dash border', margin: [0, 20, 0, 8] },
{
style: 'tableExample',
table: {
headerRows: 1,
body: [
[{ text: 'Header 1', style: 'tableHeader' }, { text: 'Header 2', style: 'tableHeader' }, { text: 'Header 3', style: 'tableHeader' }],
['Sample value 1', 'Sample value 2', 'Sample value 3'],
['Sample value 1', 'Sample value 2', 'Sample value 3'],
['Sample value 1', 'Sample value 2', 'Sample value 3'],
['Sample value 1', 'Sample value 2', 'Sample value 3'],
['Sample value 1', 'Sample value 2', 'Sample value 3'],
]
},
layout: {
hLineWidth: function (i, node) {
return (i === 0 || i === node.table.body.length) ? 2 : 1;
},
vLineWidth: function (i, node) {
return (i === 0 || i === node.table.widths.length) ? 2 : 1;
},
hLineColor: function (i, node) {
return 'black';
},
vLineColor: function (i, node) {
return 'black';
},
hLineStyle: function (i, node) {
if (i === 0 || i === node.table.body.length) {
return null;
}
return { dash: { length: 10, space: 4 } };
},
vLineStyle: function (i, node) {
if (i === 0 || i === node.table.widths.length) {
return null;
}
return { dash: { length: 4 } };
},
// paddingLeft: function(i, node) { return 4; },
// paddingRight: function(i, node) { return 4; },
// paddingTop: function(i, node) { return 2; },
// paddingBottom: function(i, node) { return 2; },
// fillColor: function (i, node) { return null; }
}
},
{ text: 'Optional border', fontSize: 14, bold: true, pageBreak: 'before', margin: [0, 0, 0, 8] },
'Each cell contains an optional border property: an array of 4 booleans for left border, top border, right border, bottom border.',
{
style: 'tableExample',
table: {
body: [
[
{
border: [false, true, false, false],
fillColor: '#eeeeee',
text: 'border:\n[false, true, false, false]'
},
{
border: [false, false, false, false],
fillColor: '#dddddd',
text: 'border:\n[false, false, false, false]'
},
{
border: [true, true, true, true],
fillColor: '#eeeeee',
text: 'border:\n[true, true, true, true]'
}
],
[
{
rowSpan: 3,
border: [true, true, true, true],
fillColor: '#eeeeff',
text: 'rowSpan: 3\n\nborder:\n[true, true, true, true]'
},
{
border: undefined,
fillColor: '#eeeeee',
text: 'border:\nundefined'
},
{
border: [true, false, false, false],
fillColor: '#dddddd',
text: 'border:\n[true, false, false, false]'
}
],
[
'',
{
colSpan: 2,
border: [true, true, true, true],
fillColor: '#eeffee',
text: 'colSpan: 2\n\nborder:\n[true, true, true, true]'
},
''
],
[
'',
{
border: undefined,
fillColor: '#eeeeee',
text: 'border:\nundefined'
},
{
border: [false, false, true, true],
fillColor: '#dddddd',
text: 'border:\n[false, false, true, true]'
}
]
]
},
layout: {
defaultBorder: false,
}
},
'For every cell without a border property, whether it has all borders or not is determined by layout.defaultBorder, which is false in the table above and true (by default) in the table below.',
{
style: 'tableExample',
table: {
body: [
[
{
border: [false, false, false, false],
fillColor: '#eeeeee',
text: 'border:\n[false, false, false, false]'
},
{
fillColor: '#dddddd',
text: 'border:\nundefined'
},
{
fillColor: '#eeeeee',
text: 'border:\nundefined'
},
],
[
{
fillColor: '#dddddd',
text: 'border:\nundefined'
},
{
fillColor: '#eeeeee',
text: 'border:\nundefined'
},
{
border: [true, true, false, false],
fillColor: '#dddddd',
text: 'border:\n[true, true, false, false]'
},
]
]
}
},
'And some other examples with rowSpan/colSpan...',
{
style: 'tableExample',
table: {
body: [
[
'',
'column 1',
'column 2',
'column 3'
],
[
'row 1',
{
rowSpan: 3,
colSpan: 3,
border: [true, true, true, true],
fillColor: '#cccccc',
text: 'rowSpan: 3\ncolSpan: 3\n\nborder:\n[true, true, true, true]'
},
'',
''
],
[
'row 2',
'',
'',
''
],
[
'row 3',
'',
'',
''
]
]
},
layout: {
defaultBorder: false,
}
},
{
style: 'tableExample',
table: {
body: [
[
{
colSpan: 3,
text: 'colSpan: 3\n\nborder:\n[false, false, false, false]',
fillColor: '#eeeeee',
border: [false, false, false, false]
},
'',
''
],
[
'border:\nundefined',
'border:\nundefined',
'border:\nundefined'
]
]
}
},
{
style: 'tableExample',
table: {
body: [
[
{ rowSpan: 3, text: 'rowSpan: 3\n\nborder:\n[false, false, false, false]', fillColor: '#eeeeee', border: [false, false, false, false] },
'border:\nundefined',
'border:\nundefined'
],
[
'',
'border:\nundefined',
'border:\nundefined'
],
[
'',
'border:\nundefined',
'border:\nundefined'
]
]
}
},
{ text: 'BorderColor per Cell with Column/row spans', pageBreak: 'before', style: 'subheader' },
'Each cell-element can set the borderColor (the cell above or left of the current cell has priority',
{
style: 'tableExample',
color: '#444',
table: {
widths: [200, 'auto', 'auto'],
headerRows: 2,
// keepWithHeaderRows: 1,
body: [
[
{
text: 'Header with Colspan = 3',
style: 'tableHeader',
colSpan: 3,
borderColor: ['#ff00ff', '#00ffff', '#ff00ff', '#00ffff'],
alignment: 'center',
},
{},
{},
],
[
{
text: 'Header 1',
style: 'tableHeader',
alignment: 'center',
},
{
text: 'Header 2',
style: 'tableHeader',
alignment: 'center',
},
{
text: 'Header 3',
style: 'tableHeader',
alignment: 'center',
},
],
[
'Sample value 1',
'Sample value 2',
'Sample value 3',
],
[
{
rowSpan: 3,
borderColor: ['#ff00ff', '#00ffff', '#ff00ff', '#00ffff'],
text: 'rowSpan set to 3\nLorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor',
},
'Sample value 2',
{
text: 'Sample value 3',
borderColor: ['#ff00ff', '#00ffff', '#ff00ff', '#00ffff'],
},
],
[
'',
'Sample value 2',
'Sample value 3',
],
[
'Sample value 1',
'Sample value 2',
'Sample value 3',
],
[
'Sample value 1',
{
colSpan: 2,
rowSpan: 2,
borderColor: ['#ff00ff', '#00ffff', '#ff00ff', '#00ffff'],
text: 'Both:\nrowSpan and colSpan\ncan be defined at the same time',
},
'',
],
[
'Sample value 1',
{
text: 'a', borderColor: ['#ff00ff', '#00ffff', '#ff00ff', '#00ffff'],
},
{
text: '',
borderColor: ['#ff00ff', '#00ffff', '#ff00ff', '#00ffff'],
},
],
],
},
},
{ text: 'Image on table', pageBreak: 'before', style: 'subheader' },
{
style: 'tableExample',
color: '#444',
table: {
widths: [200, 'auto', 'auto'],
headerRows: 2,
// keepWithHeaderRows: 1,
body: [
[
{
text: 'Header with Colspan = 3',
style: 'tableHeader',
colSpan: 3,
borderColor: ['#ff00ff', '#00ffff', '#ff00ff', '#00ffff'],
alignment: 'center',
},
{},
{},
],
[
{
text: 'Header 1',
style: 'tableHeader',
alignment: 'center',
},
{
text: 'Header 2',
style: 'tableHeader',
alignment: 'center',
},
{
text: 'Header 3',
style: 'tableHeader',
alignment: 'center',
},
],
[
{
image: 'fonts/sampleImage.jpg',
cover: {width: 100, height: 100 },
},
{
image: 'fonts/sampleImage.jpg',
cover: {width: 100, height: 100 },
},
{
image: 'fonts/sampleImage.jpg',
cover: {width: 100, height: 100 },
},
],
[
{
image: 'fonts/sampleImage.jpg',
fit: [100, 100],
},
{
image: 'fonts/sampleImage.jpg',
fit: [100, 100],
},
{
image: 'fonts/sampleImage.jpg',
fit: [100, 100],
},
],
],
},
},
],
styles: {
header: {
fontSize: 18,
bold: true,
margin: [0, 0, 0, 10]
},
subheader: {
fontSize: 16,
bold: true,
margin: [0, 10, 0, 5]
},
tableExample: {
margin: [0, 5, 0, 15]
},
tableOpacityExample: {
margin: [0, 5, 0, 15],
fillColor: 'blue',
fillOpacity: 0.3
},
tableHeader: {
bold: true,
fontSize: 13,
color: 'black'
}
},
defaultStyle: {
// alignment: 'justify'
},
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/tables.pdf').then(() => {
console.log(new Date() - now);
}, err => {
console.error(err);
});