如何在 rails 中将整个 pdf 页面的背景颜色白色更改为其他颜色

How to change entire pdf pages background color white to other color in rails

使用 pdfkit gem。我必须将整个 pdf 页面的默认背景颜色白色更改为其他颜色..如何实现这一点..

添加了以下代码:-

<BODY style=\"background-color:#04b4b4;\">

但它并没有覆盖所有页面,最后它只覆盖了数据区域,(如下图)...

更新:-

gem 'pdfkit', '0.5.0'
gem 'wkhtmltopdf-binary'

pdfkit.rb

PDFKit.configure do |config|
  config.default_options = {
    :page_size     => 'Letter',
    :margin_top    => '0in',
    :margin_right  => '0in',
    :margin_bottom => '1.0in',
    :margin_left   => '0in'
  }
end

您可以在 PDF 文件的样式表中定义它,然后像这样将其加载到您的 PDFKit 中:

  # init your pdfkit as usual
  kit = PDFKit.new(your_html, options)
  # load the stylesheet file
  kit.stylesheets << "#{Rails.root}/app/assets/stylesheets/your-style-sheet.css"
  # then build it or do what ever you want.
  kit.to_pdf

按照你的风格-sheet.css

body {
  background: #04b4b4;
}