Add doc.putTotalPages function when printing PDF
See original GitHub issueIs your feature request related to a problem? Please describe. I need a way to add “Page 1 of n” footer when using the PDF download option. This should be possible via AutoTable and jsPDF but it needs the following lines added after doc.autoTable(…) has been called.
Describe the solution you’d like Add the following code to https://github.com/olifolkerd/tabulator/blob/9e32aa87a9169503dfb6069a8eb60ec4e9d602d8/src/js/modules/download.js#L624
if (options.totalPagesExp) {
if (typeof doc.putTotalPages === 'function') {
doc.putTotalPages(options.totalPagesExp);
}
}
totalPagesExp
can then be passed as an option to the download
function:
const totalPagesExp = "{total_pages_count_string}";
table.download( "pdf", "data.pdf", {
orientation: "portrait", //set page orientation to portrait
title: "PDF Page Numbers Test",
totalPagesExp: totalPagesExp,
autoTable: ( doc ) => {
doc.autoTableSetDefaults( {
addPageContent: ( data ) => {
let footerStr = "Page " + doc.internal.getNumberOfPages();
if ( typeof doc.putTotalPages === 'function' ) {
footerStr = footerStr + " of " + totalPagesExp;
}
doc.setFontSize( 10 );
doc.text( footerStr, data.settings.margin.left, doc.internal.pageSize.height - 10 );
}
} );
//return the autoTable config options object
return {
columnStyles: columnStyles,
};
},
} );
Describe alternatives you’ve considered Doesn’t seem to be any way to workaround this at present.
Additional context https://github.com/simonbengtsson/jsPDF-AutoTable/issues/144#issuecomment-363945044
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:6 (6 by maintainers)
Top Results From Across the Web
putTotalPages not working in jspdf-autotable header
I am trying to add 'Page number x of y' to a PDF generated using jspdf and jspdf-autotable. I have used the code...
Read more >Creating customisable & beautiful PDFs using jsPDF API ...
Hi All,. I recently came across a requirement wherein I had to generate statements of account in PDF format. In this article, you...
Read more >Advanced PDF print settings - Acrobat Pro
Advanced PDF print settings in Adobe Acrobat Pro for PostScript and ... Specifies how fonts and resources in the document are sent to...
Read more >simonbengtsson/jsPDF-AutoTable - Gitter
Hello all, hopefully, someone can help. I'm using autotable to generate a pdf with a table that has styling applied to it through...
Read more >Convert HTML /CSS Content to a Sleek Multiple Page PDF ...
jspdf puttotalpages: Convert HTML /CSS Content to a Sleek Multiple Page PDF File . ... jspdf page size a4: How do I add...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@olifolkerd Thanks for doing this change! Just got around to upgrading to 4.3.0 and it works fine:
Hey @darshanrampatel
i have added a new documentProcessing option to the download options object, you can pass a callback to this that gives you access to the document object to call any functions you like on:
It is currently on the 4.3 branch that will be released later today
Cheers
Oli 😃