在heroku上实现wicked pdf时出现问题
我正在使用本指南在heroku上集成wicked_pdf。但不知怎的,它似乎不起作用。我从 Heroku 获取日志,上面写着:
Processing PdfController#get_pdf to pdf (for 115.248.175.50 at 2011-02-15 23:54:44) [GET]
Parameters: {"format"=>"pdf", "action"=>"get_pdf", "id"=>"1", "controller"=>"pdf"}
***************WICKED***************
Rendering pdf/get_pdf
RuntimeError (PDF could not be generated!
/usr/ruby1.8.7/lib/ruby/1.8/open3.rb:73:in `exec': No such file or directory - /app/fa369291-829b-4b61-9efe-b2f0d0a0a42c/home/bin/wkhtmltopdf-amd64 - - (Errno::ENOENT)
from /usr/ruby1.8.7/lib/ruby/1.8/open3.rb:73:in `popen3'
from /usr/ruby1.8.7/lib/ruby/1.8/open3.rb:59:in `fork'
from /usr/ruby1.8.7/lib/ruby/1.8/open3.rb:59:in `popen3'
from /usr/ruby1.8.7/lib/ruby/1.8/open3.rb:57:in `fork'
from /usr/ruby1.8.7/lib/ruby/1.8/open3.rb:57:in `popen3'
from /app/fa369291-829b-4b61-9efe-b2f0d0a0a42c/home/vendor/plugins/wicked_pdf/lib/wicked_pdf.rb:22:in `pdf_from_string'
from /app/fa369291-829b-4b61-9efe-b2f0d0a0a42c/home/vendor/plugins/wicked_pdf/lib/pdf_helper.rb:28:in `make_pdf'
from /app/fa369291-829b-4b61-9efe-b2f0d0a0a42c/home/vendor/plugins/wicked_pdf/lib/pdf_helper.rb:39:in `make_and_send_pdf'
from /app/fa369291-829b-4b61-9efe-b2f0d0a0a42c/home/vendor/plugins/wicked_pdf/lib/pdf_helper.rb:13:in `render'
from /app/fa369291-829b-4b61-9efe-b2f0d0a0a42c/home/app/controllers/schedule_controller.rb:33:in `get_pdf'
请帮忙。提前致谢。
编辑:
我在代码中做了一些更改,并解决了这个错误,但仍然卡在这里
NoMethodError (未定义的方法为空? for #
I am using this guide for integrating wicked_pdf on heroku. But somehow it doesn't seem to work. I got the logs from heroku and its says this:
Processing PdfController#get_pdf to pdf (for 115.248.175.50 at 2011-02-15 23:54:44) [GET]
Parameters: {"format"=>"pdf", "action"=>"get_pdf", "id"=>"1", "controller"=>"pdf"}
***************WICKED***************
Rendering pdf/get_pdf
RuntimeError (PDF could not be generated!
/usr/ruby1.8.7/lib/ruby/1.8/open3.rb:73:in `exec': No such file or directory - /app/fa369291-829b-4b61-9efe-b2f0d0a0a42c/home/bin/wkhtmltopdf-amd64 - - (Errno::ENOENT)
from /usr/ruby1.8.7/lib/ruby/1.8/open3.rb:73:in `popen3'
from /usr/ruby1.8.7/lib/ruby/1.8/open3.rb:59:in `fork'
from /usr/ruby1.8.7/lib/ruby/1.8/open3.rb:59:in `popen3'
from /usr/ruby1.8.7/lib/ruby/1.8/open3.rb:57:in `fork'
from /usr/ruby1.8.7/lib/ruby/1.8/open3.rb:57:in `popen3'
from /app/fa369291-829b-4b61-9efe-b2f0d0a0a42c/home/vendor/plugins/wicked_pdf/lib/wicked_pdf.rb:22:in `pdf_from_string'
from /app/fa369291-829b-4b61-9efe-b2f0d0a0a42c/home/vendor/plugins/wicked_pdf/lib/pdf_helper.rb:28:in `make_pdf'
from /app/fa369291-829b-4b61-9efe-b2f0d0a0a42c/home/vendor/plugins/wicked_pdf/lib/pdf_helper.rb:39:in `make_and_send_pdf'
from /app/fa369291-829b-4b61-9efe-b2f0d0a0a42c/home/vendor/plugins/wicked_pdf/lib/pdf_helper.rb:13:in `render'
from /app/fa369291-829b-4b61-9efe-b2f0d0a0a42c/home/app/controllers/schedule_controller.rb:33:in `get_pdf'
Please Help. Thanks in Advance.
EDIT:
I made some changes in my code and got through this error but still stuck here
NoMethodError (undefined method empty? for #<Pathname:0x2b7112392480>)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如何让 WickedPdf gem 在 Heroku 上工作
(请参阅下面的引用以获取网址)
bin
的文件夹。wkhtmltopdf
二进制文件并将其解压到bin
文件夹中。您将需要适合您的开发系统的版本以及适用于 Heroku 的 AMD64 版本。暂时不要添加到您的 git 存储库。bin
文件夹中每个二进制文件的执行权限,例如chmod +x bin/wkhtmltopdf-amd64
git add bin
wicked_pdf
到您的Gemfile
和捆绑安装
。不需要其他 wkhtmltopdf gem。config/initializers
文件夹中创建一个名为wicked_pdf.rb
的文件,其源代码如下。git commit -am 'added wkhtmltopdf binaries and wicked_pdf gem'
git push heroku
现在,您的 Rails 项目已针对 Heroku 配置完毕。从这里,添加 PDF 文件的程序逻辑。
** config/initializers/wicked_pdf.rb **
我如何得出这个结论:
对于初学者来说,网络上有几篇关于
wkhtmltopdf
的误导性文章,wicked_pdf
gem 和Heroku
。最新版本的
wkhtmltopdf
(10.0+) 也存在导致执行挂起的问题。最后,在某个时刻,
WickedPdf
的配置变量名称肯定发生了变化,因为有几篇文章引用了:exe_path
,而其他文章则引用了:wkhtmltopdf
>。甚至 WickedPdf 的 GitHub 文档也会在每个变量之间交替。
我的解决方案您不需要需要从源代码编译
wkhtmltopdf
。您不需要需要从Homebrew安装
wkhtmltopdf
。如果您确实想要brew install wkhtmltopdf
,我提供了解决方案。您也不需要需要将任何“wkhtmltopdf”helper gem 添加到您的项目中。我尝试了
wkhtmltopdf
、wkhtmltopdf-heroku
、wkhtmltopdf-engineyard
、wkhtmltopdf-binary
gems 和 GitHub 存储库。在当地工作得很好。 Heroku 没有运气。从 Heroku 上的 Rails 控制台:
我通过运行
RUBY_PLATFORM
调查了运行 Heroku 服务器的 CPU,结果是“x86_64-linux”
。我还通过发出
Dir.entries('bin')
来查看 Heroku 上的bin
文件夹内部实际存在的文件。我注意到我正在测试的一些wkhtmltopdf
gems 将它们的可执行文件放置在这个文件夹中。一条线索!我运行
WickedPdf.new.pdf_from_string('Hello')
来查看输出错误并测试各种 WickedPdf 配置。然后,在 @barlow 对配置
PDFKit
的回答中,有一个子注释给出了最终的密钥。在提交到 Git 之前,您必须向wkhtmltopdf
二进制文件授予 Unix 执行权限。宾果!引用:
在撰写本文时:
2015 年 2 月 12 日修订
dscout 开发了一个包含我答案概念的 gem。如果您的 Heroku 实例支持构建包,我建议使用 gem。
2015 年 3 月 27 日修订
于 适用于 Heroku(和 Linux AMD64 操作系统)wkhtmltopdf-heroku
它会自动检测是否安装了 pdfkit、wicked_pdf 和wisepdf gems。
How to get WickedPdf gem to work on Heroku
(see citation below for urls)
bin
in the root of your Rails app.wkhtmltopdf
binaries to thebin
folder. You will need the version for your development system and the AMD64 version for Heroku. Do not add to your git repo yet.bin
folder e.g.chmod +x bin/wkhtmltopdf-amd64
git add bin
wicked_pdf
to yourGemfile
andbundle install
. No other wkhtmltopdf gems are needed.config/initializers
folder calledwicked_pdf.rb
with the source code below.git commit -am 'added wkhtmltopdf binaries and wicked_pdf gem'
git push heroku
Your Rails project is now configured for Heroku. From here, add your program logic for PDF files.
** config/initializers/wicked_pdf.rb **
How I came to this conclusion:
For starters, there are SEVERAL misleading articles on the Web regarding
wkhtmltopdf
, thewicked_pdf
gem, andHeroku
.There are also issues with recent versions of
wkhtmltopdf
(10.0+) that cause execution to hang.Lastly, at some point there must have been a change in the config variable names for
WickedPdf
because several articles reference:exe_path
while other articles reference:wkhtmltopdf
.Even WickedPdf's GitHub documentation alternates between each variable.
My solution you do not need to compile
wkhtmltopdf
from source.You do not need to install
wkhtmltopdf
from Homebrew. I provided the solution to this if you really want tobrew install wkhtmltopdf
.You also do not need to add any of the 'wkhtmltopdf' helper gems to your project. I tried
wkhtmltopdf
,wkhtmltopdf-heroku
,wkhtmltopdf-engineyard
,wkhtmltopdf-binary
gems and GitHub repos. Worked great locally. No luck at Heroku.From a Rails console on Heroku:
I investigated what CPU was running Heroku's servers by running
RUBY_PLATFORM
which yielded"x86_64-linux"
.I also peeked inside the
bin
folder on Heroku by issuing theDir.entries('bin')
to see what files actually exist there. I noticed some of thewkhtmltopdf
gems I was testing placed their executables in this folder. A clue!I ran
WickedPdf.new.pdf_from_string('Hello')
to see the output errors and test various WickedPdf configurations.Then, in @barlow's answer to configuring
PDFKit
, there is a subnote that gave the ultimate key. You must give Unix execute permissions towkhtmltopdf
the binary before committing to Git. Bingo!Cite:
At the time of this writing:
Amended 2/12/2015
dscout has developed a gem that encompasses the concepts of my answer. I recommend using the gem if your Heroku instance supports buildpacks.
Amended 3/27/2015
Another gem that works with Heroku (and Linux AMD64 OSes) wkhtmltopdf-heroku
It auto-detects if pdfkit, wicked_pdf and wisepdf gems are installed.
查看您的编辑部分后,其中显示“未定义方法空?对于
#
这意味着您在路径对象上使用空?函数,而空?是一个字符串而不是路径的函数
尝试找出您在哪里使用了路径对象并在该对象上使用 to_s
。
After looking at your Edit part which says "undefined method empty? for
#<Pathname:0x2b...>
This means you are somewhere using empty? function on a path Object whereas empty? is a function of a string and not path.
try to find out where you have used a path Object and use to_s on that object.
Try it out.
如果您将 wkhtmltopdf 的本地副本添加到您的存储库中,您可以在初始化程序中像这样指向它。
记得在你的仓库中 chmod +x 你的 wkhtmltopdf 副本,然后再 - git add 它
希望这会有所帮助。
If you add a local copy of wkhtmltopdf to your repo you can point to it like this in an initializer.
remember to chmod +x your wkhtmltopdf copy in your repo before you - git add it
Hope this helps.
正在寻找 wicked_pdf 二进制文件:
/app/fa369291-829b-4b61-9efe-b2f0d0a0a42c/home/bin/wkhtmltopdf-amd64
并且不存在,请将二进制文件放入应用程序中的文件夹中,然后然后更改文件
config/initializers/wicked_pdf.rb
以包括:如果 wicked_pdf 创建文件,您可能会遇到的另一个问题是 Heroku 文件系统只能读取,所以除非您找到一种方法来告诉wicked_pdf 在 tmp 目录中创建 pdf 文件,您可能无法使用它。
Is looking for the wicked_pdf binary in :
/app/fa369291-829b-4b61-9efe-b2f0d0a0a42c/home/bin/wkhtmltopdf-amd64
And is not there, put the binary in a folder within your application and then change the file
config/initializers/wicked_pdf.rb
to include:Another problem you might come to if wicked_pdf create files, is the fact that Heroku filesystem is only read, so unless you find a way to tell wicked_pdf to create the pdfs in the tmp directory you might not be able to use it.