我正在使用PDFKit(使用wkhtmltopdf)尝试在Rails 3应用程序中将视图呈现为pdf.
PDFKit通过Errno::EPIPE (Broken pipe)指向send_data(kit.to_pdf, :filename => "generated.pdf", :type => 'application/pdf')我的控制器show动作呈现:
# 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'
...
Run Code Online (Sandbox Code Playgroud)
我知道wkhtmltopdf不是这个错误的来源,因为wkhtmltopdf public/404.html tmp/404.pdf从Rails.root工作中如预期的那样.
在使用中间件失败后,我正在使用jonathanspies.com中的一个示例 …