轨道、邪恶的 pdf 宝石和 é à ö 字符显示不正确



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

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

我确实尝试过用这些字符对字符串进行force_encoding("UTF-8"),但没有成功。

joel

<meta charset="UTF-8">添加到HTML视图的顶部或布局的头部。

您可以作为选项传递:

encoding: 'utf8'

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

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

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

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

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

最新更新