【问题标题】:wkhtmltopdf not working (pdfkit)wkhtmltopdf 不工作(pdfkit)
【发布时间】:2012-03-22 22:55:29
【问题描述】:

我无法从 html 页面生成 PDF。

我正在使用 PDFkit。我还按照安装说明安装了 wkhtmltopdf。在 'usr/local/bin/' 中现在有一个名为 'wkhtmltopdf' 的文件

当我使用 PDFkit 运行 pdf 时,它现在给出一个错误:

command failed: "/usr/local/bin/wkhtmltopdf" "--margin-right" "0.75in" "--page-size" "Letter" "--margin-top" "0.75in" "--margin-bottom" "0.75in" "--encoding" "UTF-8" "--margin-left" "0.75in" "--quiet" "-" "-"

另外,当我尝试直接生成 PDF 时,它会报错:

wkhtmltopdf --page-size A4--quiet http://localhost/invoices/22 -

'/usr/local/bin/wkhtmltopdf: cannot execute binary file'

知道这可能是什么吗? 这是 PDFkit 配置文件的外观:

PDFKit.configure do |config|
  config.wkhtmltopdf = '/usr/local/bin/wkhtmltopdf'
end

【问题讨论】:

  • 当我遇到类似的错误是因为我正在执行的帐户没有对 wkhtmltopdf 的执行权限。我最终在上面做了一个chmod
  • 我检查了权限,但它拥有所有用户的所有权限。
  • 似乎有些安装问题。您正在使用哪个版本的 WKHTMLTOPDF 以及在哪个操作系统中?
  • 我在 mac os x lion 上遇到了类似的问题。

标签: ruby-on-rails-3 wkhtmltopdf


【解决方案1】:

你必须像这样给出可执行文件的整个路径

路径应如下所示:C:/usr/local/bin/wkhtmltopdfwkhtmltopdf.exe

试试这个效果很好

【讨论】:

  • 这是mac或linux上的完整路径
  • 嗨@Piioo 我认为这是Windows路径
【解决方案2】:

我已经用自制软件在我的 Mac OSX 上安装了 wkhtmltopdf,我正在使用 wicked_pdf gem,我遇到了类似的错误。这可能会有所帮助:

在我的 rails 3 应用程序中,我有一个文件 app/config/initializers/wicked_pdf.rb 包含

# brew install wkhtmltopdf
WickedPdf.config = { :exe_path => '/usr/local/bin/wkhtmltopdf'} if Rails.env == 'development'

对我有用。所以你可能想试试:

PDFKit.configure do |config|
  config.wkhtmltopdf = { :exe_path => '/usr/local/bin/wkhtmltopdf' }
end

另外:查看 github 项目页面的安装说明:

https://github.com/mileszs/wicked_pdf

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-07-25
    • 1970-01-01
    • 2015-01-22
    • 1970-01-01
    • 2018-10-25
    • 2017-07-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多