forked from prawnpdf/prawn
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:sandal/prawn
- Loading branch information
Showing
31 changed files
with
636 additions
and
71 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
$LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib') | ||
require 'rubygems' | ||
require 'bundler' | ||
require 'prawn' | ||
Bundler.require | ||
|
||
## | ||
# When this is fixed then Testing should appear with normal default black color in Acrobat reader | ||
|
||
Prawn::Document.generate("looks_blank.pdf") do | ||
|
||
repeat :all do | ||
text "Testing", :size => 24, :style => :bold | ||
end | ||
|
||
fill_color '662255' | ||
|
||
end |
Binary file not shown.
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# encoding: utf-8 | ||
# | ||
# Another group of helpers for changing the cursor position are the pad methods. | ||
# They accept a numeric value and a block. <code>pad</code> will use the numeric | ||
# value to move the cursor down both before and after the block content. | ||
# <code>pad_top</code> will only move the cursor before the block while | ||
# <code>pad_bottom</code> will only move after. | ||
# | ||
# <code>float</code> is a method for not changing the cursor. Pass it a block | ||
# and the cursor will remain on the same place when the block returns. | ||
# | ||
require File.expand_path(File.join(File.dirname(__FILE__), | ||
%w[.. example_helper])) | ||
|
||
filename = File.basename(__FILE__).gsub('.rb', '.pdf') | ||
Prawn::Example.generate(filename) do | ||
stroke_horizontal_rule | ||
pad(20) { text "Text padded both before and after." } | ||
|
||
stroke_horizontal_rule | ||
pad_top(20) { text "Text padded on the top." } | ||
|
||
stroke_horizontal_rule | ||
pad_bottom(20) { text "Text padded on the bottom." } | ||
|
||
stroke_horizontal_rule | ||
move_down 50 | ||
|
||
text "Text written before the float block." | ||
|
||
float do | ||
move_down 50 | ||
bounding_box [0, cursor], :width => 200 do | ||
text "Text written inside the float block." | ||
stroke_bounds | ||
end | ||
end | ||
|
||
text "Text written after the float block." | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,9 +13,10 @@ | |
], | ||
[ "Advanced", [ "stretchy", | ||
"nesting", | ||
"indentation" | ||
"indentation", | ||
"canvas" | ||
] | ||
], | ||
] | ||
] | ||
|
||
) do | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# encoding: utf-8 | ||
# | ||
# The origin example already mentions that a new document already comes with | ||
# a margin box whose bottom left corner is used as the origin for calculating | ||
# coordinates. | ||
# | ||
# What has not been told is that there is one helper for "bypassing" the margin | ||
# box: <code>canvas</code>. This method is a shortcut for creating a bounding | ||
# box mapped to the absolute coordinates and evaluating the code inside it. | ||
# | ||
# The following snippet draws a circle on each of the four absolute corners. | ||
# | ||
require File.expand_path(File.join(File.dirname(__FILE__), | ||
%w[.. example_helper])) | ||
|
||
filename = File.basename(__FILE__).gsub('.rb', '.pdf') | ||
Prawn::Example.generate(filename) do | ||
canvas do | ||
fill_circle_at [bounds.left, bounds.top], :radius => 30 | ||
fill_circle_at [bounds.right, bounds.top], :radius => 30 | ||
fill_circle_at [bounds.right, bounds.bottom], :radius => 30 | ||
fill_circle_at [0, 0], :radius => 30 | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# encoding: utf-8 | ||
# | ||
# This option can only be used on document creation. Pass an image path to the | ||
# <code>:image</code> option and it will be used as the background for all | ||
# pages. | ||
# | ||
require File.expand_path(File.join(File.dirname(__FILE__), | ||
%w[.. example_helper])) | ||
|
||
img = "#{Prawn::BASEDIR}/data/images/letterhead.jpg" | ||
|
||
Prawn::Document.generate("background.pdf", | ||
:background => img, | ||
:margin => 100 | ||
) do | ||
text "My report caption", :size => 18, :align => :right | ||
|
||
move_down font.height * 2 | ||
|
||
text "Here is my text explaning this report. " * 20, | ||
:size => 12, :align => :left, :leading => 2 | ||
|
||
move_down font.height | ||
|
||
text "I'm using a soft background. " * 40, | ||
:size => 12, :align => :left, :leading => 2 | ||
end |
27 changes: 27 additions & 0 deletions
27
manual/document_and_page_options/document_and_page_options.rb
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# encoding: utf-8 | ||
# | ||
# Examples for stamps and repeaters. | ||
# | ||
require File.expand_path(File.join(File.dirname(__FILE__), | ||
%w[.. example_helper])) | ||
|
||
Prawn::Example.generate("document_and_page_options.pdf") do | ||
build_package("document_and_page_options", [ | ||
{:name => "page_size", :eval_source => false, :full_source => true}, | ||
{:name => "page_margins", :eval_source => false, :full_source => true}, | ||
{:name => "background", :eval_source => false, :full_source => true}, | ||
{:name => "metadata", :eval_source => false, :full_source => true} | ||
] | ||
|
||
) do | ||
text "So far we've already seen how to create new documents and start new pages. This chapter expands on the previous examples by showing the options avialable. Some of the options are only available when creating new documents. | ||
The examples show:" | ||
|
||
list( "How to configure page size", | ||
"How to configure page margins", | ||
"How to use a background image", | ||
"How to add metadata to the generated 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# encoding: utf-8 | ||
# | ||
# To set the document metadata just pass a hash to the <code>:info</code> | ||
# option when creating new documents. | ||
# | ||
require File.expand_path(File.join(File.dirname(__FILE__), | ||
%w[.. example_helper])) | ||
|
||
Prawn::Document.generate("metadata.pdf", | ||
:info => { | ||
:Title => "My title", | ||
:Author => "John Doe", | ||
:Subject => "My Subject", | ||
:Keywords => "test metadata ruby pdf dry", | ||
:Creator => "ACME Soft App", | ||
:Producer => "Prawn", | ||
:CreationDate => Time.now, | ||
:Grok => "Test Property" | ||
}) do | ||
|
||
text "This is a test of setting metadata properties via the info option." | ||
text "It allows one to specify no standard properties like 'Grok'." | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# encoding: utf-8 | ||
# | ||
# The default margin for pages is 0.5 inch but you can change that with the | ||
# <code>:margin</code> option or if you'd like to have different margins you | ||
# can use the <code>:left_margin</code>, <code>:right_margin</code>, | ||
# <code>:top_margin</code>, <code>:bottom_margin</code> options. | ||
# | ||
# These options are available both for starting new pages and creating new | ||
# documents. | ||
# | ||
require File.expand_path(File.join(File.dirname(__FILE__), | ||
%w[.. example_helper])) | ||
|
||
Prawn::Document.generate("page_margins.pdf", | ||
:margin => 100 | ||
) do | ||
text "100 pts margins." | ||
stroke_bounds | ||
|
||
start_new_page(:left_margin => 300) | ||
text "300 pts margin on the left." | ||
stroke_bounds | ||
|
||
start_new_page(:top_margin => 300) | ||
text "300 pts margin both on the top and on the left. Notice that whenever " + | ||
"you set an option for a new page it will remain the default for the " + | ||
"following pages." | ||
stroke_bounds | ||
|
||
start_new_page(:margin => 50) | ||
text "50 pts margins. Using the margin option will reset previous specific " + | ||
"calls to left, right, top and bottom margins." | ||
stroke_bounds | ||
|
||
start_new_page(:margin => [50, 100, 150, 200]) | ||
text "There is also the shorthand CSS like syntax used here." | ||
stroke_bounds | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# encoding: utf-8 | ||
# | ||
# Prawn comes with support for most of the common page sizes so you'll only need | ||
# to provide specific values if your intended format is not supported. To see a | ||
# list with all supported sizes take a look at: https://github.com/sandal/prawn/blob/master/lib/prawn/document/page_geometry.rb | ||
# | ||
# To define the size use <code>:page_size</code> when creating new documents | ||
# and <code>:size</code> when starting new pages. The default page size for new | ||
# documents is LETTER (612.00 x 792.00). | ||
# | ||
# You may also define the orientation of the page to be either portrait | ||
# (default) or landscape. Use <code>:page_layout</code> when creating new | ||
# documents and <code>:layout</code> when starting new pages. | ||
# | ||
require File.expand_path(File.join(File.dirname(__FILE__), | ||
%w[.. example_helper])) | ||
|
||
Prawn::Document.generate("page_size.pdf", | ||
:page_size => "EXECUTIVE", | ||
:page_layout => :landscape | ||
) do | ||
text "EXECUTIVE landscape page." | ||
|
||
custom_size = [275, 326] | ||
|
||
["A4", "TABLOID", "B7", custom_size ].each do |size| | ||
|
||
start_new_page(:size => size, :layout => :portrait) | ||
text "#{size} portrait page." | ||
|
||
start_new_page(:size => size, :layout => :landscape) | ||
text "#{size} landscape page." | ||
end | ||
end |
Oops, something went wrong.