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.

Callback Function Not Called - addHTML & fromHTML

See original GitHub issue

Thank you for submitting an issue to jsPDF. Please read carefully.

jsPDF Version 1.3.5

Have you tried using jspdf.debug.js? Yes, currently using it.

Steps to reproduce

var doc = new jsPDF();
doc.fromHTML(document.getElementById("chip"), function(){
            console.log("Callback");
           doc.save('test.pdf');
})

If I use addHTML instead, I get the same issue. I see the canvas object being rendered

0ms html2canvas: html2canvas 1.0.0-alpha.10
189ms html2canvas: Canvas renderer initialized (1746x32 at 174,437) with scale 1

But the callback function is still not called.

http://jsbin.com/qamececego/edit?html,js,output

What I saw Callback function is not called. Console.log not executed and pdf not saved.

What I expected Callback function to be called.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:8

github_iconTop GitHub Comments

11reactions
gonzaReycommented, Mar 21, 2018

you are calling it completely wrong.

but they are also missing documentation.

fromHTML( element.innerHTML, xAxis, yAxis, { options and settings (which I dont know)}, callback HERE! )

so it would be your 5th parameter you are trying to call it on the second… probably getting an error.

GL

1reaction
rener172846commented, Mar 2, 2019

It seems the addHTML function is deprecated. Here is another way to create PDF file.

html2canvas(document.body).then(canvas => {
    let pdf = new jsPDF('p', 'mm', 'a4');
    pdf.addImage(canvas.toDataURL('image/png'), 'PNG', 0, 0, 211, 298);
    pdf.save(filename);
});

I can get rendered pdf file with above code, but there are still some small style issues yet. So finally I removed jsPDF library, however I will check if this library will be improved later as well.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Callback Function Not Called - addHTML & fromHTML #1693
Callback function is not called. Console.log not executed and pdf not saved. What I expected. Callback function to be called.
Read more >
Callback Function Not Called - addHTML & fromHTML
Have you tried using jspdf.debug.js? Yes, currently using it. ... But the callback function is still not called. ... Callback function is not...
Read more >
JSPDF html() Method callback not Fired - PCF - Stack Overflow
jsPDF callback never gets fired because it depends on core-js to handle Promise. If you import 'core-js/features/promise' callback is called ...
Read more >
html2canvas, jspdf warning
The callback function is called when fromHTML in jsPDF loaded all images and generated the document. var doc = new jsPDF('p', 'pt', 'a4',...
Read more >
.load() | jQuery API Documentation
A callback function that is executed when the request completes. ... When calling .load() using a URL without a suffixed selector expression, the...
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