6
votes

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.

4

4 Answers

4
votes

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.

3
votes

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
}
3
votes

wkhtmltopdf will install into /usr/bin/wkhtmltopdf but it's expected at /usr/local/bin/wkhtmltopdf.

To fix it just create symbolic link as (probably you will need to use sudo):

ln -s /usr/bin/wkhtmltopdf /usr/local/bin/wkhtmltopdf

1
votes

I faced similar problem. Try reinstalling gem and also install library to support that gem. here are the links to install that library in mac and ubuntu:

unable to install wkhtmltopdf with patched qt in ubuntu 16.04

http://macappstore.org/wkhtmltopdf/