ruby-on-railswicked-pdf

wicked_pdf Error: PDF could not be generated


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'
}

Solution

  • 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.