【问题标题】:rails, wicked-pdf gem and é à ö characters showing incorrectlyrails、wicked-pdf gem 和 é à ö 字符显示不正确
【发布时间】:2012-02-27 13:51:00
【问题描述】:

当我生成包含 é è à 等字符的文本的 PDF 时,我确实会得到有趣的字符。

我知道这一定与编码有关。

我确实在字符串上尝试了 force_encoding("UTF-8") 没有成功。

乔尔

【问题讨论】:

    标签: ruby-on-rails character-encoding wicked-pdf


    【解决方案1】:

    你可以作为选项传递:

    encoding: 'utf8'
    

    【讨论】:

      【解决方案2】:

      您也可以将其作为选项添加到 wickedpdf 中

       WickedPdf.new.pdf_from_string(
          render :pdf => "Paper",
          :template => "paper/paper.html",
          :page_size => 'A4',
           formats: :html, encoding: 'utf8',
          :margin => {:top => 40}
        )
      

      【讨论】:

      • 谢谢。 Wicked 的pdf_from_string 文档并没有真正暗示您可以传递这样的选项(无控制器/视图)。例如,这对我有用:pdf = WickedPdf.new.pdf_from_string(html, encoding: 'utf8')
      【解决方案3】:

      要解决此问题,请在视图开头添加以下行:

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

      您可以参考此链接 - https://github.com/mileszs/wicked_pdf/issues/35 了解更多详情。

      【讨论】:

        【解决方案4】:

        &lt;meta charset="UTF-8"&gt; 添加到 HTML 视图的顶部或布局的头部。

        【讨论】:

          猜你喜欢
          • 2017-03-03
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2019-02-25
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-06-17
          相关资源
          最近更新 更多