Reputation: 81
Using html2canvas and pdfmake to export HTML to a PDF file. Doing this in an AngularJS framework.
The problem I am having, images in the HTML are not shown in the PDF file. data
does contain a base64 string, but when I decode this there are no images (only the table and text I wrote). What am I doing wrong here?
html2canvas($("#pdfFileToExport"), {
onrendered: function (canvas) {
var data = canvas.toDataURL();
var docDefinition = {
content: [{
image: data,
width: 500
}]
};
pdfMake.createPdf(docDefinition).download("fileName.pdf");
}
});
Upvotes: 0
Views: 1878
Reputation: 11
What is the url of the image? Is it from another host other then where your app is running? By default html2canvas blocks cross origin images. You can override this with the "proxy" option however I think chrome will still block cross origin images. The best bet is to make sure you have the same origin for your image as used by the page.
See the "Limitations" section here: http://html2canvas.hertzen.com/documentation
Upvotes: 1