Skip to content

Does jsPDF have a height limit? #3120

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

Closed
zokanzi opened this issue Mar 19, 2021 · 3 comments
Closed

Does jsPDF have a height limit? #3120

zokanzi opened this issue Mar 19, 2021 · 3 comments

Comments

@zokanzi
Copy link

zokanzi commented Mar 19, 2021

I have a long html file which i want convert to pdf. I noticed that jspdf did not create the pdf file with a height of more than 65519px. I tried this as follows.

This way I was able to get the pdf file

<body>
   <div style="height: 65519px"> dasd</div>
</body>

<script>
let doc = new jsPDF('1','pt','a4');
doc.addHTML(document.body, {pagesplit: true}, function() {
    doc.save('offer.pdf');
});
</script>

But jsPDF did nothing as follows

<body>
   <div style="height: 65520px"> dasd</div>
</body

<script>
let doc = new jsPDF('1','pt','a4');
doc.addHTML(document.body, {pagesplit: true}, function() {
    doc.save('offer.pdf');
});
</script>

Users have been told there is no limit. I thinking that this problem may be caused by the browser, I tried it from different computers and browsers. However, the same problem occurred. I would be glad if you help

Try on CodePen.io

@zokanzi zokanzi changed the title Have jsPDF document height limitation? Does jsPDF have a height limit? Mar 20, 2021
@HackbrettXXX
Copy link
Collaborator

First of all: you are using a really old version of jsPDF. It's probably a good idea to update to a more recent version.

I think the issue is indeed due to browser limitations. The addHTML function converts the HTML to a bitmap image before adding it to the PDF. The browser probably has a limit on how large this image can be.

As a solution I suggest to update to 2.3.x and use the html function instead of addHTML. It does not convert the HTML to an image and instead renders it as text and vector graphics. Note though, that there are some issues with the margins currently: #2924.

@zokanzi
Copy link
Author

zokanzi commented Mar 22, 2021

I updated jsPDF. I am using the most current version right now. But I think your guess is correct. Browsers have certain canvas limits, and I couldn't find a way to get around this. I worked really hard to write my code and I don't have time to rewrite it. So I can't use html function instead of addHHTML . I will try to split the document into appropriate sizes and create multiple documents.

Thanks for reply.

@HackbrettXXX
Copy link
Collaborator

Alright. I'm closing this, because it's not really an issue of jsPDF. We can still use this for discussion.

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

No branches or pull requests

2 participants