2016-12-20 88 views
1

我在rails應用程序中使用wicked_pdf gem,一切正常。問題是我已經安裝了wicked_pdf.exe,因爲wicked_pdf gem無法正常工作。 它返回此錯誤:wicked_pdf(或類似)的wkhtmltopdf的路徑不正確。 這是我wicked_pdf配置:如何在rails中使用wicked_pdf gem?

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', 
} 

我如何使用正確的方法寶石?我需要發送我的應用程序到另一臺電腦,我不想在每臺電腦上安裝該exe文件。 我不想使用exe,我只想使用寶石。

回答

0

GitHub的documentation說:

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'

如此看來,你將不得不還包括這個二進制在你的應用程序。捆綁安裝應該解決這個問題。您可能需要創建應用設置WickedPdf.config(例如在/ usr/bin中/本地/ wkhtmltopdf VS C:\ Program Files文件\ wkhtmltopdf \ BIN \ wkhtmltopdf.exe)裏面的一些操作系統映射

+0

Hi @ whodini9!謝謝,但它仍然無法正常工作。我已經安裝了gem'wicked_pdf',gem'wkhtmltopdf-binary'和「exe_path:'C:\ RailsInstaller \ Ruby2.2.0 \ bin \ wkhtmltopdf'」而不是「exe_path:'C:\ Program Files \ wkhtmltopdf \ bin \ wkhtmltopdf.exe'」。這是運行時錯誤:wkhtmltopdf不可執行 – ValeMarz

+0

您可以嘗試使用第二個選項:exe_path:Gem.bin_path('wkhtmltopdf-binary','wkhtmltopdf')。另外通常更安全的使用File.join(「C:\」,「Program Files」,「#{foo}」,bar) – whodini9

+0

仍然「wkhtmltopdf不可執行」 – ValeMarz

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

這爲我工作

相關問題