我正在使用gem 'pdfkit'
并gem 'wkhtmltopdf-binary'
在 Ruby on Rails 应用程序上生成发票。我有一个erb文件,我将其渲染如下:
kit = PDFKit.new(ActionController::Base.new.render_to_string('billing/invoice_pdf', layout: nil, locals: { invoice: invoice_data }), pdf_option)
file = kit.to_file("#{Rails.root}/tmp/#{@invoice.id}_#{@invoice.remote_id}.pdf")
@invoice.document = Document.create(file: file)
而且pdf_option
是
def pdf_option
{
disable_smart_shrinking: false,
page_size: 'A4',
margin_top: '0',
margin_right: '0',
margin_bottom: '0',
margin_left: '0',
encoding: 'UTF-8'
}
end
生成的 pdf 在本地机器上看起来不错,但在生产服务器上变得很奇怪。
任何想法?有什么问题?谢谢