【问题标题】:prawn font-families update results in empty pdf对虾字体家族更新导致空pdf
【发布时间】:2017-11-25 22:40:42
【问题描述】:

我使用 prawn 实现了 pdf 生成,这在我的测试服务器上运行没有任何问题。 部署和测试功能后,我收到以下错误消息

Your document includes text that's not compatible with the Windows-1252 character set.

如果您需要完整的 UTF-8 支持,请使用 TTF 字体而不是 PDF 的内置字体。

于是我加了一个TTF字体,把这段代码加到大虾里

p.font_families.update("DejaVuSerif" => {
       :normal => "#{Rails.root}/path/to/fonts/DejaVuSerif.ttf",
 :bold => "#{Rails.root}/path/to/fonts/DejaVuSerif-Bold.ttf"        
  })

p.font "DejaVuSerif"

现在我没有收到任何错误消息,但它导致 PDF 为空,并且错误日志中也没有任何内容。

有人知道吗?

【问题讨论】:

    标签: ruby-on-rails pdf fonts prawn


    【解决方案1】:

    我用的是外部字体的虾

    以下是pdf.rb类中的代码

    class DataPDF < Prawn::Document
        def initialize
            font Rails.root.join("app/assets/fonts/DejaVuSerif.ttf")
        end
    end
    

    并确保文件名的大写/小写与文件夹中的物理文件相同

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-11
      • 1970-01-01
      • 2019-12-17
      • 2015-12-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多