question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

hi,

when producing a pdf with multiple tables and the footer as specified in the example, it seems as if the footer was added again with every table thats drawn. also the page numbering is incorrect.

var footer = function (data) {
                doc.setFontSize(10);
                doc.setFontStyle('normal');
                var str = "Page " + data.pageCount;
                str = str + " of " + totalPagesExp;
                doc.text(str, data.settings.margin.left, doc.internal.pageSize.height - 30);
                var today = new moment().format("YYYY-MM-DD");
                doc.text(today, right, doc.internal.pageSize.height - 30, 'right');
            };
doc.autoTable(columns, [], {
                        startY: doc.autoTableEndPosY(),
                        afterPageContent: footer,
                        headerStyles: {
                            fillColor: 255,
                            textColor: 0,
                            fontStyle: 'bold',
                            rowHeight: 20
                        }
                    });

page 1

image

other pages

image

last page (6)

image

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

18reactions
funflyercommented, Jul 12, 2016

ok i found a permanent fix. just call the footer function at every table generation and use the jspdf.numberofpages() function to print the actual page nr. no need to change the autotables api:

var currentpage = 0;

            var footer = function (data) {

                if (currentpage < doc.internal.getNumberOfPages()) {

                    doc.setFontSize(10);
                    doc.setFontStyle('normal');

                    var str = "Page " + doc.internal.getNumberOfPages();
                    str = str + " of " + totalPagesExp;
                    doc.text(str, data.settings.margin.left, doc.internal.pageSize.height - 30);
                    var today = new moment().format("YYYY-MM-DD");
                    doc.text(today, right, doc.internal.pageSize.height - 30, 'right');
                    currentpage = doc.internal.getNumberOfPages();
                }
            };
12reactions
jwmanncommented, Feb 7, 2018

Also for reference, you don’t really need a page counter variable. This is my barebones version for anyone else’s future reference.

const totalPagesExp = "{total_pages_count_string}";

doc.autoTable(columns, data, {
  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);
  }
});

if (typeof doc.putTotalPages === 'function') {
  doc.putTotalPages(totalPagesExp);
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Insert page numbers - Microsoft Support
Select Insert > Page Number, and then choose the location and style you want. · If you don't want a page number to...
Read more >
Word: Page Numbers - GCF Global
Page numbers can be used to automatically number each page in your document. They come in a wide range of number formats and...
Read more >
Page numbering - Overleaf, Online LaTeX Editor
Page numbering. Document page numbers can be typeset using a particular style, such as using Arabic or Roman numerals, and typeset at a...
Read more >
Add page numbering to your pages in Adobe InDesign
Page number markers are commonly added to parent pages. When parent pages are applied to document pages, the page numbering is updated ...
Read more >
How to Add Page Numbers in Word - CustomGuide
1. Click the Insert tab. 2. Click the Page Number button. Next, choose where you want the page number to appear. You can...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found