当使用repeat(:all)时,Prawn似乎没有推动布局

我正在生成一个文档,其中包含流入每个后续页面的数据,每个页面都有一个标准标题。 但是,当我使用repeat(:all)将标题放在每个页面上时,我发现除了第一页之外的每个页面上,下一个内容都没有按照我放在页面上的标题横幅的大小向下移动。

我生成横幅的代码:

class SmartsoftPdf  40 draw_text text, :at => [80,25], :size => 12, :style => :bold, :color => BLUE draw_text "Date: #{ausDate(date)}", :at => [bounds.right - 100,bounds.top - 15], :size => 10 if date end end def header_box(&block) bounding_box([-bounds.absolute_left, cursor + BOX_MARGIN + 8], :width => bounds.absolute_left + bounds.absolute_right, :height => BOX_MARGIN*2) do fill_color LIGHT_GRAY fill_rectangle([bounds.left, bounds.top], bounds.right, bounds.top - bounds.bottom) fill_color BLACK move_down(RHYTHM) indent(BOX_MARGIN, &block) end stroke_color GRAY stroke_horizontal_line(-BOX_MARGIN, bounds.width + BOX_MARGIN, :at => cursor) stroke_color BLACK move_down(RHYTHM*4) end end 

然后在pdf生成本身内我做:

 repeat(:all) do show_header("Custom Report",DateTime.now()) end 

但是,当我开始将内容放到页面上时,我预计当内容溢出到下一页时,内容将显示在标题之后。 我发现标题重叠了内容。

这是一个说明问题的图像: http : //i.imgur.com/mSy2but.png

我是否错误地构建了标题框? 我是否需要做一些额外的工作才能使泄漏到下一页的内容被压缩到适当的数量?

好的。 我自己解决了这个问题。 最新版本的Prawn有更好的方法来处理这种情况。 当您使用repeat(:all)时,在创建文档后重新打开页面,然后添加内容创建项。 这不会推翻页面。 将此标头添加到每个页面的正确方法是使用“canvas”方法,该方法允许您在页边距的范围之外操作。 使用canvas在页面顶部绘制一个框,并设置页面的top_margin以推送横幅下方的所有内容。

 canvas do bounding_box([bounds.left,bounds.top], :width => bounds.absolute_left + bounds.absolute_right, :height => BOX_MARGIN*2) do fill_color LIGHT_GRAY fill_rectangle([bounds.left, bounds.top], bounds.right, bounds.top - bounds.bottom) fill_color BLACK move_down(RHYTHM) indent(BOX_MARGIN, &block) end stroke_color GRAY stroke_horizontal_line(-BOX_MARGIN, bounds.width + BOX_MARGIN, :at => cursor) stroke_color BLACK end 

在文件创建…

  def initialize(options = {}) super(:page_layout => :landscape,:top_margin => HEIGHT_OF_BANNER) end