0

I just want to know if there is anyway i can add the page border in PDF file generated by pdfmake.

Jagdeep Singh
  • 4,880
  • 2
  • 17
  • 22
Haseeb Rehman
  • 1,929
  • 1
  • 8
  • 13

2 Answers2

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