how to use wicked_pdf gem in rails?

1.4k views Asked by At

I'm using wicked_pdf gem in a rails app and everything works fine. The problem is that I have installed wicked_pdf.exe because wicked_pdf gem doesn't work correctly. It returns this error: Bad wkhtmltopdf's path for wicked_pdf ( Or similar). This is my wicked_pdf config:

    WickedPdf.config = {
  # Path to the wkhtmltopdf executable: This usually isn't needed if using
  # one of the wkhtmltopdf-binary family of gems.
  exe_path: 'C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe',
  #   or
  #exe_path: Gem.bin_path('wkhtmltopdf-binary', 'wkhtmltopdf')

  # Layout file to be used for all PDFs
  # (but can be overridden in `render :pdf` calls)
  # layout: 'pdf.html',
}

How can i use the gem in proper way? I need to send my app to another pc and I don't want to install the exe in every pc. I don't want to use exe, i want to use only gem.

2

There are 2 answers

3
whodini9 On

The github documentation says:

Because wicked_pdf is a wrapper for wkhtmltopdf, you'll need to install that, too.

The simplest way to install all of the binaries (Linux, OSX, Windows) is through the gem wkhtmltopdf-binary. To install that, add a second gem

gem 'wkhtmltopdf-binary'

So it seems that you will have to also include this binary in your app. Bundling the install should solve this. You may need to create some OS mapping inside your app to set WickedPdf.config (ex /usr/bin/local/wkhtmltopdf vs C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe)

0
Abdul Wahed On
exe_path: 'C://Program Files/wkhtmltopdf/bin/wkhtmltopdf.exe'

This worked for me