Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

support of dataurl images

  • Loading branch information...
commit fb3c7df1a4e26e19464cb73ef8238709f8245f47 1 parent 157527d
@woolfg woolfg authored
Showing with 20 additions and 6 deletions.
  1. +3 −0  jspdf.plugin.addimage.js
  2. +17 −6 jspdf.plugin.from_html.js
View
3  jspdf.plugin.addimage.js
@@ -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) {
+ return element.getAttribute('src');
} else {
var canvas = document.createElement('canvas');
canvas.width = element.clientWidth || element.width;
View
23 jspdf.plugin.from_html.js
@@ -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) {
+ 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) {
Please sign in to comment.
Something went wrong with that request. Please try again.