简体   繁体   中英

wicked_pdf + rails 3.1 asset pipeline

I'm having an issue with wicked_pdf. It's not taking into account any of my javascript. The report is being generated and the text that is rendered is "Page undefined of undefined". Any help on linking up javascript into wicked_pdf would be greatly appreciated!

Markup:

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

Controller action:

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

That code was given as example in the wkhtmltopdf documentation, and only works when provided in a header or footer file like so:

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

When this is run, the inner template shows page undefined of undefined , but the footer shows page 1 of 1 . I think this has to do with the internals of page splitting in wkhtmltopdf.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM