2

我正在尝试使用以下代码为我在 RoR 3.2.11 中使用 PDFKit 创建的 PDF 添加页脚:

template = File.read "#{Rails.root}/app/views/layouts/portfolio.haml"
@ci = self
pdf_html = Haml::Engine.new(template).render self

template_footer = File.read "#{Rails.root}/app/views/layouts/portfolio_footer.haml"
@ci = self
pdf_footer_html = Haml::Engine.new(template_footer).render self

pdfkit_instance = PDFKit.new(pdf_html, :orientation => 'Landscape', 'footer-html' => pdf_footer_html)

send_data(pdf.to_pdf, :filename => "generated.pdf", :type => 'application/pdf')

不幸的是,这导致了“Broken Pipe”错误:

pdfkit (0.5.2) lib/pdfkit/pdfkit.rb:65:in `write'
pdfkit (0.5.2) lib/pdfkit/pdfkit.rb:65:in `puts'
pdfkit (0.5.2) lib/pdfkit/pdfkit.rb:65:in `block in to_pdf'
pdfkit (0.5.2) lib/pdfkit/pdfkit.rb:64:in `popen'
pdfkit (0.5.2) lib/pdfkit/pdfkit.rb:64:in `to_pdf'
app/controllers/admin/collection_items_controller.rb:9:in `test_generate_pdf'

当我生成没有页脚的 PDF 时,它是成功的。如果我使用页脚 html 作为主要的 html 源,它也会成功。使用像“footer-right”这样的纯文本选项之一也可以,但显然我想使用 html 选项。这种行为在本地和部署到 Heroku 时都是一致的。

4

1 回答 1

0

试试这条线

pdfkit_instance = PDFKit.new(pdf_html, :orientation => 'Landscape', :footer_html => pdf_footer_html)
于 2013-09-26T21:27:15.697 回答