【问题标题】:insert binary img as html to pdf with node html-pdf使用节点html-pdf将二进制图像作为html插入pdf
【发布时间】:2019-08-01 22:32:25
【问题描述】:

我尝试将二进制图像插入 html 以使用节点模块 html-pdf 从 html doc 生成 PDF。

根据其他问题,我尝试了以下代码:

const pictureHtml = `<img src="data:image/png;base64","${binaryPicture}">`;

图片以二进制数据类型存储在mongoDB中。

如果无法使用模块 html-pdf,您能否推荐一个不同的模块?

【问题讨论】:

    标签: node.js pdf binary html-pdf


    【解决方案1】:

    img src 必须是base64string。我们需要将 binaryPicture 转换为 base64string 。我们有这样的代码

    var base64data = Buffer.from(binaryPicture, 'binary').toString('base64');
    const pictureHtml = `<img src="data:image/png;base64","${base64data}">`;
    

    【讨论】:

    • 非常感谢,一旦我被允许,我会尽快投票给你的答案:)
    • 我稍微更改了代码以使其工作: const base64data = Buffer.from(binaryPicture, 'binary').toString('base64');常量图片Html = &lt;img src="data:image/jpeg;base64,${base64data}"&gt;;
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-19
    • 2014-08-28
    • 1970-01-01
    • 2016-05-22
    相关资源
    最近更新 更多