我正在尝试使用 pdfMake pdf engine 在我的应用程序中将一些报告下载为 pdf 格式我添加了一个 jpg Logo 图像,
var logoImg = 'sampleImage.jpg';
var logoImage = "http://upload.wikimedia.org/wikipedia/en/a/a9/Example.jpg";
if (logoImage) {
var img = new Image();
img.setAttribute('crossOrigin', 'anonymous');
img.src = logoImage;
var canvas = document.createElement("canvas");
canvas.width = img.width;
canvas.height = img.width;
var ctx = canvas.getContext("2d");
ctx.drawImage(img, 0, 0);
logoImg = canvas.toDataURL("image/png");
}
在 this fiddle 中给出.但是当我使用自定义图像时,它会在第一次单击下载按钮时出现 Uncaught TypeError: Cannot read property 'embed' of undefined 错误(检查控制台)。当我再次运行 ode 时,pdf 将正确下载。那么如何解决Uncaught TypeError错误呢?
编辑:如果我按照 this fiddle 中给出的直接给出图像的数据 url,它将正常工作.但我想根据上面第一个 fiddle 中给出的图像链接动态传递 dataurl。
最佳答案
我可以通过提供 Base64 格式的图像来解决“Uncaught TypeError: Cannot read property 'embed' of undefined”。
我找到了解决方案 here .
有关 PDFMake 和图像的更多信息,这里是 documentation .
关于javascript - "Uncaught TypeError: Cannot read property ' 在pdfMake pdf引擎中使用自定义图像时嵌入' of undefined",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27989026/