Created
February 18, 2011 07:49
-
-
Save 3dd13/833392 to your computer and use it in GitHub Desktop.
overflow / page break examples of Prawn Pdf generation.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# gem "prawn", "0.8.4" | |
# Sometime there is no enough space for the last table row when it reaches the end of page | |
Prawn::Document.generate("text_group_overflow_question.pdf") do |pdf| | |
add_page_break_if_overflow(pdf) do |pdf| | |
# generating table here | |
# ... | |
end | |
end | |
def add_page_break_if_overflow(pdf, &block) | |
current_page = pdf.page_count | |
roll = pdf.transaction do | |
yield(pdf) | |
pdf.rollback if pdf.page_count > current_page | |
end | |
if roll == false | |
pdf.start_new_page | |
yield(pdf) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# gem "prawn", "0.11.1.pre" | |
Prawn::Document.generate("text_group_overflow_question.pdf") do | |
10.times do | |
text "I am part of a paragraph" | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# gem "prawn", "0.11.1.pre" | |
Prawn::Document.generate("text_group_overflow_question.pdf") do | |
group do | |
10.times do | |
text "I am part of a paragraph" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@maurcarvalho http://prawnpdf.org/docs/0.11.1/Prawn/Document/Snapshot.html also see http://www.rubydoc.info/github/sandal/prawn/Prawn%2FDocument%2FSnapshot%3Atransaction#