如何将整个pdf页面的背景颜色白色更改为导轨中的其他颜色
问题描述:
使用pdfkit gem。我不得不改变整个PDF页面默认背景颜色为白色到其它颜色。如何做到这一点..如何将整个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;
}
增加,但如果最后一页有一些数据,背景颜色只覆盖数据存在的地方,扩展页面是白色的.. – khalidh