使用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
在your-style-sheet.css中
body {
background: #04b4b4;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句