Jspdf: Saving pdf with jsPDF gives error: Cannot read property 'elementHandlers' of undefined

Created on 11 Feb 2017  路  2Comments  路  Source: MrRio/jsPDF

I want to automatically save certain webpages as pdf. For that I came across jsPDF. The code on target page was not working. So I created a dummy code:

$.getScript('https://cdnjs.cloudflare.com/ajax/libs/jspdf/0.9.0rc1/jspdf.min.js');

var doc = new jsPDF();

var pdfStr = "<div><div>Mahesh</div><img src=\"https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png\" /></div>"

//creating dom from string
var div =  document.createElement('div');
div.innerHTML = pdfStr;
var pdfHtml = div.childNodes;
doc.fromHTML(pdfHtml);
doc.save('pdfjsdemo.pdf');

I am copy pasting following code in Chromes console and hitting Enter. It is giving me:

Uncaught TypeError: Cannot read property 'elementHandlers' of undefined
    at Object.f.fromHTML (jspdf.min.js:75)
    at <anonymous>:11:5

I used dom string in format <div><div></div><img></img></div> because thats how my target page looks like.

Besides, it works, if I use

doc.text("<div>mahesh</div>");

saving desired pdf.

So whats going on here?

All 2 comments

Nice dude! You use a super old version. 0.9.0rc1

How about using the current version?

https://raw.githubusercontent.com/MrRio/jsPDF/master/dist/jspdf.debug.js

Come back if you tested it with the new version.

@MrRio
Please close. No issue, just ignorance.

It is same my problem, I got new version for jsdpf, but new error is appeared
Uncaught TypeError: Cannot create property 'outY' on boolean 'true'
at DrillForContent (jspdf.js?v4.5:7470)
at DrillForContent (jspdf.js?v4.5:7441)
at DrillForContent (jspdf.js?v4.5:7441)
at jspdf.js?v4.5:7609
at done (jspdf.js?v4.5:7484)
at Image.img.onerror.img.onload (jspdf.js?v4.5:7506)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tarekis picture tarekis  路  4Comments

MaxCodeDE picture MaxCodeDE  路  4Comments

MelanieCroce picture MelanieCroce  路  4Comments

0721Betty picture 0721Betty  路  4Comments

NoFootDancer picture NoFootDancer  路  3Comments