Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
814 views
in Technique[技术] by (71.8m points)

ruby on rails - Stylesheet renders in grover debug but not on downloaded pdf

I'm using Grover to render and download pdf copies of documents that are generated in my app and am having trouble applying css to it. When in grover's debug mode (and therefore exported and rendered in Chromium), the CSS renders exactly how I would expect. However, when I put it in headless mode and download as a pdf, it appears that my application.css is not being applied.

The PDF is being generated with the following method in a concern:

def purchase_order_gen(the_purchase_order, request_host_with_port)
  puts "generating pdf"
  puts "Generating PDF for PO " + the_purchase_order.id.to_s
  puts "Host is " + request_host_with_port

  html = render_to_string({
                              partial: '/purchase_orders/display_purchase_order',
                              layout: '/layouts/pdf_layout.html.erb',
                              locals: { po: the_purchase_order }
                              })
  puts "html"
  ap html

  the_display_url = 'http://' + request_host_with_port
  grover = Grover.new(html, {format: 'A4' , display_url: the_display_url})
  pdf = grover.to_pdf
  puts "Back From Grover!"

  return pdf
end

And I'm referencing the css with the following line, placed in the <head> of my layout.

<%= stylesheet_link_tag '/assets/stylesheets/application.css'%>

If I had to guess, I'd figure that I'm bungling the stylesheet_link_tag and that the debug version is able to pull from the asset pipeline, where the headless version is not.

Thanks in advance


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Turned out that grover requires a configuration for backgrounds to appear print_background: true. It just so happened that I had only set backgrounds before realizing that it wasn't working so setting that parameter to true did the trick.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...