Skip to content

Instantly share code, notes, and snippets.

@maveonair
Last active December 21, 2015 08:28
Show Gist options
  • Save maveonair/6278134 to your computer and use it in GitHub Desktop.
Save maveonair/6278134 to your computer and use it in GitHub Desktop.
Prawn PDF Export with page break for bounding_box
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