无法让 wicked_pdf 在 heroku 上工作? (但它在本地有效)

发布于 2024-11-08 20:19:08 字数 1175 浏览 3 评论 0原文

遵循 https://github.com/jordan-brough/heroku-pdf 上的指南我设法让 wicked_pdf 在本地工作并按预期创建 PDF。 然而,一旦我推送到heroku,每次我调用pdf时,应用程序都会在一段时间后崩溃

日志给了我这样的信息:

2011-05-19T06:36:56+00:00 app[web.1]: Started GET "/authors/cash_payment_receipt/4dd4aff0a2d5a5000100000c.pdf" for XXX.XXX.XXX.XXX at Wed May 18 23:36:56 -0700 2011
2011-05-19T06:36:56+00:00 heroku[router]: Error H13 (Connection closed without response) -> GET xxx.xxxx.com/authors/cash_payment_receipt/4dd4aff0a2d5a5000100000c.pdf dyno=web.1 queue=0 wait=0ms service=0ms bytes=0
2011-05-19T06:36:56+00:00 app[web.1]: !! Unexpected error while processing request: PDF could not be generated!
2011-05-19T06:36:56+00:00 app[web.1]: /app/.bundle/gems/ruby/1.8/gems/wkhtmltopdf-0.1.2/bin/wkhtmltopdf_linux_386: error while loading shared libraries: libfontconfig.so.1: cannot open shared object file: No such file or directory

我将wkhtmltopdf bin添加到我的rails-root/bin目录中,检查了权限,一切正常。我首先尝试了 0.10rc2,然后又降回 0.9.9,但结果都相同。

我在谷歌上找不到与我的错误相关的任何内容。我不明白我做错了什么。

环境是: - 导轨 3.0.7 - ruby​​ 1.8.7

谢谢,

艾尔

Following the guide on https://github.com/jordan-brough/heroku-pdf I managed to have wicked_pdf working locally and creating PDF as expected.
However once I push to heroku, the app crashes after a while everytime I call the pdf

The logs gives me this:

2011-05-19T06:36:56+00:00 app[web.1]: Started GET "/authors/cash_payment_receipt/4dd4aff0a2d5a5000100000c.pdf" for XXX.XXX.XXX.XXX at Wed May 18 23:36:56 -0700 2011
2011-05-19T06:36:56+00:00 heroku[router]: Error H13 (Connection closed without response) -> GET xxx.xxxx.com/authors/cash_payment_receipt/4dd4aff0a2d5a5000100000c.pdf dyno=web.1 queue=0 wait=0ms service=0ms bytes=0
2011-05-19T06:36:56+00:00 app[web.1]: !! Unexpected error while processing request: PDF could not be generated!
2011-05-19T06:36:56+00:00 app[web.1]: /app/.bundle/gems/ruby/1.8/gems/wkhtmltopdf-0.1.2/bin/wkhtmltopdf_linux_386: error while loading shared libraries: libfontconfig.so.1: cannot open shared object file: No such file or directory

I added the wkhtmltopdf bin to my rails-root/bin directory, checked the rights, and it's all ok. I first tried the 0.10rc2 and moved back down to 0.9.9 but it all gives the same results.

I can't find anything on google related to my error. I don't see what I am doing wrong.

The env is:
- rails 3.0.7
- ruby 1.8.7

Thanks,

Ale

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

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

发布评论

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

评论(6

终陌 2024-11-15 20:19:08

我最近为 wkhtmltopdf 二进制文件创建了一个 GEM,以便在 heroku 上工作,而无需在您自己的存储库中安装任何二进制文件。它还包含用于开发的 OSX (darwin) 二进制文件。它与 PDFKit 一起工作,可能也应该与 WickedPDF 一起工作

https://github.com/bradphelan/wkhtmltopdf-heroku

,或者在你的 Gemfile 中

gem "wkhtmltopdf-heroku"

I recently created a GEM for the wkhtmltopdf binaries to work on heroku without you having to install any binaries in your own repository. It also comes packed with the OSX ( darwin ) binary for development. It worked with PDFKit and probably should work with WickedPDF as well

https://github.com/bradphelan/wkhtmltopdf-heroku

or in your Gemfile as

gem "wkhtmltopdf-heroku"
无名指的心愿 2024-11-15 20:19:08

这个 github 项目对我来说非常有帮助,我让它在 Rails 3 项目中运行,这要归功于这

this github project was immensely helpful for me, I have it running in rails 3 projects thanks to this

何止钟意 2024-11-15 20:19:08

我能够按照此处描述的步骤 https://github.com/jordan-brough/heroku- pdf 制作我自己的项目副本,它在本地和 Heroku 上运行良好。

然后我更新了应用程序以使用 Rails 3.0.9。它在heroku http://heroku-pdf-3.heroku.com/ 上运行。您可以从此处获取该项目的代码。

I was able to follow the steps described here https://github.com/jordan-brough/heroku-pdf to make my own copy of the project and it worked fine locally and on heroku.

I then updated the application to work with rails 3.0.9. It is running on heroku http://heroku-pdf-3.heroku.com/. You can grab my code from here for this project.

演多会厌 2024-11-15 20:19:08

作为记录,我经历过这在我们的 stage env 上完美运行(相同的 heroku 设置),但部署到生产可能会因上述错误而中断(但并非总是如此)。

发生这种情况时,重新部署会起作用(不知道为什么)。由于它是一个 git 存储库,因此您必须进行微小的更改,否则它将不允许您再次推送。

For the record, I've experienced where this works perfectly on our stage env (same heroku setup), but a deploy to production can break with the error above (but not always).

When this happens, a re-deploy worked (no idea why). Since it's a git repo, you'll have to make a minor change, otherwise it won't allow you to push again.

家住魔仙堡 2024-11-15 20:19:08

wicked_pdf 使用 wkhtmltopdf 将 HTML 转换为 PDF(正如名称所示)。您可以在此处下载其二进制文件,并将其放入您的应用 bin 中文件夹。

您还需要创建一个指向二进制文件的 wicked_pdf.rb 初始值设定项:

# config/initializers/wicked_pdf.rb

WickedPdf.config = {
  :exe_path => Rails.root.join('bin', 'wkhtmltopdf-amd64').to_s,
}

但是,如果您需要将图像输入到 PDF 文件中,则需要运行 X 服务器。由于您无法在 Heroku 中运行 X 服务器,因此有两种解决方法:

  • 使用 xvfb 将 wkhtmltopdf 二进制文件包装在虚拟 X 服务器环境中
  • 在另一台服务器中安装 HTML 到 PDF 提供程序具有更大的灵活性,例如 RackSpace 或 Amazon EC2 中的 VPS。

我更喜欢第二个选项,因为它分离了另一台服务器中的 PDF 创建,并且不会因性能问题而影响应用程序的其余部分。

您可以在此处查看如何执行此操作: http://blog.hugerepo.com/2013/04/29/how-to-create-your-own-html-to-pdf-provider/

The wicked_pdf uses wkhtmltopdf to convert HTML to PDF (as the name obviously states). You can download its binary here, and place it in your apps bin folder.

You also need to create a wicked_pdf.rb initializer pointing to the binary:

# config/initializers/wicked_pdf.rb

WickedPdf.config = {
  :exe_path => Rails.root.join('bin', 'wkhtmltopdf-amd64').to_s,
}

However, if you need to input images into your PDF files, you'll need a X server running. Since you can't run a X server in Heroku, there are two ways out:

  • Use xvfb to wrap your wkhtmltopdf binary within a virtual X server environment
  • Install a HTML to PDF provider in another server, where you have more flexibility, such as a VPS in RackSpace or Amazon EC2.

I prefer the second option, since it detachs PDF creation in another server and does not compromises the rest of the application with performance issues.

You can see how to do that here: http://blog.hugerepo.com/2013/04/29/how-to-create-your-own-html-to-pdf-provider/

请帮我爱他 2024-11-15 20:19:08

我也有同样的问题。我通过使用 wkhtmltopdf 二进制文件的 amd64 版本而不是 i386 来修复它。

I had the same problem. I fixed it by using the amd64 build of wkhtmltopdf binary instead of the i386.

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