Avoid page breaks during tables in OrderPdf

This commit is contained in:
Patrick Gansterer 2021-02-08 01:07:23 +01:00
parent 9f2e630266
commit 26a91ec957

View file

@ -9,9 +9,9 @@ class OrderPdf < RenderPDF
end end
def nice_table(name, data, dimrows = []) def nice_table(name, data, dimrows = [])
down_or_page 25 name_options = {size: 10, style: :bold}
text name, size: 10, style: :bold name_height = height_of name, name_options
table data, width: bounds.width, cell_style: {size: 8, overflow: :shrink_to_fit} do |table| made_table = make_table data, width: bounds.width, cell_style: {size: 8, overflow: :shrink_to_fit} do |table|
# borders # borders
table.cells.borders = [:bottom] table.cells.borders = [:bottom]
table.cells.padding_top = 2 table.cells.padding_top = 2
@ -27,6 +27,15 @@ class OrderPdf < RenderPDF
yield table if block_given? yield table if block_given?
end end
if name_height + made_table.height < cursor
down_or_page 15
else
start_new_page
end
text name, name_options
made_table.draw
end end
protected protected