jsPdf creating blank pdfs after first pdf generate in loop
See original GitHub issuefor (let i=0;i<2;i++){
for (let j=0;j<2;j++){
let doc = new jsPDF(“p”, “pt”, “a4”);
doc.html(<p>hi ${i} ${j}</p>
, {
callback: function (pdf) {
pdf.save(i+“_”+j+“.pdf”);
}
});
}
}
Issue Analytics
- State:
- Created 2 years ago
- Comments:12
Top Results From Across the Web
jsPdf creating blank pdfs after first pdf generate in loop #3249
Thanks for reporting this. The reason for the bug is that with your code, the calls to html are executed in parallel due...
Read more >jspdf output is getting blank pdf - javascript - Stack Overflow
But I have the 115 rows in the database, for this the pdf's are displaying as empty, don't know why it is happening?...
Read more >Help with jsPDF, generating blank pdf when I try to add mulitline
I've been building a feature that generates pdfs client-side and have been getting deep into some libraries that abstract the encoding away -...
Read more >Component generates PDF-file with one blank page. What's ...
I have added the PDF Generator (jsPDF) component to our Web. ... when I click on the button to generate the PDF-file I...
Read more >html2pdf.js | Client-side HTML-to-PDF rendering using pure JS.
html2pdf.js converts any webpage or element into a printable PDF entirely client-side using html2canvas and jsPDF. :warning: There have been several issues ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
If a new instance is created in a root that means it’s created multiple times thus there are multiple instances.
Without being tied to the maintainers of the project, or knowing the codebase, I could see two approaches to solve this:
One (easier) solution: create a utility function that can be used in place of a loop (so could have a similar syntax to the javascript forEach) that triggers the html rendering recursively as I have shown in my codesnippet above.
Another (cleaner) solution: make sure multiple instances of jsPDF do not share state when called simultaneously. I could imagine that in this specific use case the shared state is related to an HTML canvas or a similar renderer.
I guess @HackbrettXXX has more of an insight and more of an opinion on this 😃
@harshilparmar sure, go ahead 😉