PDFKit javascript issues

I also posted this on stackoverflow so apologises for cross posting but
I think this is probably a better home for this post.

I have been looking into using PDFKit to generate pdf reports for a Rail
3 app I’m working on. Basically if I use PDFKit as middleware any page
in the app is nicely rendered to a pdf including the javascript
generated graphs.

However, I want to use a different layout for pdf reports that removes
any of the sidebar or navigation details so instead of using the
middleware option I have been playing around with adding the following
to the relevant controller action

format.pdf {
html = render_to_string(:action => “show.html.erb”,
:layout => “report.html.erb”)
kit = PDFKit.new(html)
kit.stylesheets <<
“#{Rails.root}/public/stylesheets/application.css”
send_data kit.to_pdf, :filename => “file.pdf”, :type =>
:pdf}

This definitely solves my layout problem but it appears that none of the
javascripts are being run and the graphs are no longer appearing. I had
a look at the PDFKit mddleware source but I couldn’t spot any major
differences in the way the pdfs are produced.

I’m still finding my feet with a lot of things with rails so I’m sure it
is probably something pretty obvious that is staring me in the face. Any
pointers that anyone might have would be greatly appreciated and again
I’m sorry for cross posting

Actually having looked at the middleware source a little more carefully
it does look like the javascript paths need to be translated to their
absolute form so that wkhtmltopdf can find the resources. There is also
a trouble shooting section of PDFKit github page that basically points
this out too. I’ll post my solution here once I have it sorted.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs