【问题标题】:Stylesheet renders in grover debug but not on downloaded pdf样式表在 grover 调试中呈现,但在下载的 pdf 中不呈现
【发布时间】:2020-12-31 23:32:19
【问题描述】:

我正在使用 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,并且调试版本能够从资产管道中提取,而无头版本则不能。

提前致谢

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-5 asset-pipeline stylesheet-link-tag


    【解决方案1】:

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

    【讨论】:

    • 你只是将它添加到 Grover.new options 中?
    • @Artur79 这可能有效,但我们在 grover 初始化程序中做到了:config/initializers/grover.rb
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-22
    • 2017-05-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多