Théo Capdet
Théo Capdet

Reputation: 1062

Don't break paragraph when new page (Prawn)

Is there a way to keep text as a same block when a new page (don't break it). If it exists, what is the command?

I mean for example, I have a paragraph of five lines. When a new page starts I don't want two lines in the first page and three lines in the second page. I want the lines to stay together. Another way to do it : put the five lines in the second page.

Upvotes: 6

Views: 2481

Answers (4)

bonsai
bonsai

Reputation: 106

After group was removed I did it this way:

I get the height of the text block

height = pdf.height_of_formatted([{ :text => my_text, size: 14, style: :bold }])

And compare the height with the remaining space on the page. If there's no space for the whole text block, I start a new page before printing.

if pdf.cursor < height
  pdf.start_new_page
end

I know, this is more complicated than it was to create a simple group-block, but at least it works and can be altered to all kinds of situations and formattings.

Upvotes: 8

Th&#233;o Capdet
Th&#233;o Capdet

Reputation: 1062

This work too :

group do
   #Your code
end

Upvotes: -1

Igor Beaufils
Igor Beaufils

Reputation: 914

You could just do :

pdf.group do

  #Your code

end

Is that what you were looking for ??

Upvotes: 2

user3712956
user3712956

Reputation: 29

Im a newbie so dont take me seriously. But there seems to be these block text holders in prawn. You can make the borders invisible. So you put the text in one of the boxes and maybe it moves automatically to a new page if the whole box doesnt fit on the last page?

Upvotes: 2

Related Questions