【发布时间】:2011-09-09 20:40:18
【问题描述】:
我在我的 Rails 应用程序中使用 PDFKit 来生成 PDF。问题是我的一些内容包含非ASCII字符。如何强制它使用 UTF-8?
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-3 utf-8 wkhtmltopdf pdfkit
我在我的 Rails 应用程序中使用 PDFKit 来生成 PDF。问题是我的一些内容包含非ASCII字符。如何强制它使用 UTF-8?
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-3 utf-8 wkhtmltopdf pdfkit
通过将其添加到 html 头部来修复:
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
【讨论】:
html = '<meta http-equiv="Content-type" content="text/html; charset=utf-8" />' + str(msg.html)
You can write in PDFKIT configration.
PDFKit.configure do |config|
config.wkhtmltopdf = '/opt/wkhtmltopdf'
config.default_options = {
:encoding => 'UTF-8'
:page_size => 'Letter',
:margin_top => '0.3in',
:margin_bottom => '0.1in',
:print_media_type => true
}
end
【讨论】:
utf-8 是 encoding 键的默认值 github.com/pdfkit/pdfkit/blob/master/lib/pdfkit/…