如何解决pdfkit 没有在网页中获取嵌入的图像
我正在尝试使用 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。 另外,这是我个人使用的。
解决方法
问题不在于不正确的 sRGB 配置文件。只是网站没有足够的时间来加载图像。可以通过增加传递给 javascript-delay
pdfkit.from_url
来解决此问题
pdfkit_options = {
'javascript-delay': '10000',# Increase this value if images are not loading properly
}
pdfkit.from_url(url,output_path,options=pdfkit_options)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。