How do I add page numbering to a jsPDF document? Is there any API avaialble.
hi,
actually, I proceed like that:
var doc = new jsPDF();
doc.page=1;
// then use this as a counter.
function footer(){
doc.text(150,285, 'page ' + doc.page);
doc.page ++;
};
// and i call footer() after each doc.addPage()
Hope it helped,
FC
Thanks so much. Actually I ended up doing the same :-). Just didn't get a chance to reply back to the thread.
Thanks so much for getting back to me on this
Sg
Sent from my iPhone
On Jun 25, 2013, at 9:56 AM, FlyingC [email protected] wrote:
hi,
actually, I proceed like that:var doc = new jsPDF();
doc.page=1;// then use this as a counter.
function footer(){
doc.text(150,285, 'page ' + doc.page);
doc.page ++;
};// and i call footer after each doc.addPage()
—
Reply to this email directly or view it on GitHub.
You're welcome.
I'm trying to add a new page as the first page fill up. I have 3 textareas separated by "\n\n". The second textarea has the potential to be really long. When I create the pdf, the text simply goes to the end of the first page and stops. Help please!
Is there any way to add total number of pages to the header? Like 1/100, 2/100, ..., 100/100?
Yes, with "doc.internal.getNumberOfPages()"
I ended up using the above doc.internal.getNumberOfPages() by adding this code just before outputting/saving the pdf. So that there is no need to keep track of added pages during pdf creation when for example using autoTables.
const pages = doc.internal.getNumberOfPages();
const pageWidth = doc.internal.pageSize.width; //Optional
const pageHeight = doc.internal.pageSize.height; //Optional
doc.setFontSize(10); //Optional
for (let j = 1; j < pages + 1 ; j++) {
let horizontalPos = pageWidth / 2; //Can be fixed number
let verticalPos = pageHeight - 10; //Can be fixed number
doc.setPage(j);
doc.text(`${j} of ${pages}`, horizontalPos, verticalPos, {align: 'center' //Optional text styling});
}
// Then save
doc.save('thePDF.pdf');
Most helpful comment
I ended up using the above
doc.internal.getNumberOfPages()by adding this code just before outputting/saving the pdf. So that there is no need to keep track of added pages during pdf creation when for example using autoTables.