简体   繁体   English

如何在导轨中使用wicked_pdf gem?

[英]how to use wicked_pdf gem in rails?

I'm using wicked_pdf gem in a rails app and everything works fine. 我在Rails应用程序中使用wicked_pdf gem,一切正常。 The problem is that I have installed wicked_pdf.exe because wicked_pdf gem doesn't work correctly. 问题是我安装了wicked_pdf.exe,因为wicked_pdf gem无法正常工作。 It returns this error: Bad wkhtmltopdf's path for wicked_pdf ( Or similar). 它返回以下错误:wicked_pdf的wkhtmltopdf错误路径(或类似)。 This is my wicked_pdf config: 这是我的wicked_pdf配置:

    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. 我需要将我的应用程序发送到另一台PC,并且我不想在每台PC中都安装exe。 I don't want to use exe, i want to use only gem. 我不想使用exe,我只想使用gem。

The github documentation says: github 文档说:

Because wicked_pdf is a wrapper for wkhtmltopdf , you'll need to install that, too. 因为wicked_pdfwicked_pdf的包装器, wkhtmltopdf您也需要安装它。

The simplest way to install all of the binaries (Linux, OSX, Windows) is through the gem wkhtmltopdf-binary. 安装所有二进制文件(Linux,OSX,Windows)的最简单方法是通过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) 您可能需要在应用程序内部创建一些操作系统映射以设置WickedPdf.config (例如/ usr / bin / local / wkhtmltopdf与C:\\ Program Files \\ wkhtmltopdf \\ bin \\ wkhtmltopdf.exe)

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

这对我有用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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