Permalink
Browse files

Merge pull request #267 from woolfg/dataurl

support of dataurl images
  • Loading branch information...
2 parents fcb97f4 + 029b96a commit c8ea94bd57dd6c353a23c3d8b25e49cf05f5dd1c @diegocr diegocr committed May 25, 2014
Showing with 19 additions and 5 deletions.
  1. +3 −0 jspdf.plugin.addimage.js
  2. +16 −5 jspdf.plugin.from_html.js
@@ -174,6 +174,9 @@
if(element.nodeName === 'CANVAS') {
var canvas = element;
+ //if element is an image which uses data url defintion, just return the dataurl
+ } else if (element.nodeName === 'IMG' && element.getAttribute('src') && element.getAttribute('src').indexOf('data:image/') === 0) {
+ return element.getAttribute('src');
} else {
var canvas = document.createElement('canvas');
canvas.width = element.clientWidth || element.width;
@@ -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)
+ 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) {
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) {

0 comments on commit c8ea94b

Please sign in to comment.