【问题标题】:Prawn: float text automatically to a new page大虾:自动将文本浮动到新页面
【发布时间】:2017-12-06 14:52:41
【问题描述】:

我有以下简单的代码来生成 pdf。

def employe_details
        y = cursor
bounding_box([0, y], :width => 16.cm) do
          @employe.each do |pr|
                txt = pr.week.to_s + ' '
                txt += "work hours"
                text_box txt, size: 11, :at => [0.5.cm, cursor]
                move_down 0.4.cm
            end
              .#more similar texts
              .
              .    
end

问题是,这不会自动创建新页面。当文本超过第一页时,其余文本根本不会显示,或者这些文本不会显示在新页面中。

当文本到达页面末尾时如何自动将文本浮动到新页面?

更新: 我的代码问题似乎与这一行 :at => [0.5.cm, cursor] 有关,如果我删除该位置然后它会流到下一页,当我使用 span 时也会发生同样的情况。如果我在跨度中使用带有文本的位置,那么它不会流到下一页,如果我删除它,它就会流到下一页。那么我该如何使用这样的东西

text_box txt, size: 11, :at => [0.5.cm]
text txt, size: 11, :at => [0.5.cm]

没有光标位置的文本框或文本,我需要使用 x 位置,因为每一行都有不同的 x 位置。

【问题讨论】:

标签: ruby-on-rails ruby prawn prawnto


【解决方案1】:

bounding_box 内容不会流到下一页。您可以改用span:(已添加重点)

span 是一个特殊用途的边界框,它允许一列元素相对于 margin_box 定位。

此方法通常用于将一列文本从一页流到下一页

manual 在第 35 页提到了这一点:

此示例还显示了在页边距之后跨页流动的文本 框和其他边界框。

# ...

move_cursor_to 200
span(350, :position => :center) do
    text "Span is a different kind of bounding box as it lets the text " +
         "flow gracefully onto the next page. It doesn't matter if the text " +
         "started on the middle of the previous page, when it flows to the " +
         "next page it will start at the beginning." + " _ " * 500 +
         "I told you it would start on the beginning of this page."
end

结果显示在第 37/38 页:

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-03-22
  • 1970-01-01
  • 1970-01-01
  • 2020-11-29
  • 1970-01-01
  • 2011-01-19
相关资源
最近更新 更多