WKHTMLTOPDF path in ROR application
Asked Answered
S

4

6

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.

Skepful answered 18/4, 2015 at 9:44 Comment(0)
B
5

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.

Bulbiferous answered 18/4, 2015 at 10:2 Comment(2)
Output of which wkhtmltopdf is - /usr/local/bin/wkhtmltopdf and of wkhtmltopdf -V is wkhtmltopdf 0.9.6Skepful
Hmm, im as baffled as you are. I think as a last debugging attempt you could try specifying the path explicitly and/or moving the executable to a different location.Bulbiferous
E
3

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
}
Equi answered 21/4, 2015 at 19:48 Comment(0)
H
3

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

Highspirited answered 25/2, 2020 at 8:0 Comment(0)
T
1

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/

Terranceterrane answered 8/2, 2017 at 13:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.