question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

jsPdf creating blank pdfs after first pdf generate in loop

See original GitHub issue

for (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:open
  • Created 2 years ago
  • Comments:12

github_iconTop GitHub Comments

2reactions
arnesprembergcommented, Oct 12, 2021

@harshilparmar But the original example doesn’t work and it should.

But there is only one jsPdf instance right?

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 😃

1reaction
HackbrettXXXcommented, Oct 6, 2021

@harshilparmar sure, go ahead 😉

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found