【问题标题】:pdfkit not getting embedded images in a webpagepdfkit没有在网页中嵌入图像
【发布时间】:2021-08-11 05:30:54
【问题描述】:

我正在尝试使用 pdfkit 将网页另存为 pdf。但是,在保存的 PDF 中,没有图像。它们都有一个问号图标代替图像。为什么会这样?有可能解决这个问题吗?

例如,如下:

import pdfkit

pdfkit.from_url('https://www.quora.com/Spoilers-What-is-something-you-noticed-in-Avengers-Endgame-that-you-believe-others-have-missed/answer/Prabhhav-Sharma?ch=3&share=5feaef03&srid=aHe5', 'output.pdf')

我收到以下警告。可能是这个问题。

libpng warning: iCCP: known incorrect sRGB profile

我在网上找到的解决方案是修改 png 文件,因为 pdfkit 正在从网页加载图像,所以我在这里无法这样做。有没有办法解决这个问题?

PS:我愿意使用任何其他实用程序从网页 URL 保存 PDF。 另外,这是我个人使用的。

【问题讨论】:

    标签: python pdf pdf-generation wkhtmltopdf pdfkit


    【解决方案1】:

    问题不在于 sRGB 配置文件不正确。只是网站没有足够的时间来加载图像。这个问题可以通过增加传递给pdfkit.from_url的选项中的javascript-delay来解决

    pdfkit_options = {
        'javascript-delay': '10000',  # Increase this value if images are not loading properly
    }
    pdfkit.from_url(url, output_path, options=pdfkit_options)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-11-29
      • 2016-11-14
      • 2012-02-27
      • 2023-03-24
      • 2017-02-03
      • 2015-02-23
      • 1970-01-01
      相关资源
      最近更新 更多