简体   繁体   中英

how to use wicked_pdf gem in rails?

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.

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)

exe_path: 'C://Program Files/wkhtmltopdf/bin/wkhtmltopdf.exe'

这对我有用

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM