jspdfjspdf-autotable

Page border for pdf exported using jspdf


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?


Solution

  • 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');