WickedPDF头部渲染

时间:2013-01-14 11:56:21

标签: ruby-on-rails-3.2 wicked-pdf

我用户mac osx并通过wickedpdf尝试我的html文件到pdf文件。我想在我的pdf文件的每一页都放一个字符串,但我有一个关于标题的问题,而不是渲染。

我的wickedpdf方法是,

format.pdf do
        render :pdf => '#{@examination.name}.pdf',
               :disposition => 'inline',
               :layout => 'examination_session_pdf.html.erb',
               :no_background => true,
               :header =>{:html =>{:template=>'shared/pdf/header.pdf.erb'}}
      end

并且头文件只包含“hello”字符串或什么都没有。但是,每次我看到这个错误,

can't convert nil into String

问题行是“:header => {:html => {:template =>'shared / pdf / header.pdf.erb'”。另外,我看不到有关在控制台上呈现标题页的任何日志。

我该如何解决?

2 个答案:

答案 0 :(得分:6)

我今天早些时候遇到了同样的问题!

这是我为了让它工作而做的事情


    format.pdf do
        render :pdf => "#{@inv.invno}.pdf",
               :template => "inv/show.pdf",
               :layout =>'pdf',
               :header => { :content => render_to_string({:template => 'inv/header.pdf.erb'})},
               :footer => { :content => render_to_string({:template => 'inv/footer.pdf.erb'})},
               :margin => { :top => 38, :bottom => 35}
        end

你会看到Ive实际使用了render_to_string,然后通过:content将结果粘贴到页眉或页脚。这对我很有用。

你可以忽略:margin部分因为我只是使用它来很好地分隔,因为页眉和页脚都包含图形。

希望这有帮助!

答案 1 :(得分:3)

this issue上注明了我的解决方案。

确保你有

<!DOCTYPE html>

位于标题模板文件的顶部。

相关问题