I just want to know if there is anyway i can add the page border in PDF file generated by pdfmake.
Asked
Active
Viewed 4,803 times
0
-
1Checked this: https://stackoverflow.com/questions/29936965/add-border-arround-a-paragraph-with-pdfmake? – Jagdeep Singh May 08 '18 at 06:47
-
Thank you but I want border around whole page instead of a specific paragraph – Haseeb Rehman May 09 '18 at 06:11
2 Answers
2
This is probably not the best way, but you could use a table to wrap the whole document, and set its borders.
let docDefinition = {
content: [
{
table: {
body: [[{
stack: [
//you content goes here
]
}]]
},
layout: {
//set custom borders size and color
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';
}
}
}
]
}
pdfMake.createPdf(docDefinition).open();

Stefano Mozart
- 1,191
- 10
- 11
2
If you need to have a border for each page you can do sth like that:
var dd = {
background: function (currentPage, pageSize) {
return [
{
canvas: [
{ type: 'line', x1: 5, y1: 5, x2: 590, y2: 5, lineWidth: 1 }, //Up line
{ type: 'line', x1: 5, y1: 5, x2: 5, y2: 835, lineWidth: 1 }, //Left line
{ type: 'line', x1: 5, y1: 835, x2: 590, y2: 835, lineWidth: 1 }, //Bottom line
{ type: 'line', x1: 590, y1: 5, x2: 590, y2: 835, lineWidth: 1 }, //Rigth line
]
}
]
},
content: []
}
You can give it a shot here http://pdfmake.org/playground.html

Vitalik Yepik
- 126
- 1
- 7