【发布时间】:2022-08-17 01:04:27
【问题描述】:
这是我的代码
options = {
\"enable-local-file-access\": True,
...
}
pdfkit.from_string(html_file, pdf_file, options=options, ...)
因为我使用 Django 模板,所以这是我的代码来引用它
<img src=\"{{ static_root }}{% static \'../../target.svg\' %}\" alt=\"\">
我在 html 中使用本地图像文件,它只是在 pdf 输出文件中显示一个空白框
我还尝试使用 \"base64\" 来解决我的问题,基于此链接pdfkit not converting image to pdf
它对我真的不起作用。
-
django 为浏览器生成带有 URL 的 HTML,它可以向服务器请求图像。但是
pdfkit像普通程序一样工作,不能向服务器发送图像请求,我宁愿使用普通路径/full/path/to/file -
It doesn\'t really work to me.是无用的信息。你运行的时候有没有报错?你如何使用base64?更好地显示您的代码。 -
嘿嘿,谢谢大家回答我的问题。我意识到在这种情况下我不能使用 .svg 格式的图像,而且我不知道究竟是为什么,但是 .png 对我来说非常有效,这解决了我的问题。
-
当你在 django 中使用 PNG 时,你有这个问题吗?
-
我记得
PDF是在SVG发明之前发明的,也许PDF这种格式有问题。或pdfkit对此格式有疑问。
标签: python django wkhtmltopdf pdfkit python-pdfkit