Open
Description
I'm using JsPDF to download an html styled element, but when it is downloaded, it takes too long to be showed in google chrome as pdf (shows just an empty pdf document at first and charge it after long time),
the size of the file is only 300KB, I don't know why I have this problem however it's showed correctly in mozilla firefox browser
Please do you know how could I solve this problem.
this is my code
generatePDF = () => {
var doc = new jsPDF('p','pt',"a4");
const inp = document.getElementById("cv");
doc.html( inp , {
html2canvas: {
scale: 0.75,
},
callback: function (doc) {
var pageCount = doc.internal.getNumberOfPages();
doc.deletePage(pageCount)
doc.save("download.pdf");
}
});
}
this is the pdf file:
downloaded.pdf
Activity
HackbrettXXX commentedon Apr 20, 2021
Please attach the PDF document.
stounej commentedon Apr 20, 2021
I have edited my post and included the pdf document, this is the code rendered in the pdf document:
HackbrettXXX commentedon Apr 22, 2021
The performance issue seems to be that each letter is written as a single chunk of text. Why that is, I don't know, yet.
stounej commentedon Apr 22, 2021
I tried to transform the document to an Image before saving it and it worked but the text inside the pdf can't be copied,
I need the text to be copyable.
KurtGokhan commentedon Jul 26, 2021
Seems like if there is
letter-spacing
in CSS, this will happen. Here is the workaround I am using to removeletter-spacing
for PDF:kevinmelo commentedon Sep 10, 2021
Any return? have the same issue
KurtGokhan commentedon Oct 1, 2021
In addition to
letter-spacing
, too many words can also cause this issue. Whenletter-spacing
is not 0, each letter is rendered separately. But when it is 0,html2canvas
renders each word separately and that still makes the PDF size grow too much and cause performance problems.I created this PR in
html2canvas
which significantly improves the performance by rendering multiple words in a line together.4 remaining items
DanLopess commentedon Dec 20, 2021
@KurtGokhan Yeah unfortunately that wouldn't be ideal. However if I did that, since my HTML converts into multiple pages the image would have to be split (still haven't figured out how to do that) and I would have to calculate how many pages would be needed.
CollenZhou commentedon Jan 6, 2022
Hi dear authors any update?
CollenZhou commentedon Jan 7, 2022
Hi, just FYI. I noticed if a single table cell contains too much text will cause the performance issue. Hope it helps.
github-actions commentedon Apr 8, 2022
This issue is stale because it has been open 90 days with no activity. It will be closed soon. Please comment/reopen if this issue is still relevant.
prasheel888 commentedon Oct 18, 2022
Also having the same issue, Any Suggestions guys??
kevinmelo commentedon Oct 18, 2022
At the end the best solution was using Puppeeter with my nodejs backend
prasheel888 commentedon Oct 18, 2022
Thanks For Suggestion!!
haaah commentedon Jan 3, 2024
trying @KurtGokhan css hack does improve the rendering speed a little but when there's Word Starting With Upper Case it will sometimes join 2 word together --> WordWord.
Is there any other workaround ?
adamturski commentedon Feb 28, 2024
In my case generated PDF was loading fine in Ubuntu Document Viewer, but not in Chrome PDF viewer. Rendering was slow for some pages, visible especially on scrolling (but also on load if I put problematic element on first page). I could narrow down the issue to border-radius style on my table element. If text was short then there was no issue, but for long texts it was loading very long (forever). I set border-radius to 0 on my table container class and problem disappeared. I do not know why is that.
I also played with letter-spacing style and set 0 globally, but it helped just a little I would say - finally border-radius solved the issue.
Html:
Css:
JS:
Amatewasu commentedon Feb 28, 2024
@adamturski Thank you for the update. I just tested and I reproduce that removing the border radius in my generated pdf make them way faster in chrome.