Gemfile
gem "wicked_pdf"
gem "wkhtmltopdf-binary"
the error:
RuntimeError in CarsController#show
Failed to execute:
/usr/bin/wkhtmltopdf --print-media-type -q - -
Error: PDF could not be generated!
Rails.root: /u/apps/zeepauto/autozeep_update
cars_controller
def show
@class_showcar = true
@class_admin = true
@car = Car.find(params[:id])
@search = Car.search(params[:search])
@cars_see_special = Car.where(:special => "1").order('rand()').limit(3)
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @car }
format.pdf do
render :pdf => "#{@car.carname.name}",
:print_media_type => true
end
end
end
show.html.erb
<p class="show_links"><%= link_to url_for(request.params.merge(:format => :pdf)) do %>
<%= image_tag('/images/printversion.png', :alt => 'Download') %>
</p>
wicked_pdf.erb
# config/initializers/wicked_pdf.rb
WickedPdf.config = {
# :exe_path => '/var/lib/gems/1.8/bin/wkhtmltopdf'
:exe_path => '/usr/bin/wkhtmltopdf'
}
2 个解决方案
#1
19
I had the same problem. The solution was to add wkhtmltopdf-binary
to the gem file and run bundle install
.
我有同样的问题。解决方案是将wkhtmltopdf-binary添加到gem文件并运行bundle install。
gem "wicked_pdf"
gem "wkhtmltopdf-binary"
#2
7
I had wkhtmltopdf-binary
already in gemfile
, but as this was working on my local computer and not on server, I left this error for the server support team to care off.. they have checked the path to wkhtmltopdf, they tried to convert a simple html to pdf and it worked.. so they tried to run a bundle update
command and after this the pdf converting worked fine on server too. I had a gem path changed and I guess this was the problem. I posted my solution in case someone else will have this problem too.
我已经在gemfile中使用了wkhtmltopdf-binary,但由于这是在我的本地计算机而不是在服务器上工作,我为服务器支持团队留下了这个错误来关心..他们已经检查了wkhtmltopdf的路径,他们试图转换一个简单的HTML到pdf,它工作..所以他们试图运行一个捆绑更新命令,在此之后,pdf转换在服务器上工作正常。我改变了宝石路径,我想这就是问题所在。我发布了我的解决方案,万一其他人也会遇到这个问题。
#1
19
I had the same problem. The solution was to add wkhtmltopdf-binary
to the gem file and run bundle install
.
我有同样的问题。解决方案是将wkhtmltopdf-binary添加到gem文件并运行bundle install。
gem "wicked_pdf"
gem "wkhtmltopdf-binary"
#2
7
I had wkhtmltopdf-binary
already in gemfile
, but as this was working on my local computer and not on server, I left this error for the server support team to care off.. they have checked the path to wkhtmltopdf, they tried to convert a simple html to pdf and it worked.. so they tried to run a bundle update
command and after this the pdf converting worked fine on server too. I had a gem path changed and I guess this was the problem. I posted my solution in case someone else will have this problem too.
我已经在gemfile中使用了wkhtmltopdf-binary,但由于这是在我的本地计算机而不是在服务器上工作,我为服务器支持团队留下了这个错误来关心..他们已经检查了wkhtmltopdf的路径,他们试图转换一个简单的HTML到pdf,它工作..所以他们试图运行一个捆绑更新命令,在此之后,pdf转换在服务器上工作正常。我改变了宝石路径,我想这就是问题所在。我发布了我的解决方案,万一其他人也会遇到这个问题。