You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thanks for reporting this. The reason for the bug is that with your code, the calls to html are executed in parallel due to the asynchronous nature of the html function. If you run the calls strictly after another, it works:
let doc1 = new jsPDF("p", "pt", "a4");
doc1.html(`<p>hi 0</p>`, {
callback: function(pdf) {
pdf.save("0.pdf");
let doc2 = new jsPDF("p", "pt", "a4");
doc2.html(`<p>hi 1</p>`, {
callback: function(pdf) {
pdf.save("1.pdf");
}
});
}
});
However, in theory, different jsPDF instances should be independent of one another and should not share any state. Pull requests to fix this are welcome.
Thanks for reporting this. The reason for the bug is that with your code, the calls to html are executed in parallel due to the asynchronous nature of the html function. If you run the calls strictly after another, it works:
let doc1 = new jsPDF("p", "pt", "a4");
doc1.html(`<p>hi 0</p>`, {
callback: function(pdf) {
pdf.save("0.pdf");
let doc2 = new jsPDF("p", "pt", "a4");
doc2.html(`<p>hi 1</p>`, {
callback: function(pdf) {
pdf.save("1.pdf");
}
});
}
});
However, in theory, different jsPDF instances should be independent of one another and should not share any state. Pull requests to fix this are welcome.
@HackbrettXXX But here it's working fine right !! please guide me here.
@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 :)
Activity
HackbrettXXX commentedon Sep 3, 2021
Thanks for reporting this. The reason for the bug is that with your code, the calls to
html
are executed in parallel due to the asynchronous nature of thehtml
function. If you run the calls strictly after another, it works:However, in theory, different jsPDF instances should be independent of one another and should not share any state. Pull requests to fix this are welcome.
arnespremberg commentedon Sep 11, 2021
Hi there!
I faced the same problen and just came to realise that an easy workaround to this problem is recursion instead of looping.
Hope this may help...
harshilparmar commentedon Oct 6, 2021
Can I take this issue?
HackbrettXXX commentedon Oct 6, 2021
@harshilparmar sure, go ahead ;)
harshilparmar commentedon Oct 10, 2021
@HackbrettXXX So Here I have to fix the behavior of jsPDF instances that should be independent of one another ?
HackbrettXXX commentedon Oct 11, 2021
@harshilparmar yes.
harshilparmar commentedon Oct 11, 2021
@HackbrettXXX But here it's working fine right !! please guide me here.
HackbrettXXX commentedon Oct 12, 2021
@harshilparmar But the original example doesn't work and it should.
harshilparmar commentedon Oct 12, 2021
But there is only one jsPdf instance right?
arnespremberg commentedon Oct 12, 2021
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 :)
HackbrettXXX commentedon Oct 13, 2021
You're absolutely right @arnespremberg. I'm not exactly sure what state exactly is shared, but finding it out is part of the ticket ;)
kanisshka commentedon Oct 1, 2022
i want to work on this issue
1 remaining item