我正在使用 Prawn.rb 生成 pdf 并遇到一个问题:
我在每个页面上都有一个标题,当我使用 span 时,span 中的文本将会流动到下一页并与页眉重叠,但如果我使用 bounding_box,其中的文本将从 bounding_box 从文本流到下一页的时间开始。
这是我的标题:
repeat(:all) do
transparent(0.5) do
bounding_box [bounds.left, bounds.top], :width =>
bounds.width do
image "#{Rails.root}/app/assets/images/logo-of-
nextcode.png", height: 20
move_down 2
stroke_horizontal_rule
end
bounding_box [bounds.left, bounds.bottom + 50], :width => bounds.width do
text_box 'PRIVATE & CONFIDENTIAL', align: :center, valign: :bottom, size: 10
end
end
这是长文本:
span(bounds.width) do
object.actions.each_with_index do |a, i|
text "#{i + 1}. Description: #{a.message}"
text_box "Expected Completion Date: #{a.expected_completion_time&.strftime('%F')}", at: [0, cursor]
move_down 15
text_box "Actual Completion Date: #{a.actual_completion_time&.strftime('%F')}", at: [0, cursor]
move_down 20
end
end
我的问题是:如果使用 span 如何避免与标题重叠以及如果使用 如何避免标题和文本之间的大空白行>边界框 ?
最佳答案
尝试将您的 header 放入canvas
repeat(:all) do
canvas do
transparent(0.5) do
bounding_box [bounds.left, bounds.top], :width =>
bounds.width do
image "#{Rails.root}/app/assets/images/logo-of-
nextcode.png", height: 20
move_down 2
stroke_horizontal_rule
end
bounding_box [bounds.left, bounds.bottom + 50], :width => bounds.width do
text_box 'PRIVATE & CONFIDENTIAL', align: :center, valign: :bottom, size: 10
end
end
end
关于ruby-on-rails - 文本流到下一页与 Prawn 的标题重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46971220/