【问题标题】:How to use UTF-8 in PDFKit in Rails?如何在 Rails 的 PDFKit 中使用 UTF-8?
【发布时间】:2011-09-09 20:40:18
【问题描述】:

我在我的 Rails 应用程序中使用 PDFKit 来生成 PDF。问题是我的一些内容包含非ASCII字符。如何强制它使用 UTF-8?

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3 utf-8 wkhtmltopdf pdfkit


    【解决方案1】:

    通过将其添加到 html 头部来修复:

    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
    

    【讨论】:

    • 也适用于 Python pdfkit。 html = '&lt;meta http-equiv="Content-type" content="text/html; charset=utf-8" /&gt;' + str(msg.html)
    【解决方案2】:
    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
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-09-24
    • 2016-03-13
    • 1970-01-01
    • 1970-01-01
    • 2012-02-09
    • 1970-01-01
    • 1970-01-01
    • 2015-08-03
    相关资源
    最近更新 更多