jsPDF-AutoTable icon indicating copy to clipboard operation
jsPDF-AutoTable copied to clipboard

Bug: addPageContent

Open romeoDo opened this issue 9 years ago • 1 comments

The new addPageConent Hook won't be triggered if I add a new page manually e.g.

// FAILED to RUN IF I USE doc.autoTableAddPage(); manually
examples['header-footer'] = function () {
    var doc = new jsPDF();
    var totalPagesExp = "{total_pages_count_string}";

    var pageContent = function (data) {
		console.log(data.pageCount);
        // HEADER
        doc.setFontSize(20);
        doc.setTextColor(40);
        doc.setFontStyle('normal');
        doc.addImage(headerImgData, 'JPEG', data.settings.margin.left, 15, 10, 10);
        doc.text("Report", data.settings.margin.left + 15, 22);

        // FOOTER
        var str = "Page " + data.pageCount;
        // Total page number plugin only available in jspdf v1.0+
        if (typeof doc.putTotalPages === 'function') {
            str = str + " of " + totalPagesExp;
        }
        doc.setFontSize(10);
        doc.text(str, data.settings.margin.left, doc.internal.pageSize.height - 10);
    };
    
    doc.autoTable(getColumns(), getData(40), {
        addPageContent: pageContent,
		drawCell: function(row, data) {doc.autoTableAddPage()},
        margin: {top: 30}
    });

    // Total page number plugin only available in jspdf v1.0+
    if (typeof doc.putTotalPages === 'function') {
        doc.putTotalPages(totalPagesExp);
    }

    return doc;
};

On a side note: Why did u decide to remove the

beforePageContent: function(data) {},
afterPageContent: function(data) {},
afterPageAdd: function(data) {}

They are good for many things :(

P/S: This problem caused by the latest changes.

Edited: Add Information

romeoDo avatar Jan 05 '17 06:01 romeoDo

Can you verify that version 2.2 fixed this issue? If not, can you try using drawRow instead with data.addPage instead of doc.autoTableAddPage?

The reason for removing the hooks you listed was that everything you could do with them could be done with one hook: addPageContent. Or have you found a use case that does not work with `addPageContent?

simonbengtsson avatar Jan 09 '17 13:01 simonbengtsson