NodeJS Pdfmake 如何添加图像
NodeJS Pdfmake how to add an image
我在 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 to convert your png
to a base64
-encoded string or you let node do the conversion as they did in this issue):
const pdfDefinition = {
content: [
{ rowSpan: 2, image:'data:image/png;base64,<put-your-base64-string-here>'}
]
}
另请注意,目前仅支持 JPEG 和 PNG 图像。
我在 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 to convert your png
to a base64
-encoded string or you let node do the conversion as they did in this issue):
const pdfDefinition = {
content: [
{ rowSpan: 2, image:'data:image/png;base64,<put-your-base64-string-here>'}
]
}
另请注意,目前仅支持 JPEG 和 PNG 图像。