wkhtmltopdf 命令失败
我正在尝试使用 wkhtmltopdf
将 HTML 文件转换为 PDF。
为此,我在 Debian 机器上安装了 wkhtmltopdf 并尝试运行此命令:
/usr/bin/xvfb-run -a -s "-screen 0 640x480x16" wkhtmltopdf /path/convert.1303714349.4961.html.tmp /path/convert.1303714349.4961.pdf.tmp
我收到以下错误:
Loading page (1/2)
Error: Failed loading page file:///path/convert.1303714349.4961.html.tmp (sometimes it will work just to ignore this error with --ignore-load-errors)
该文件确实存在于 /path/convert.1303714349.4961.html.tmp
中,并且权限设置正确。它与前面带有 file://
的路径有什么关系吗?
I am trying to convert a HTML file to PDF using wkhtmltopdf
.
For that purpose I have installed wkhtmltopdf on a Debian box and am trying to run this command:
/usr/bin/xvfb-run -a -s "-screen 0 640x480x16" wkhtmltopdf /path/convert.1303714349.4961.html.tmp /path/convert.1303714349.4961.pdf.tmp
I get the following error:
Loading page (1/2)
Error: Failed loading page file:///path/convert.1303714349.4961.html.tmp (sometimes it will work just to ignore this error with --ignore-load-errors)
The file does exist in /path/convert.1303714349.4961.html.tmp
, and the permissions are set correctly. Can it have anything to do with the path being prepended with file://
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我相信
wkhtmtopdf
不处理具有非典型扩展名的本地文件。尝试将输入文件重命名为*.html
。请参阅 https://web.archive.org/web/20131124022426/http://code.google.com/p/wkhtmltopdf/issues/detail?id=486。
I believe
wkhtmtopdf
does not handle local files with non-typical extensions. Try renaming the input file to*.html
.See issue and comments at https://web.archive.org/web/20131124022426/http://code.google.com/p/wkhtmltopdf/issues/detail?id=486.
另一个有用的提示是用“_”等字符替换文件名中的空格,因为当文件名包含空格时,进程加载页面失败
Another useful tip is to replace the spaces in the filename by some char like "_", because of when the filename has spaces the process fails loading page
您的问题是由文件系统、
xvfb-run
wkhtmltopdf
和无头 X11 服务器之间的用户权限协商引起的。用户运行此命令:
wkhtmltopdf 会产生警告:
目标 PDF 文件不存在、缺少 somefile.html 的内容或者为空。
如何重现问题,sscce:
条件:
somehtml.html 中的违规 HTML:
位于用户目录中并运行
wkhtmltopdf 产生警告
/home/user/preview.pdf 丢失或为空。
导致问题的原因:
您的
xvfb-run
将wkhtmlpdf
限制给用户,并且无权读取和/或写入/home/user/somehtml .pdf
或/home/user/preview.pdf
要查看这是否是您的问题,请询问
xvfb-run
我们拥有什么样的权限?解决方法:
/tmp
通常比 /home/user/ 具有更宽松的权限,因此在 /tmp 内完成所有工作并且您应该得到此标准输出:
和 Preview.pdf
为什么 wkhtmltopdf 不更聪明并为我处理这个问题?
这比看起来更难,因为 wkhtmltopdf 必须与敌对的第 3 方专有 PDF 渲染软件(由 adobe 制造?)抗衡,并且他们与浏览器开发人员合作来混淆并使其难以访问他们的引擎,因为许多大公司都靠他们的钱他们的绝密源代码。 wkhtmltopdf 正在进入这个世界,以便开源人员无需在高层办公楼中支付现金即可拥有它。这就是为什么 adobe 向浏览器开发者付钱让我们很难做到这一点。我们正在稀释他们的利润机制,因此他们会尽可能地向我们抛出停止棒来进行报复。就是这样。我们在世界范围内向新手传播得越多,第三者就越难阻止,因为你正在阻止其他人获利。
Your trouble is caused by the negotiation of user permission between the filesystem,
xvfb-run
wkhtmltopdf
and headless X11 server.The User runs this command:
wkhtmltopdf produces a Warning:
The target PDF file doesn't exist, has missing content from somefile.html or is blank.
How to reproduce the problem, an sscce:
Conditions:
The offending HTML in somehtml.html:
Be in a user's directory and run
wkhtmltopdf produces a warning
/home/user/preview.pdf is missing or blank.
What is causing the problem:
Your
xvfb-run
jailswkhtmlpdf
to the user and doesn't have permission to read and or write to/home/user/somehtml.pdf
or/home/user/preview.pdf
To see if this is your problem, ask
xvfb-run
what kind of permissions we have?Workaround:
/tmp
typically has looser permissions than /home/user/, so do all your work inside /tmpAnd you should get this stdout:
And preview.pdf
Why is not wkhtmltopdf smarter and handling this problem for me?
This is harder than it looks, because wkhtmltopdf has to contend with hostile 3rd party proprietary PDF rendering software (made by adobe?) and they work in concert with browser developers to obfuscate and make access to their engines hard because many large corporations by them money for their top secret source code. wkhtmltopdf is pricking into that world so that open source people can have it without paying suits in tall office buildings cash money. That's why adobe pay money to developers of browsers to make this hard for us. We are diluting their profit mechanism, so they retaliate by throwing stop sticks at us where they can. This is that. The more we spreads this round the world to novices, the harder the 3rd party throws stop sticks, since you are preventing profit in others.
我的 Windows 7 机器上的“file://”路径没有遇到任何问题。
您是否尝试过错误消息
--igonore-load-errors
中的建议?I haven't had any problem with "file://" paths on my Windows 7 box.
Did you try the advice in the error message,
--igonore-load-errors
?