0

我正在使用Grover渲染和下载在我的应用程序中生成的文档的 pdf 副本,并且无法将 css 应用于它。在 grover 的调试模式下(因此在 Chromium 中导出和渲染),CSS 完全按照我的预期进行渲染。但是,当我将它置于无头模式并以 pdf 格式下载时,我的 application.css 似乎没有被应用。

正在使用以下方法生成 PDF:

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

我正在使用以下行引用 css,放置在<head>我的布局中。

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

如果我不得不猜测,我会认为我搞砸了stylesheet_link_tag,并且调试版本能够从资产管道中提取,而无头版本不是。

提前致谢

4

1 回答 1

0

原来,grover 需要配置才能显示背景print_background: true。碰巧我只设置了背景,然后才意识到它不起作用,所以true在我们的 grover 初始化程序中设置该参数就可以了。

于 2021-01-04T23:09:08.727 回答