Skip to content
Advertisement

How to set top and bottom margin in .HTML using jspdf

how to add margin-bottom and top at multiple pages pdf .

although i am using the latest version of jspdf which uses .html function

let doc = new jsPDF('p', 'pt', 'a4');
let myImage = '../../../assets/logo.png';
var margins = {
top: 40,
bottom: 60,
left: 40,
width: 522
    };

doc.html(document.getElementById('htmlData'), {
callback: function (pdf) {

pdf.output('dataurlnewwindow');
      },
    });

thank you for help

Advertisement

Answer

I think you forgot to add the margins variable into the .html() I added it as an array below.

let doc = new jsPDF('p', 'pt', 'a4');
let myImage = '../../../assets/logo.png';

doc.html(document.getElementById('htmlData'), {
// Adjust your margins here (left, top, right ,bottom)
margin: [40, 60, 40, 60],
callback: function (pdf) {

pdf.output('dataurlnewwindow');
      },
    });
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement