Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions jspdf.plugin.addimage.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@

if(element.nodeName === 'CANVAS') {
var canvas = element;
//if already a supported data url image, just return the dataurl
} else if (element.getAttribute('src').indexOf('data:image/') === 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be good checking element.nodeName === 'IMG' before getAttribute()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, getAttribute can return null, so using indexOf on it will throw.

return element.getAttribute('src');
} else {
var canvas = document.createElement('canvas');
canvas.width = element.clientWidth || element.width;
Expand Down
23 changes: 17 additions & 6 deletions jspdf.plugin.from_html.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,22 +420,33 @@
renderer.pdf.internal.events.publish('imagesLoaded');
cb();
}
function loadImage(url) {
function loadImage(url, width, height) {
if (!url)
return;
var img = new Image();
++x;
img.crossOrigin = '';
img.onerror = img.onload = function () {
if (img.complete && img.width + img.height)
images[url] = images[url] || img;
if (!--x)
done();
if(img.complete) {
//to support data urls in images, set width and height
//as those values are not recognized automatically
if (img.src.indexOf('data:image/') === 0) {
img.width = width || 0;
img.height = height || 0;
}
//if valid image add to known images array
if (img.width + img.height) {
images[url] = images[url] || img;
}
if(!--x) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The call to done() needs to be outside the img.complete block.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are damn right, sorry, result of a too fast merge conflict resolution ;)

done();
}
}
};
img.src = url;
}
while (l--)
loadImage(imgs[l].getAttribute("src"));
loadImage(imgs[l].getAttribute("src"),imgs[l].width,imgs[l].height);
return x || done();
};
checkForFooter = function (elem, renderer, elementHandlers, callback) {
Expand Down