在rails应用程序上使用Prawn gem,在每个页面上使用当前页面和总页数重复页脚,但获取重叠的当前页码

时间:2015-06-24 06:41:06

标签: ruby-on-rails header footer prawn overlapping

这是我的代码

repeat :all do
  # footer
  bounding_box [bounds.left, bounds.bottom + 35], :width  => bounds.width do
    font "Helvetica"
    move_down(15)
    number_pages "Page <page> of <total>",
                 { :start_count_at => 1, :page_filter => :all,:at => [bounds.right - 50, 0],
                   :align => :right,
                   :size => 8}
  end
end

并且当前的错误结果是当前页码的重叠,例如2&#34;和#34;它们之间的重叠(1和2重叠)。 ...但是在最后一页结果就像&#34; Page 2 of 2&#34;这是正确的

1 个答案:

答案 0 :(得分:4)

解决方案是使用canvas而不是repeat:all

以下是工作解决方案:

canvas do
  bounding_box [bounds.left, bounds.bottom + 50], :width  => bounds.width do
    font "Helvetica"
    move_down(15)
    number_pages "Page <page> of <total>",
                 { :start_count_at => 1, :page_filter => :all,:at => [bounds.right - 70, 10],
                   :size => 8}
    move_down(8)
    number_pages "This is an automatically generated certificate from BlaBla (blabla.com)", :size => 8, :align => :center,:at => [0, 0]
    number_pages "Downloaded on #{Date.today.to_formatted_s(:long)} by #{@user.full_name}", :size => 8, :align => :center,:at => [0, 10]
  end
end