【问题标题】:Rails Prawn bounding_box font errorRails Prawn bounding_box字体错误
【发布时间】:2013-08-01 10:33:08
【问题描述】:

我正在尝试使用带有“Arial”字体的虾生成 pdf。我在继承的 Prawn::Document 类中完成所有这些工作。

我已经导入了arial字体:

font_families.update("Arial" => {
    :normal => { :file => "#{Rails.root}/app/assets/fonts/Arial.ttf", :font => "Arial" },
    :bold => { :file => "#{Rails.root}/app/assets/fonts/Arial_Bold.ttf", :font => "Arial_Bold" }
    })

font "Arial", size: 11 # use this font and size from now on

这可以正常工作,但只能在 bounding_boxes 之外。 bounding_box 内的文本与外部使用的字体无关。当我尝试在框中定义字体时,出现此错误:

 is not a known font.

bounding_box 是否能够自定义字体?谢谢!

【问题讨论】:

    标签: ruby-on-rails pdf fonts prawn


    【解决方案1】:

    这应该可行:

    font_families.update("Arial" => {
      :normal => "#{Rails.root}/app/assets/fonts/Arial.ttf",
      :bold => "#{Rails.root}/app/assets/fonts/Arial_Bold.ttf"
    })
    
    font "Arial", size: 11
    

    确保在开始边界框之前更新字体系列。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多