2013-01-14 37 views
2

我試圖頁腳添加到PDF我使用下面的代碼與PDFKit創造回報率3.2.11:破管錯誤頁腳-HTML參數PDFKit(wkhtmltopdf)

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') 

不幸這是導致「破管」錯誤:

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時都是一致的。

回答

0

試試這條線

pdfkit_instance = PDFKit.new(pdf_html, :orientation => 'Landscape', :footer_html => pdf_footer_html)