我在 nodeJS 中使用 api pdfmake 生成 pdf 文件 http://pdfmake.org/#/但我不知道如何将图像添加到文档中,并且总是出现以下错误
error invalid image, images dictionary should contain dataURL entries (or local file paths in node.js)
这就是我添加图像的方式,它存在于代码的同一文件夹中:
body: [
[{ rowSpan: 2, image: 'data:aa/png' }, 'Capteur', '', 'image', 'image', 'image'],
['', 'Health', '', 'Proximite', 'Lumiere', 'Geroscope'],
]
我需要一些帮助,谢谢。
最佳答案
在您的示例中,您没有指定有效的 base64
编码字符串。
您需要将其更改为正确的 base64 编码字符串(请注意,您可以使用例如 this website 将 png
转换为 base64
编码字符串,或者让 Node 像他们一样进行转换 in this issue ):
const pdfDefinition = {
content: [
{ rowSpan: 2, image:'data:image/png;base64,<put-your-base64-string-here>'}
]
}
另请注意,目前仅支持 JPEG 和 PNG 图像。
关于node.js - NodeJS Pdfmake 如何添加图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62499131/