【问题标题】:WKHTMLTOPDF path in ROR applicationROR 应用程序中的 WKHTMLTOPDF 路径
【发布时间】:2015-04-18 09:44:14
【问题描述】:

我正在使用 wicked_pdf gem 进行 HTML 到 PDF 的转换。根据 Github 中的描述,我正确安装了所有内容。但我遇到了运行时错误 -

RuntimeError(错误的 wkhtmltopdf 路径:/usr/local/bin/wkhtmltopdf): app/controllers/orders_controller.rb:46:in `create

`44 @count = Item.count(:qty)
45  @temp = Item.where(:received => true).count()
46  render  :pdf => "Bill" ,
47  :template => 'orders/create.pdf.erb', # Excluding ".pdf" extension.
48  page_height:  100,
49  page_width:   80`

并且 wkhtmltopdf 安装在我的系统中的 /usr/local/bin/wkhtmltopdf

指定wkhtmltopdf的路径应该是已经安装的地方。

我无法弄清楚问题所在。

【问题讨论】:

    标签: ruby-on-rails wkhtmltopdf


    【解决方案1】:

    在 wkhtmltopdf 的源代码中,看起来它所做的只是运行 File.exists?在那条路上:

    https://github.com/mileszs/wicked_pdf/blob/56aa1a195d65eaaf33fbd0254e1e7df99ce1fd1c/lib/wicked_pdf.rb#L41

    所以我们必须仔细检查 wkhtmltopdf 是否正确安装在 /usr/local/bin/wkhtmltopdf 的假设

    您能提供更多信息吗?只是为了验证一下,which wkhtmltopdf 的输出是什么

    当您在控制台中运行wkhtmltopdf -V 时,您会得到什么?

    您可以尝试在配置中指定路径(在 wkhtmltopdf 自述文件中提到的初始化程序中),看看这是否也会产生影响。

    最后,您可以将可执行文件移动到不同的目录,然后在初始化程序中指定它以查看它是否可能与文件夹权限有关。

    【讨论】:

    • wkhtmltopdf 的输出是 - /usr/local/bin/wkhtmltopdf 和 wkhtmltopdf -V 的输出是 wkhtmltopdf 0.9.6
    • 嗯,我和你一样困惑。我认为作为最后一次调试尝试,您可以尝试明确指定路径和/或将可执行文件移动到其他位置。
    【解决方案2】:

    您是否尝试过在初始化程序中指定路径? ({rails.root}/config/initializers/wicked_pdf.rb) ex..

    WICKED_PDF = {
        :exe_path => '/usr/local/bin/wkhtmltopdf-amd64'#should be whatever your version is called
    }
    

    【讨论】:

      【解决方案3】:

      wkhtmltopdf 将安装到 /usr/bin/wkhtmltopdf,但预计安装在 /usr/local/bin/wkhtmltopdf

      要修复它,只需创建符号链接(可能需要使用 sudo):

      ln -s /usr/bin/wkhtmltopdf /usr/local/bin/wkhtmltopdf

      【讨论】:

        【解决方案4】:

        我遇到了类似的问题。尝试重新安装 gem 并安装库以支持该 gem。 以下是在 mac 和 ubuntu 中安装该库的链接:

        unable to install wkhtmltopdf with patched qt in ubuntu 16.04

        http://macappstore.org/wkhtmltopdf/

        【讨论】:

          猜你喜欢
          • 2012-02-26
          • 2015-08-19
          • 1970-01-01
          • 2020-04-30
          • 1970-01-01
          • 1970-01-01
          • 2013-08-06
          • 1970-01-01
          相关资源
          最近更新 更多