【问题标题】:pdfkit image not embedded using Djangopdfkit 图像未使用 Django 嵌入
【发布时间】:2020-03-09 13:10:25
【问题描述】:

我正在使用 Django 和 this solution 将受保护的网页转换为 pdf。

该解决方案效果很好,除了网页包含未显示在 pdf 中的图像并且我收到错误的部分

Warning: Failed to load file:///media/images/main/logo.jpg (ignore)

我目前使用的from_string方法如下

pdfkit.from_string(msg_html, 'testing123.pdf') #msg_html contains html string with images

【问题讨论】:

    标签: python django pdfkit


    【解决方案1】:

    原来需要使用 pdfkit 转换为 pdf 的 html 文档中的图像 url 需要有一个绝对 url

    在我的 html 文件中,我必须按如下方式更新我的网址:

    <img src="/media/images/main/logo.jpg">
    

    <img src="https://test.mywebsite.com/media/images/main/logo.jpg">
    

    使用这个我能够从 html 文件中生成包含我的徽标的 pdf

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-11
      • 2014-04-15
      • 1970-01-01
      • 2018-02-23
      • 2023-03-02
      • 1970-01-01
      • 2014-12-02
      • 2018-09-30
      相关资源
      最近更新 更多