【发布时间】:2017-05-25 17:59:38
【问题描述】:
我正在使用wicked_pdf 在我的rails 项目中从html 生成pdf。它正在渲染template,但我无法打印header/footer 部分。下面是我只打印template 部分的代码
render pdf: "pdf_name",
layout: 'application',
template: 'reports/show',
formats: [:html],
margin: { top: 10, bottom: 10, left: 10, right: 10 },
disable_javascript: true,
show_as_html: params[:debug],
header: {
html: { template: 'shared/header' },
spacing: 10
},
footer: {
html: { template: 'shared/footer' },
spacing: 30,
line: true
}
如果我尝试使用WickedPdf.new.pdf_from_string render_to_string,它会显示Failed to load PDF document 错误,即使是简单的WickedPdf.new.pdf_from_string('<html><body><h1>Hello There!</h1></body></html>') 也不起作用。
我曾尝试使用render_to_string_with_wicked_pdf, render_with_wicked_pdf,但没有成功。我的 Rails 版本是 3.2.19,wicked_pdf gem 版本是 1.1.0 和 wkhtmltopdf 版本是 wkhtmltopdf-0.13.0-alpha-7b36694_linux-trusty-amd64.deb。我也试过用wkhtmltopdf版本0.12.0。
我的问题是
- 为什么我上面的实现不起作用?
- 为什么
pdf_from_string不起作用?
感谢任何形式的帮助。谢谢。
【问题讨论】:
标签: html ruby-on-rails-3 pdf-generation wkhtmltopdf wicked-pdf