class Prawn::Document

The ‘Prawn::Document` class is how you start creating a PDF document.

There are three basic ways you can instantiate PDF Documents in Prawn, they are through assignment, implicit block or explicit block. Below is an example of each type, each example does exactly the same thing, makes a PDF document with all the defaults and puts in the default font “Hello There” and then saves it to the current directory as example.pdf.

For example, assignment can be like this:

“‘ruby pdf = Prawn::Document.new pdf.text “Hello There” pdf.render_file “example.pdf” “`

Or you can do an implied block form:

“‘ruby Prawn::Document.generate “example.pdf” do

text "Hello There"

end “‘

Or if you need to access a variable outside the scope of the block, the explicit block form:

“‘ruby words = “Hello There” Prawn::Document.generate “example.pdf” do |pdf|

pdf.text words

end “‘

Usually, the block forms are used when you are simply creating a PDF document that you want to immediately save or render out.

See the {#initialize new} and {.generate generate} methods for further details on the above.