Skip to content

html() function always starts on first page #3204

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
glebov21 opened this issue Jul 8, 2021 · 9 comments
Open

html() function always starts on first page #3204

glebov21 opened this issue Jul 8, 2021 · 9 comments

Comments

@glebov21
Copy link

glebov21 commented Jul 8, 2021

Hello. Does jsPDF.html method can draw <table> in pdf?
And how can i with html() draw in not first page of pdf?

@HackbrettXXX
Copy link
Collaborator

Yes, html can draw tables.

Just call addPage/setPage before html.

@glebov21
Copy link
Author

I was try, but can't draw html on second page: https://jsitor.com/OjADPcBNh

@HackbrettXXX
Copy link
Collaborator

Ah, you're right. There seems to be a bug in jsPDF. The context2d.autoPaging property is set to true (which is probably good for most use cases):
https://github.com/MrRio/jsPDF/blob/cef97fb34eda41a8704c9f3983e680919a328ce4/src/modules/html.js#L451-L454

However, the autoPaging mechanism doesn't respect the starting page. See e.g. here:

https://github.com/MrRio/jsPDF/blob/cef97fb34eda41a8704c9f3983e680919a328ce4/src/modules/context2d.js#L1675-L1681

A workaround would be to first call html with only one page and the afterwards add another page with insertPage before the first page.

@HackbrettXXX HackbrettXXX reopened this Jul 13, 2021
@HackbrettXXX HackbrettXXX changed the title jsPDF html() with table html() function always starts on first page Jul 13, 2021
@mageshwaran-p
Copy link

Hi, any update regarding this issue? I've been facing the same issue.. Trying to add some html content after a table in the first few pages.. But the html content always starts from the first page on top of the table contents.

@glebov21
Copy link
Author

glebov21 commented Jul 29, 2021

Hi, any update regarding this issue? I've been facing the same issue.. Trying to add some html content after a table in the first few pages.. But the html content always starts from the first page on top of the table contents.

While issue not fixed, i use offset by y coord:

doc.html(mdDiv,
    { 
    callback: function (doc) {doc.save(); },
    y: ((pageNum-1) * pageHeight) + offsetY,
    });

@kanisshka
Copy link

i want to work on this issue

@guilhermelimak
Copy link

Hey, is this issue still valid? If so, is there a way to get a new repro link? Looks like the old link was removed (returning 404 now). I tried working on it but would be very nice to help me understand the issue and confirm it's all working once fixed.

@Polarisation
Copy link

I'm still experiencing this issue in the most recent version of jspdf, though I can't offer a repro at the moment. The workaround of #3204 (comment) worked for me.

@elreyponce
Copy link

The only way I found to re-execute the html function was to place the y from the height of the document.
Note: you must take into account in the formula to calculate the Y, subtract the margins of the first html from the height.
For example:

pdf.html(htmlContent,
        callback: (doc) => {
          doc.html(htmlContent2, {            
            y: (doc.internal.pageSize.getHeight() - MARGIN)* doc.getNumberOfPages() - 1,    
            callback: (doc) => {
              window.open(doc.output("bloburl"));
            },
          });
        },
      });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants