jsPDF icon indicating copy to clipboard operation
jsPDF copied to clipboard

Footer not working

Open ABeltramo opened this issue 12 years ago • 6 comments

I'm trying to create a simple footer on my PDF and I find this If i use this simple HTML code

<html>
   <body>
      Test
   <footer>asd</footer>
   </body>
</html>

This error show up on the console: jsPDF PubSub Error Maximum call stack size exceeded RangeError jsPDF.min.js:168 And this is the resulting PDF: schermata 2014-11-27 alle 22 53 34

856 pages all white! This is the code I use to generate the PDF

     doc.fromHTML(html, 100, 15, {
                'width': 350, 
                'elementHandlers': {}
            },function(e){
                doc.save("test.pdf")    ;
            });

Using jsPDF 1.0.272-git Built on 2014-09-29T15:09

ABeltramo avatar Nov 27 '14 21:11 ABeltramo

Up! You can try in your example site just by paste this:

var doc = new jsPDF();

var html = "<html><body>Test<footer>asd</footer></body></html>"

// We'll make our own renderer to skip this editor
var specialElementHandlers = {
    '#editor': function(element, renderer){
        return true;
    }
};

// All units are in the set measurement for the document
// This can be changed to "pt" (points), "mm" (Default), "cm", "in"
doc.fromHTML(html, 15, 15, {
    'width': 170, 
    'elementHandlers': specialElementHandlers
});

If you just remove the

part all seems to working.

ABeltramo avatar Dec 04 '14 17:12 ABeltramo

still not working with latest

beinto avatar Mar 18 '15 12:03 beinto

I think the problem is caused by this line: https://github.com/MrRio/jsPDF/blob/master/jspdf.plugin.from_html.js#L778

if (this.pdf.internal.pageSize.height - this.pdf.margins_doc.bottom < this.y + this.pdf.internal.getFontSize()) {
...
this.pdf.addPage();
...
}

There is a comparison of mm values, but this.pdf.internal.getFontSize() returns a pt value which is obviously bigger. So you can never write a footer because it always seems to be to close to the bottom of the page and every time a new page is added...

Multiplying this.pdf.internal.getFontSize() with 25.4/72 solved this problem for me.

Btw. the missing unit conversion caused some problems with tables, too.

JosuaStadelmaier avatar Mar 18 '15 17:03 JosuaStadelmaier

Any update about this? I as well can't seem to get footers to work...

ashercoren avatar Feb 15 '17 19:02 ashercoren

In current version, the font size is still not multiplied with the scaleFactor

Uzlopak avatar Feb 17 '18 08:02 Uzlopak

We are closing this issue, because we will not support any longer fromHTML and addHTML.

Explaination: We are working on a new html2pdf plugin, which will be based on html2canvas and our context2d plugin. This should lead to more reliable results for your projects. And it will give us the time to focus on the core functionality of pdf-generation because we will not use our energy for writing/supporting/extending 2 html plugins. If you still want to use addHTML or fromHTML you can still use jsPDF 1.4.1.

Best Regards

Uzlopak avatar Sep 06 '18 20:09 Uzlopak