Page border for pdf exported using jspdf

5.7k views Asked by At

I need to get the page border while download a pdf file using the jspdf function.

How can I achieve this. I am able to set border for tables alone and not able to set for the pages.

var doc = new jsPDF('p', 'pt');
doc.setFontSize(12);
doc.setTextColor(0);
doc.setFontStyle('bold');
doc.text('Col and row span', 40, 50);
var elem = document.getElementById("table1");
var elem1 = document.getElementById("tbl1");
var elem1 = document.getElementById("example");
var res = doc.autoTableHtmlToJson(elem);
var res1 = doc.autoTableHtmlToJson(elem1);
doc.text('Theme "plain"', 40, doc.autoTableEndPosY() + 30);
doc.autoTable(res.columns, res.data, {
    startY: 90,
    theme: 'grid',
    drawHeaderRow: function(cell, data) {
        return false;
    },
    pageBreak: 'avoid',
    margin: {
        right: 305
    }
});
doc.autoTable(res.columns, res.data, {
    startY: 90,
    pageBreak: 'avoid',
    theme: 'grid',
    drawHeaderRow: function(cell, data) {
        return false;
    },
    margin: {
        left: 305
    }
});
doc.autoTable(res1.columns, res1.data, {
    startY: doc.autoTableEndPosY() + 30,
});

how can i set border for this doc?

2

There are 2 answers

2
Simon Bengtsson On BEST ANSWER

If you by page border mean a border around the entire page, try something like this:

doc.rect(20, 20, doc.internal.pageSize.width - 40, doc.internal.pageSize.height - 40, 'S');
0
Nagarajan R On

For multiple pages we can do like this

for (let i = 0; i < doc.getNumberOfPages(); i++) {
        doc.setPage(i + 1)
        doc.setDrawColor("#000000");
        doc.rect(5, 5, pdf.internal.pageSize.width - 10, pdf.internal.pageSize.height - 10, 'S');
      }