Bad wkhtmltopdf's path for wicked_pdf and wkhtmltopdf
Asked Answered
F

3

7

I am using two Gems to convert HTML to PDF.

Using "https://github.com/mileszs/wicked_pdf"

gem 'wicked_pdf'
gem "wkhtmltopdf-binary"

/initializer/wicked_pdf.rb

WickedPdf.config = {
  exe_path =>  "xxxxxxxxxxxxxxxxxxx"
}

What path should I use for the exe_path ?

Fairley answered 4/6, 2015 at 13:45 Comment(4)
are you using windows?Grassgreen
@test no i am using ubuntu.Fairley
Do which wkhtmltopdf in your project directory terminal. It will give you path. Paste that path in config/initializers/wicked_pdf.rb and then restart your serverGrassgreen
@test same error after i pass path which is get after which wkhtmltopdfFairley
G
18

which wkhtmltopdf

This will give you path of your wkhtmltopdf. You should copy this path and paste in your config/intializers/wicked_pdf.rb And then restart your server.

Grassgreen answered 4/6, 2015 at 14:14 Comment(1)
Worked for me. love you my dudeGarwin
L
5

Add this to config/initializers/wicked_pdf.rb ensuring your correct GEM_HOME is being referenced:

WickedPdf.config = {
  :exe_path => "#{ENV['GEM_HOME']}/bin/wkhtmltopdf"
}

This way you wont be hard coding any paths.

Leporide answered 20/1, 2017 at 0:52 Comment(2)
Thank you for your time and effort with this. It was a super annoying issueFerwerda
If you use '.asdf' as ruby version manager, => "#{ENV['GEM_HOME'].split("/").first(4).join("/")}/shims/wkhtmltopdf"Letta
B
5

config/initializers/wicked_pdf.rb

path = `which wkhtmltopdf`.gsub(/\n/, "")

WickedPdf.config = { exe_path: path }
Belloir answered 7/3, 2018 at 6:10 Comment(1)
Although your code snippet might solve the issue, you should describe what’s the purpose of your code (how it solves the problem). Furthermore, you might want to check stackoverflow.com/help/how-to-answerAbnaki

© 2022 - 2024 — McMap. All rights reserved.