Using Ruby 2.4 and Prawn 2.2.0, I would like to place a block of content on the next page if it does not match the current page. I tried with a bounding box, because in this way the internal content may be what I want, but I do not achieve this.
I have the following document:
require 'prawn'
class Doc < Prawn::Document
def initialize(options: {})
super(options.merge(**page_options))
setup_page
header
body
footer
end
def header
bounding_box([0, cursor], width: bounds.width) do
bounding_box([0, bounds.top], width: bounds.width / 2) do
text 'Left Header', size: 36
end
bounding_box([bounds.width / 2, bounds.top], width: bounds.width / 2) do
text 'Right Header', size: 36
end
stroke_bounds
end
end
def body
bounding_box([0, cursor], width: bounds.width / 2) do
text 'The stack has overflowed over the overflow' * 12, size: 24
end
end
def footer
bounding_box([0, cursor], width: bounds.width) do
bounding_box([0, bounds.top], width: bounds.width / 2) do
text 'Left Footer' * 3, size: 36, color: '0000FF'
stroke_bounds
end
bounding_box([bounds.width / 2, bounds.top], width: bounds.width / 2) do
text 'Right Footer' * 3, size: 36, color: '0000FF'
stroke_bounds
end
end
end
def setup_page
define_grid(columns: 12, rows: 8, gutter: 10)
end
def page_options
{
page_size: ::PDF::Core::PageGeometry::SIZES['A4'],
page_layout: :portrait
}
end
end
Doc.new.render_file 'doc.pdf'
Since I want to have footer
on the same page, that is, without a page break, I need to check the height and see if it matches the current page, if not insert a page break.
The problem is that I have no way to create a bounding box for validation, and then draw it.
Or is there another way to ensure that content is not shared by providing it all on one page?