0

我遇到了 wicked_pdf 的问题。它没有考虑到我的任何javascript。正在生成报告,呈现的文本是“未定义的页面未定义”。任何有关将 javascript 链接到 wicked_pdf 的帮助将不胜感激!

标记:

<html>
  <head>
    <script>
      function number_pages() {
        console.log('hi');
        var vars={};
        var x=document.location.search.substring(1).split('&');
        for(var i in x) {var z=x[i].split('=',2);vars[z[0]] = unescape(z[1]);}
        var x=['frompage','topage','page','webpage','section','subsection','subsubsection'];
        for(var i in x) {
          var y = document.getElementsByClassName(x[i]);
          for(var j=0; j<y.length; ++j) y[j].textContent = vars[x[i]];
        }
      }
    </script>
  </head>
  <body onload="number_pages()">
    Page <span class="page"></span> of <span class="topage"></span>
  </body>
</html>

控制器动作:

def generate_report
  respond_to do |format|
    format.html
    format.pdf do
      render :pdf => "hello.pdf", :template => "reports/templates/#{params[:report]}.pdf.erb", :disable_javascript => false
    end
  end
end
4

1 回答 1

1

该代码在 wkhtmltopdf 文档中作为示例给出,并且仅在页眉或页脚文件中提供时才有效,如下所示:

format.pdf do
  render :pdf => "hello.pdf",
         :template => "reports/templates/#{params[:report]}.pdf.erb",
         :footer   => {
           :html => {
             :template => "reports/templates/#{params[:report]}.pdf.erb"
           }
         }
end

运行时,内部模板显示page undefined of undefined,但页脚显示page 1 of 1。我认为这与 wkhtmltopdf 中页面拆分的内部结构有关。

于 2012-05-01T15:42:18.760 回答