runub
runub

Reputation: 199

Prawn PDF: render a set of things on the same page

I am looking for a way to do the following

pdf.on_same_page do
   pdf.text "foo"
   pdf.imaage bar
   pdf.table(baz)
   ....
end

In other words, I am wanting to group several elements such that if the entire group can fit on the page, render it on the same page, otherwise page break and render it all on the next page (assuming the entire group can fit on a single page) how would such a thing be accomplished?

Upvotes: 3

Views: 1134

Answers (1)

Paulo Fidalgo
Paulo Fidalgo

Reputation: 22331

I've used a slightly different approach, but using tables.

footer_table = pdf.make_table(data) do
  cells.borders = []
  row(0).font_style = :bold
  row(2).font_style = :bold
end
pdf.start_new_page if (pdf.cursor - footer_table.height).negative?
footer_table.draw

Given pdf is the pdf document, I only put the table if it fits the page.

Upvotes: 2

Related Questions