1

我有以下简单的代码来生成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 位置。

4

1 回答 1

2

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

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

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

手册在第 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 页:

截屏

于 2017-07-03T11:43:32.213 回答