Sha256: d181728535198555ccb3ea85db771d55af58fb47410249f6bf651c1702fa624e

Contents?: true

Size: 1.37 KB

Versions: 16

Compression:

Stored size: 1.37 KB

Contents

# encoding: utf-8
#
# There are three ways to create a PDF Document in Prawn: creating a new
# <code>Prawn::Document</code> instance, or using the
# <code>Prawn::Document.generate</code> method with and without block arguments.
#
# The following snippet showcase each way by creating a simple document with
# some text drawn.
#
# When we instantiate the <code>Prawn::Document</code> object the actual pdf
# document will only be created after we call <code>render_file</code>.
#
# The generate method will render the actual pdf object after exiting the block.
# When we use it without a block argument the provided block is evaluated in the
# context of a newly created <code>Prawn::Document</code> instance. When we use
# it with a block argument a <code>Prawn::Document</code> instance is created
# and passed to the block.
#
# The generate method without block arguments requires
# less typing and defines and renders the pdf document in one shot.
# Almost all of the examples are coded this way.
#
require File.expand_path(File.join(File.dirname(__FILE__),
                                   %w[.. example_helper]))

# Assignment
pdf = Prawn::Document.new
pdf.text "Hello World"
pdf.render_file "assignment.pdf"

# Implicit Block
Prawn::Document.generate("implicit.pdf") do
  text "Hello World"
end

# Explicit Block
Prawn::Document.generate("explicit.pdf") do |pdf|
  pdf.text "Hello World"
end

Version data entries

16 entries across 16 versions & 3 rubygems

Version Path
prawn-2.1.0 manual/basic_concepts/creation.rb
prawn-git-2.0.1 manual/basic_concepts/creation.rb
prawn-2.0.2 manual/basic_concepts/creation.rb
prawn-2.0.1 manual/basic_concepts/creation.rb
prawn-2.0.0 manual/basic_concepts/creation.rb
prawn-1.3.0 manual/basic_concepts/creation.rb
prawn-1.2.1 manual/basic_concepts/creation.rb
prawn-1.1.0 manual/basic_concepts/creation.rb
prawn-1.0.0 manual/basic_concepts/creation.rb
prawn-0.15.0 manual/basic_concepts/creation.rb
prawn-0.14.0 manual/basic_concepts/creation.rb
prawn-0.13.2 manual/basic_concepts/creation.rb
prawn-0.13.1 manual/basic_concepts/creation.rb
prawn-0.13.0 manual/basic_concepts/creation.rb
prawn-1.0.0.rc2 manual/basic_concepts/creation.rb
nurettin-prawn-1.0.0.rc1 manual/basic_concepts/creation.rb