Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WKHTMLTOPDF path in ROR application

I am using wicked_pdf gem for HTML to PDF conversion. As per the descriptions in Github, I installed everything correctly. But I am getting a runtime error -

RuntimeError (Bad wkhtmltopdf's path: /usr/local/bin/wkhtmltopdf): app/controllers/orders_controller.rb:46:in `create

`44 @count = Item.count(:qty)
45  @temp = Item.where(:received => true).count()
46  render  :pdf => "Bill" ,
47  :template => 'orders/create.pdf.erb', # Excluding ".pdf" extension.
48  page_height:  100,
49  page_width:   80`

and wkhtmltopdf is installed in my system at /usr/local/bin/wkhtmltopdf

It is specified that the path for wkhtmltopdf should be where it's already installed.

I am not able to figure out what the problem is.

like image 545
Niyanta Avatar asked Apr 18 '15 09:04

Niyanta


2 Answers

In the source of wkhtmltopdf it looks like all it is doing is running File.exists? on that path:

https://github.com/mileszs/wicked_pdf/blob/56aa1a195d65eaaf33fbd0254e1e7df99ce1fd1c/lib/wicked_pdf.rb#L41

So we gotta double check the assumption that wkhtmltopdf is correctly installed at /usr/local/bin/wkhtmltopdf

Could you give a bit more information? Just to verify, what is the output of which wkhtmltopdf

And when you run wkhtmltopdf -V in the console, what do you get?

You could try specifying the path in the configuration (in an initializer as mentioned in the wkhtmltopdf readme) just to see if that makes a difference too.

And lastly you could move the executable to a different directory, and then specify that in the initializer to see if it maybe has something to do with folder permissions.

like image 61
Oliver Nicolaas Ponder Avatar answered Sep 19 '22 23:09

Oliver Nicolaas Ponder


Have you tried specifying the path in an initializer? ({rails.root}/config/initializers/wicked_pdf.rb) ex..

WICKED_PDF = {
    :exe_path => '/usr/local/bin/wkhtmltopdf-amd64'#should be whatever your version is called
}
like image 28
Clark Avatar answered Sep 18 '22 23:09

Clark