Rails:wkhtmltopdf RuntimeError(wkhtmltopdf 的位置未知)

发布于 2024-12-09 08:08:51 字数 363 浏览 1 评论 0原文

我正在使用 Ubuntu 11.04 在 Ruby on Rails 中开发应用程序。 在应用程序中我需要生成pdf文档。所以我正在使用 wicked_pdf 和 wkhtmltopdf-binary gems。

在我的系统的开发环境中一切工作正常。 但是一旦我使用 Phusion 在 CentOS 5.6 上将应用程序部署到生产环境中 乘客,当我尝试动态生成 pdf 时,出现以下错误:

RuntimeError (Location of wkhtmltopdf Unknown)

我正在使用 Ruby1.9.2.p136 Rails 3.1.1

任何帮助将不胜感激......谢谢。

I am using Ubuntu 11.04 to develop an app in Ruby on Rails.
In the app I need to generate pdf documents. So I am using
the wicked_pdf and wkhtmltopdf-binary gems.

In the development environment in my system everything is working fine.
But once I deployed the app in production on CentOS 5.6 using Phusion
Passenger, when I try to generate pdfs on the fly its giving me the following error:

RuntimeError (Location of wkhtmltopdf unknown)

I am using Ruby1.9.2.p136
Rails 3.1.1

Any help will be much appreciated....Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

夜访吸血鬼 2024-12-16 08:08:51

另一种方法是通过 Gemfile 安装二进制文件。

只需将以下行添加到您的生产组:

gem 'wkhtmltopdf-binary'

这应该添加对 linux-i386、amd64 和 darwin 的二进制支持。

然后

bundle install --without development test

在生产环境中运行安装gem。之后,您只需重新启动服务器即可。

就这样。

我希望这有帮助

An alternative is to install the binary via the Gemfile.

Just add the following line to your production group:

gem 'wkhtmltopdf-binary'

That should add binary support for linux-i386, amd64, and darwin.

And then run

bundle install --without development test

to install the gem in a production environment. After which, you just restart your server.

That's all.

I hope this helps

第几種人 2024-12-16 08:08:51

你使用静态 wkhtmltopdf 二进制文件吗?我在此处下载了它,并将其提取到/path/to/rails_app /bin

并将其添加到 Rails 中,如下所示:

#config/initializers/wicked_pdf.rb
WickedPdf.config = {
  :exe_path => Rails.root.join('bin', 'wkhtmltopdf-i386').to_s,
}

do you use static wkhtmltopdf binary? i downloaded it here and extraced it to /path/to/rails_app/bin

and add it to rails like this:

#config/initializers/wicked_pdf.rb
WickedPdf.config = {
  :exe_path => Rails.root.join('bin', 'wkhtmltopdf-i386').to_s,
}
梦境 2024-12-16 08:08:51

对于 mac os - x 你应该通过 homebrew 安装 wkhtmltopdf

$ brew tap homebrew/boneyard # the wkhtmltopdf formula is now inactive but still available in the boneyard repository 
$ brew install wkhtmltopdf

for mac os - x you should install wkhtmltopdf by homebrew

$ brew tap homebrew/boneyard # the wkhtmltopdf formula is now inactive but still available in the boneyard repository 
$ brew install wkhtmltopdf
惜醉颜 2024-12-16 08:08:51

OS X Yosemite 解决方案

要使其在 Mac OS X 10.10 (Yosemite) 上运行,请安装 wkhtmltopdf-binary gem,然后将其放入 config/initializers 中/wicked_pdf.rb:

module WickedPdfHelper
  if Rails.env.development?
    if RbConfig::CONFIG['host_os'] =~ /linux/
      executable = RbConfig::CONFIG['host_cpu'] == 'x86_64' ? 'wkhtmltopdf_linux_x64' : 'wkhtmltopdf_linux_386'
    elsif RbConfig::CONFIG['host_os'] =~ /darwin/
      executable = 'wkhtmltopdf_darwin_386'
    else
      raise 'Invalid platform. Must be running linux or intel-based Mac OS.'
    end

    WickedPdf.config = { exe_path: "#{Gem.bin_path('wkhtmltopdf-binary').match(/(.+)\/.+/).captures.first}/#{executable}" }
  end
end

Ps.: 这个解决方案也适用于 Linux。

Solution for OS X Yosemite

To get it working on Mac OS X 10.10 (Yosemite), install the wkhtmltopdf-binary gem and then put it in your config/initializers/wicked_pdf.rb:

module WickedPdfHelper
  if Rails.env.development?
    if RbConfig::CONFIG['host_os'] =~ /linux/
      executable = RbConfig::CONFIG['host_cpu'] == 'x86_64' ? 'wkhtmltopdf_linux_x64' : 'wkhtmltopdf_linux_386'
    elsif RbConfig::CONFIG['host_os'] =~ /darwin/
      executable = 'wkhtmltopdf_darwin_386'
    else
      raise 'Invalid platform. Must be running linux or intel-based Mac OS.'
    end

    WickedPdf.config = { exe_path: "#{Gem.bin_path('wkhtmltopdf-binary').match(/(.+)\/.+/).captures.first}/#{executable}" }
  end
end

Ps.: This solution will work on Linux too.

瀟灑尐姊 2024-12-16 08:08:51

MAC OSX:

brew install wkhtmltopdf

这将让您安装

brew install Caskroom/cask/wkhtmltopdf

config/initializers/wicked_pdf.rb

WickedPdf.config = {
  exe_path: '/usr/local/bin/wkhtmltopdf'
}

MAC OSX:

brew install wkhtmltopdf

this will let you to install

brew install Caskroom/cask/wkhtmltopdf

then in config/initializers/wicked_pdf.rb

WickedPdf.config = {
  exe_path: '/usr/local/bin/wkhtmltopdf'
}
故人的歌 2024-12-16 08:08:51

刚刚有类似的问题。

正如自述文件中所述,我使用以下命令创建了一个初始化程序:

WickedPdf.config = {
  exe_path: '/usr/local/bin/wkhtmltopdf'
}

Just had a similar problem.

As stated in readme, I created an initializer with:

WickedPdf.config = {
  exe_path: '/usr/local/bin/wkhtmltopdf'
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文