Git Product home page Git Product logo

Comments (4)

simonbengtsson avatar simonbengtsson commented on September 24, 2024

You should be able to use any jspdf function in the header and footer functions, including addHTML. I haven't used that function myself however. Do you get an error message?

from jspdf-autotable.

danieldacruzferreira avatar danieldacruzferreira commented on September 24, 2024

Hello
I don't get any error, the header is blank.
I noticed that the addHtml() inside the header function runs after doc.save ('table.pdf'). That is, addHTML() runs only after the PDF is ready.

My test:

        var totalPagesExp = "{total_pages_count_string}";
    var doc = new jsPDF('p', 'pt');

    var htmlHeader = $(".report-container header")[0];

    var header = function (docPage, pageCount, options) {

        docPage.addHTML(htmlHeader, null, function(){

            console.log("adding header");

        });
    };

    var footer = function (doc, lastCellPos, pageCount, options) {
    var str = "Page " + pageCount;
        // Total page number plugin only available in jspdf v1.0+
        if (typeof doc.putTotalPages === 'function') {
            str = str + " of " + totalPagesExp;
        }
        doc.text(str, options.margins.horizontal, doc.internal.pageSize.height - 30);
    };
    var options = {renderHeader: header, renderFooter: footer, margins: {horizontal: 40, top: 80, bottom: 50}};


    doc.autoTable(columns, data, options);

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

    console.log("saving pdf");

         doc.save('table.pdf');

Firebug console output:

saving pdf
(4) adding header (called 4 times, once per page)

from jspdf-autotable.

simonbengtsson avatar simonbengtsson commented on September 24, 2024

I read some about the addHTML function add it seems like you have to use it like this

var pdf = new jsPDF('p','pt','a4');
pdf.addHTML(document.body,function() {
    pdf.save('web.pdf');
});

Unfortunaletly that means that you can't use it in the renderHeader or renderFooter functions afterall. Sorry for the confusing answer above.

from jspdf-autotable.

danieldacruzferreira avatar danieldacruzferreira commented on September 24, 2024

OK, I'll try some other way
Thank you :)

from jspdf-autotable.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.