Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 475
Théo Capdet Avatar asked Jul 29 '15 10:07

Théo Capdet


3 Answers

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.

like image 80
bonsai Avatar answered Nov 03 '22 03:11

bonsai


You could just do :

pdf.group do

  #Your code

end

Is that what you were looking for ??

like image 41
Igor Beaufils Avatar answered Nov 03 '22 03:11

Igor Beaufils


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?

like image 42
user3712956 Avatar answered Nov 03 '22 03:11

user3712956