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.
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
in our grover initializers did the trick.