安装程序:Rails 4.1.1应用程序使用 gem 'wicked_pdf', '~> 0.11.0' 和手动安装的wkhtmltopdf二进制版本0.12.1(带有修补的qt)
我有两个控制器生成类似的pdf报告,共享几页 . 我对两种报告类型之间共享的页面有部分内容 .
控制器代码:
# GET /assessments/1
def show
respond_to do |format|
format.html
format.pdf do
render pdf: "Individual_Report-#{Date.today}",
disposition: "inline",
layout: "pdf",
dpi: "300",
encoding: "UTF-8",
show_as_html: params[:debug].present?
end
end
end
# GET /reports/1
def show
respond_to do |format|
format.html
format.pdf do
render pdf: "Team_Report-#{Date.today}",
disposition: "inline",
layout: "pdf",
dpi: "300",
encoding: "UTF-8",
show_as_html: params[:debug].present?
end
end
end
查看代码:
# layouts/pdf.slim
doctype html
html
head
meta charset="utf-8"
title
= content_for?(:title) ? yield(:title) : 'Main Title'
== wicked_pdf_stylesheet_link_tag "application", :media => 'all'
== wicked_pdf_stylesheet_link_tag "print", :media => 'all'
== wicked_pdf_javascript_include_tag 'vendor/modernizr'
== csrf_meta_tags
body data-action=action_name data-controller=controller_name data-format="pdf"
main
== yield
== wicked_pdf_javascript_include_tag 'application'
javascript:
window.jQuery || alert("false");
# assessments/show.pdf.slim
= render "shared/cover", m: @assessment, t: "Individual"
= render "shared/about"
= render "shared/team", report: @report
# etc. etc. this is where the reports differ
# reports/show.pdf.slim
= render "shared/cover", m: @report, t: "Team"
= render "shared/about"
= render "shared/team", report: @report
# etc. etc. this is where the reports differ
然而,评估控制器的报告生成的pdf内容宽度稍窄,文本大小也相应较小 . 使用debug param渲染html会给出相同的页面,并且检查css显示没有差异 . 我使用Foundation作为css框架,但我认为这不重要 .
我读了一些关于wkhtmltopdf的 --disable-smart-shrinking 选项,但我修复了潜在的问题 . 我可以根据需要添加截图,但我认为问题应该在没有它们的情况下足够清晰 .
感谢您提供有关如何解决问题的任何帮助或使用wicked_pdf调整wkhtmltopdf选项 .