ruby-on-rails-3 – PDFKit(wkhtmltopdf)破碎的管道,OS X和Rails 3

前端之家收集整理的这篇文章主要介绍了ruby-on-rails-3 – PDFKit(wkhtmltopdf)破碎的管道,OS X和Rails 3前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用 PDFKit(使用 wkhtmltopdf)来尝试在Rails 3应用程序中呈现为pdf格式的视图.

在我的控制器显示操作中,PDFKit使用Errno :: EPIPE(Broken pipe)指向send_data(kit.to_pdf,:filename =>“generated.pdf”,:type =>’application / pdf)

# Controller
def show
  respond_to do |format|
    format.html { render }
    format.pdf do
      html = render_to_string(:layout => false,:action => "show.html.haml")
      kit = PDFKit.new(html)
      send_data(kit.to_pdf,:filename => "invoice.pdf",:type => 'application/pdf')
      return # to avoid double render call
    end
  end
end

# Gemfile
...
gem 'pdfkit'
gem 'wkhtmltopdf'
...

我知道wkhtmltopdf不是这个错误的根源,因为Rails.root中的wkhtmltopdf public / 404.html tmp / 404.pdf可以按预期工作.

在使用中间件失败后,我正在使用example from jonathanspies.com.

# config/application.rb
require 'pdfkit'
config.middleware.use PDFKit::Middleware

尝试在一个新的Rails 3应用程序,我得到以下错误

command Failed: "~/.rvm/gems/ree-1.8.7-2011.01@blog/bin/wkhtmltopdf" "--page-size" "Letter" "--margin-right" "0.75in" "--margin-top" "0.75in" "--margin-bottom" "0.75in" "--encoding" "UTF-8" "--margin-left" "0.75in" "--quiet" "-" "-"

手动运行命令和使用情况屏幕显示,查看–quiet选项很容易看到它应该是–quit

/lib/pdfkit/pdfkit.rb:35更改为以下内容,一切正常工作(中间件也可以).

args << '--quit'

所以,我再次解决了我的问题,在写这个问题的行为得到帮助(总是支付包括细节).我提交了一个pull request,它纠正了拼写错误(总是一个愚蠢的错误,被忽视).希望没有人会介意我.

解决方法

关于改变安静的参数退出.

此更改仅在您使用wkhtmltopdf gem使用旧版本的wkhtmltopdf二进制文件时有效.

用wkhtmltopdf宝石

10:32:15 wkhtml >     wkhtmltopdf --version
wkhtmltopdf 0.8.3 using wkhtmltopdf patched qt
Copyright (C) 2008,2009 Jakob Truelsen,License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY,to the extent permitted by law.

Written by Jakob Truelsen
Patches by Mário Silva and Emmanuel Bouthenot

10:32:16 wkhtml >     wkhtmltopdf --help | grep quit
  -q,--quit                      Be less verbose.
10:32:16 wkhtml >     wkhtmltopdf --help | grep quite
10:32:19 wkhtml >

用最新的二进制文件我已经安装

10:33:40 tmp > wkhtmltopdf --version
Name:
  wkhtmltopdf 0.9.9

License:
  Copyright (C) 2008,2009 Wkhtmltopdf Authors.



  License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
  This is free software: you are free to change and redistribute it. There is NO
  WARRANTY,to the extent permitted by law.

Authors:
  Written by Jakob Truelsen. Patches by Mário Silva,Benoit Garret and Emmanuel
  Bouthenot.

10:33:50 tmp > wkhtmltopdf --help | grep quit
10:34:02 tmp > wkhtmltopdf --help | grep quiet
  -q,--quiet                         Be less verbose
10:34:07 tmp >

拼写错误存在于wkhtmltopdf gem附带的旧二进制文件中.我会建议你的猴子补丁pdfkit与初始化或基于如果你包括wkhtmltopdf宝石的东西.

我也会接受一个引用请求,使得pdfkit知道它正在运行的wkthtmltopdf的版本,并有条件地切换该参数.

原文链接:https://www.f2er.com/ruby/273767.html

猜你在找的Ruby相关文章