Pdfmake: Getting Uncaught (in promise): invalid image, images dictionary should contain dataURL entries (or local file paths in node.js) while using it with angular2

Created on 12 Jul 2017  路  2Comments  路  Source: bpampuch/pdfmake

I'm trying to generate pdf in my angular2 app, which contains dynamic data and images from APIs.

createPdf(): void {
    html2canvas(document.getElementById('main'), {
        onrendered: function (canvas) {
            var data = canvas.toDataURL();
            var docDefinition = {
                content: [{
                    image: data,
                    width: 763,
                }]
            };
            pdfMake.createPdf(docDefinition).download("web.pdf");
        }
    });

Getting this error
EXCEPTION: Uncaught (in promise): invalid image, images dictionary should contain dataURL entries (or local file paths in node.js)

if I console.log(canvas) I get <canvas width="1366" height="0">
as It has dynamic data, height can't be fixed.
Can you please help me out here?

Most helpful comment

Added <canvas></canvas> at the end of ther component.html and it worked.
I think it was having problem with finding canvas image

All 2 comments

Added <canvas></canvas> at the end of ther component.html and it worked.
I think it was having problem with finding canvas image

i m getting the same error and unable to find where to add .

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MathLavallee picture MathLavallee  路  3Comments

dmatesic picture dmatesic  路  3Comments

kamilkp picture kamilkp  路  3Comments

qgliu picture qgliu  路  3Comments

michaelqiji picture michaelqiji  路  3Comments