2016-12-20 47 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' 

这为我工作

相关问题