【发布时间】:2013-02-01 05:58:59
【问题描述】:
我正在使用 PDFKit 将部分视图呈现为 PDF 文件。但是,我在尝试使用 render_to_string(首选方法)而不是外部 Web 请求时遇到了一些问题。
使用 url 呈现时的 pdf 文件:
html = "#{root_url}/contracts/#{@contract.id}"
pdf = PDFKit.new(html, page_size: 'Letter').to_pdf
使用 render_to_string 渲染时的 pdf 文件:
html = render_to_string :partial => "agreement"
pdf = PDFKit.new(html , page_size: 'Letter').to_pdf
*from the console*
html => "\n\n<style>\n #contract h2{text-align: center; margin-bottom: 10px;}\n #contract em{font-weight: bold; text-decoration: underline; font-style: normal;}\n #contract p.tab{margin-left: 25px;}\n #contract ol{list-style:lower-alpha;}\n #contract ol li{margin-left: 25px; font-size: 1em; line-height: 1.615em; color: #555; margin-bottom: 5px;}\n #contract b{font-weight: bold;}\n #contract p p{margin-left: 10px;}\n</style>\n<div id=\"contract\">\n <p>This agreement (“<b>Agreement</b>”) is entered into...
我做错了什么?
【问题讨论】:
-
您可能试图在具有
ASCII编码的页面中显示 unicode 符号(引号)。问题与pdf无关,在你html的head中添加<meta encoding="utf-8">。 -
我试过了,但这似乎没有奏效。在这两种情况下,为 PDFKit 提供了相同的 html,但只有一种编码较差。
标签: ruby-on-rails ruby encoding pdfkit