Search code examples
jspdf

jsPDF change page format


I have a function to set a footer on a page. But I want to make the code more flexible and add an if statement where I want it to set the footer on a different position when the document is an 'a4' or a3'.

function footer(){
    doc.setFontSize(11);
    doc.text(180,280, 'Seite ' + doc.page);
    doc.page ++;
    }

But I can't find the paramater to change the format after the page has been initiated:

var doc = new jsPDF('p', 'mm', 'a4');

I tried:

doc.format('a3');
doc.setFormat = 'a3';
doc.setPageFormat('a3');

but none works.

Does someone know the paramater to change page format anywhere in the code even after "new jsPDF" initiation? Or does this simply not work?

Thanks in advance!


Solution

  • You can set format and orientation on each new page:

    doc.addPage('a3', 'portrait');
    

    Orientation is either 'portrait' or 'landscape'

    Alternately you can also set the height and widht:

    doc.addPage(newWidth, newHeight);
    

    In this case the units will be the same as in your jsPDF instantiation ('mm'):

    var doc = new jsPDF('p', 'mm', 'a4');