Last active
December 21, 2015 08:28
-
-
Save maveonair/6278134 to your computer and use it in GitHub Desktop.
Prawn PDF Export with page break for bounding_box
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
class PdfExport < Prawn::Document | |
def to_pdf | |
build_pdf | |
render | |
end | |
def build_pdf | |
add_page_break_if_overflow do | |
bounding_box([155, cursor - 25], :width => 330) do | |
# Put some PDF text here... | |
end | |
end | |
end | |
def add_page_break_if_overflow(&block) | |
roll = transaction do | |
yield(self) | |
rollback if bounds.bottom > cursor | |
end | |
unless roll | |
start_new_page | |
yield(self) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment