prawn 0.11.1 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/GPLv2 +340 -0
- data/GPLv3 +674 -0
- data/README.md +96 -0
- data/Rakefile +0 -12
- data/examples/example_helper.rb +3 -0
- data/lib/prawn.rb +1 -1
- data/lib/prawn/core/page.rb +4 -2
- data/lib/prawn/core/pdf_object.rb +7 -7
- data/lib/prawn/core/text/formatted/arranger.rb +2 -1
- data/lib/prawn/core/text/formatted/line_wrap.rb +2 -1
- data/lib/prawn/core/text/formatted/wrap.rb +5 -1
- data/lib/prawn/document.rb +135 -112
- data/lib/prawn/document/bounding_box.rb +51 -5
- data/lib/prawn/document/column_box.rb +0 -19
- data/lib/prawn/document/internals.rb +1 -0
- data/lib/prawn/document/snapshot.rb +3 -0
- data/lib/prawn/font.rb +4 -3
- data/lib/prawn/font/afm.rb +11 -2
- data/lib/prawn/font/ttf.rb +15 -0
- data/lib/prawn/images.rb +1 -1
- data/lib/prawn/table.rb +23 -7
- data/lib/prawn/table/cell.rb +31 -9
- data/lib/prawn/table/cell/text.rb +2 -2
- data/prawn.gemspec +5 -6
- data/spec/bounding_box_spec.rb +157 -0
- data/spec/data/curves.pdf +66 -0
- data/spec/document_spec.rb +59 -4
- data/spec/extensions/mocha.rb +1 -3
- data/spec/font_spec.rb +23 -0
- data/spec/formatted_text_box_spec.rb +40 -0
- data/spec/images_spec.rb +7 -0
- data/spec/object_store_spec.rb +3 -3
- data/spec/snapshot_spec.rb +33 -0
- data/spec/table_spec.rb +75 -0
- data/spec/template_spec.rb +11 -5
- data/spec/text_spacing_spec.rb +18 -0
- data/spec/text_spec.rb +32 -0
- metadata +217 -283
- data/HACKING +0 -50
- data/README +0 -141
- data/examples/bounding_box/bounding_boxes.rb +0 -44
- data/examples/bounding_box/indentation.rb +0 -35
- data/examples/bounding_box/stretched_nesting.rb +0 -68
- data/examples/general/background.rb +0 -24
- data/examples/general/canvas.rb +0 -16
- data/examples/general/float.rb +0 -12
- data/examples/general/margin.rb +0 -37
- data/examples/general/measurement_units.rb +0 -52
- data/examples/general/metadata-info.rb +0 -17
- data/examples/general/multi_page_layout.rb +0 -19
- data/examples/general/outlines.rb +0 -67
- data/examples/general/page_geometry.rb +0 -32
- data/examples/general/page_numbering.rb +0 -40
- data/examples/general/page_templates.rb +0 -20
- data/examples/general/repeaters.rb +0 -48
- data/examples/general/stamp.rb +0 -42
- data/examples/general/templates.rb +0 -14
- data/examples/graphics/basic_images.rb +0 -24
- data/examples/graphics/curves.rb +0 -12
- data/examples/graphics/hexagon.rb +0 -14
- data/examples/graphics/image_fit.rb +0 -16
- data/examples/graphics/image_flow.rb +0 -38
- data/examples/graphics/image_position.rb +0 -18
- data/examples/graphics/line.rb +0 -33
- data/examples/graphics/polygons.rb +0 -17
- data/examples/graphics/rounded_polygons.rb +0 -20
- data/examples/graphics/rounded_rectangle.rb +0 -21
- data/examples/graphics/ruport_style_helpers.rb +0 -20
- data/examples/graphics/stroke_bounds.rb +0 -21
- data/examples/graphics/stroke_cap_and_join.rb +0 -46
- data/examples/graphics/stroke_dash.rb +0 -43
- data/examples/graphics/transformations.rb +0 -53
- data/examples/graphics/transparency.rb +0 -27
- data/examples/grid/bounding_boxes.rb +0 -22
- data/examples/grid/column_gutter_grid.rb +0 -21
- data/examples/grid/multi_boxes.rb +0 -52
- data/examples/grid/show_grid.rb +0 -14
- data/examples/grid/simple_grid.rb +0 -21
- data/examples/m17n/chinese_text_wrapping.rb +0 -18
- data/examples/m17n/euro.rb +0 -16
- data/examples/m17n/utf8.rb +0 -14
- data/examples/security/hello_foo.rb +0 -9
- data/examples/table/borders.rb +0 -25
- data/examples/table/cell.rb +0 -13
- data/examples/table/checkerboard.rb +0 -23
- data/examples/table/inline_format_table.rb +0 -13
- data/examples/table/multi_page_table.rb +0 -10
- data/examples/table/simple_table.rb +0 -25
- data/examples/table/subtable.rb +0 -13
- data/examples/table/widths.rb +0 -21
- data/examples/text/alignment.rb +0 -19
- data/examples/text/character_spacing.rb +0 -13
- data/examples/text/dfont.rb +0 -49
- data/examples/text/family_based_styling.rb +0 -25
- data/examples/text/font_size.rb +0 -34
- data/examples/text/inline_format.rb +0 -104
- data/examples/text/kerning.rb +0 -31
- data/examples/text/rendering_mode.rb +0 -21
- data/examples/text/rotated.rb +0 -99
- data/examples/text/shaped_text_box.rb +0 -32
- data/examples/text/simple_text.rb +0 -18
- data/examples/text/simple_text_ttf.rb +0 -18
- data/examples/text/span.rb +0 -30
- data/examples/text/text_box.rb +0 -90
- data/examples/text/text_box_returning_excess.rb +0 -52
- data/examples/text/text_flow.rb +0 -68
data/HACKING
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
= Hacking on Prawn
|
2
|
-
|
3
|
-
While we hope to have more extensive documentation for contributors in time, for
|
4
|
-
now, here is the bare minimum to get you up and running
|
5
|
-
|
6
|
-
== NOTES
|
7
|
-
|
8
|
-
Install test-spec, pdf-reader, and mocha from RubyGems
|
9
|
-
|
10
|
-
Be sure to load in the necessary git submodules as well:
|
11
|
-
|
12
|
-
git submodule init
|
13
|
-
git submodule update
|
14
|
-
|
15
|
-
If you are running on Ruby 1.9, you will need Test::Unit 1.2.3:
|
16
|
-
|
17
|
-
gem install test-unit -v 1.2.3
|
18
|
-
|
19
|
-
== Patch process
|
20
|
-
|
21
|
-
1. File a ticket in the bug tracker describing a defect or feature
|
22
|
-
|
23
|
-
http://github.com/sandal/prawn/issues
|
24
|
-
|
25
|
-
2. Fork us on Github, make your changes. Bug fixes or tiny enhancements can
|
26
|
-
be done on your master branch, everything else should be done on its own topic
|
27
|
-
branch.
|
28
|
-
|
29
|
-
3. Post a comment to the ticket telling us where your fork is, and what
|
30
|
-
patches we should be looking at.
|
31
|
-
|
32
|
-
If you are working on a ticket that has already been created, skip step 1.
|
33
|
-
|
34
|
-
All feature enhancements should come with an example in the examples/ dir,
|
35
|
-
and preferably, some specs.
|
36
|
-
|
37
|
-
All bug reports should have a reproducible example in bugs/ and preferably,
|
38
|
-
some specs.
|
39
|
-
|
40
|
-
== Support
|
41
|
-
|
42
|
-
Find us in #prawn on irc.freenode.net
|
43
|
-
<sandal> - Gregory Brown
|
44
|
-
<yob> - James Healy
|
45
|
-
<bluejade> - Daniel Nelson
|
46
|
-
<bradediger> - Brad Ediger
|
47
|
-
<jonsgreen> - Jonathan Greenberg
|
48
|
-
|
49
|
-
Otherwise, use the mailing list:
|
50
|
-
http://groups.google.com/group/prawn-ruby
|
data/README
DELETED
@@ -1,141 +0,0 @@
|
|
1
|
-
= Prawn: Fast, Nimble PDF Generation For Ruby
|
2
|
-
|
3
|
-
Prawn is a PDF writing library for Ruby designed to be tiny, fast, and nimble,
|
4
|
-
just like the majestic sea creature.
|
5
|
-
|
6
|
-
Development on this library was initially made possible thanks to
|
7
|
-
the many people who donated to the Ruby Mendicant project:
|
8
|
-
http://rubymendicant.wikidot.com
|
9
|
-
|
10
|
-
The project is currently maintained by Gregory Brown, with lots of help from
|
11
|
-
Prawn's core developers and the community.
|
12
|
-
|
13
|
-
== Quick Start
|
14
|
-
|
15
|
-
Getting started with Prawn can be as simple as:
|
16
|
-
|
17
|
-
require 'prawn'
|
18
|
-
pdf = Prawn::Document.new
|
19
|
-
pdf.text("Prawn Rocks")
|
20
|
-
pdf.render_file('prawn.pdf')
|
21
|
-
|
22
|
-
But prawn can do a lot more:
|
23
|
-
|
24
|
-
===Any page size you can think of
|
25
|
-
|
26
|
-
Prawn::Document.new('A0')
|
27
|
-
|
28
|
-
...gives you an _really_ big page.
|
29
|
-
|
30
|
-
Prawn::Document.new(:page_size => [11.32, 8.49],
|
31
|
-
:page_layout => :portrait)
|
32
|
-
|
33
|
-
...giving you a postage stamp.
|
34
|
-
|
35
|
-
{Learn more}[link:classes/Prawn/Document.html]
|
36
|
-
|
37
|
-
===Multiple Font Handling with UTF-8 Support
|
38
|
-
|
39
|
-
pdf.text("Prawn Rocks")
|
40
|
-
pdf.font("/myfont.ttf")
|
41
|
-
pdf.text("Prawn still rocks in a different font")
|
42
|
-
|
43
|
-
...allowing you to use any font you want.
|
44
|
-
|
45
|
-
{Learn more}[link:classes/Prawn/Font.html]
|
46
|
-
|
47
|
-
===Drawing graphics directly into the page
|
48
|
-
|
49
|
-
Simple shapes:
|
50
|
-
|
51
|
-
pdf.stroke do
|
52
|
-
pdf.circle_at [100,100], :radius => 25
|
53
|
-
pdf.rectangle [300,300], 100, 200
|
54
|
-
end
|
55
|
-
|
56
|
-
(note, you need to stroke the path to put "ink" there)
|
57
|
-
|
58
|
-
{Learn more}[link:classes/Prawn/Graphics.html]
|
59
|
-
|
60
|
-
===Embedding JPEG and PNG Images Natively
|
61
|
-
|
62
|
-
Reading an image directly from a file:
|
63
|
-
|
64
|
-
prawn_logo = "#{Prawn::BASEDIR}/data/images/prawn_logo.png"
|
65
|
-
pdf.image prawn_logo, :at => [50,450], :width => 450
|
66
|
-
|
67
|
-
Or reading it from an IO stream:
|
68
|
-
|
69
|
-
require "open-uri"
|
70
|
-
pdf.image open("http://prawn.majesticseacreature.com/media/prawn_logo.png")
|
71
|
-
|
72
|
-
{Learn more}[link:classes/Prawn/Images.html]
|
73
|
-
|
74
|
-
===Measurement Conversion Tools for Your Sanity
|
75
|
-
|
76
|
-
Prawn deals exclusively in PDF points... which work out to about 2.83464567mm...
|
77
|
-
don't try and do it in your head, instead, let Prawn help you:
|
78
|
-
|
79
|
-
require "prawn/measurement_extensions"
|
80
|
-
|
81
|
-
Prawn::Document.generate(:page_layout => :portrait,
|
82
|
-
:left_margin => 10.mm, # different
|
83
|
-
:right_margin => 1.cm, # units
|
84
|
-
:top_margin => 0.1.dm, # work
|
85
|
-
:bottom_margin => 0.01.m, # well
|
86
|
-
:page_size => 'A4') do
|
87
|
-
text "Prawn Rocks"
|
88
|
-
end
|
89
|
-
|
90
|
-
{Learn more}[link:classes/Prawn/Measurements.html]
|
91
|
-
|
92
|
-
===Document Security, Permissions, and Encryption
|
93
|
-
|
94
|
-
See examples/security/ for example code, such as this:
|
95
|
-
|
96
|
-
require 'prawn/security'
|
97
|
-
|
98
|
-
Prawn::Document.generate("hello_foo.pdf") do
|
99
|
-
text "Hello, world!"
|
100
|
-
encrypt_document :user_password => 'foo', :owner_password => 'bar',
|
101
|
-
:permissions => { :print_document => false }
|
102
|
-
end
|
103
|
-
|
104
|
-
This creates a document that requires the password 'foo' to be opened,
|
105
|
-
and cannot be printed without entering the owner password 'bar'.
|
106
|
-
|
107
|
-
If you want to prohibit most anyone from performing a certain activity, you can
|
108
|
-
pass :owner_password => :random to generate a probably-unguessable owner
|
109
|
-
password.
|
110
|
-
|
111
|
-
== Resources
|
112
|
-
|
113
|
-
=== Examples:
|
114
|
-
|
115
|
-
http://github.com/sandal/prawn/tree/stable/examples
|
116
|
-
|
117
|
-
=== Bug Tracker:
|
118
|
-
|
119
|
-
http://github.com/sandal/prawn/issues
|
120
|
-
|
121
|
-
=== Source Code:
|
122
|
-
|
123
|
-
http://github.com/sandal/prawn
|
124
|
-
|
125
|
-
=== Mailing List:
|
126
|
-
|
127
|
-
http://groups.google.com/group/prawn-ruby
|
128
|
-
|
129
|
-
=== IRC:
|
130
|
-
|
131
|
-
Find us in #prawn on irc.freenode.net
|
132
|
-
Gregory Brown: <sandal>
|
133
|
-
James Healy: <yob>
|
134
|
-
Brad Ediger: <bradediger>
|
135
|
-
Daniel Nelson: <bluejade>
|
136
|
-
Jonathan Greenberg: <jonsgreen>
|
137
|
-
|
138
|
-
== Notes to Developers:
|
139
|
-
|
140
|
-
See HACKING file for details on getting set up with a local build.
|
141
|
-
|
@@ -1,44 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
#
|
3
|
-
# This example demonstrates the basic functionality of Prawn's bounding boxes.
|
4
|
-
# Note that top level bounding boxes are positioned relative to the margin_box.
|
5
|
-
#
|
6
|
-
require File.expand_path(File.join(File.dirname(__FILE__),
|
7
|
-
%w[.. example_helper]))
|
8
|
-
|
9
|
-
Prawn::Document.generate("bounding_boxes.pdf") do
|
10
|
-
|
11
|
-
# Generates a box with a top-left of [100,600] and a top-right of [300,600]
|
12
|
-
# The box automatically expands as the cursor moves down the page. Notice
|
13
|
-
# that the final coordinates are outlined by a top and bottom line drawn
|
14
|
-
# relatively using calculations from +bounds+.
|
15
|
-
#
|
16
|
-
bounding_box [100,600], :width => 200 do
|
17
|
-
move_down 10
|
18
|
-
text "The rain in spain falls mainly on the plains " * 5
|
19
|
-
move_down 20
|
20
|
-
stroke do
|
21
|
-
line bounds.top_left, bounds.top_right
|
22
|
-
line bounds.bottom_left, bounds.bottom_right
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
# Generates a bounding box from [100, cursor], [300, cursor - 200],
|
27
|
-
# where cursor is the current y position.
|
28
|
-
#
|
29
|
-
bounding_box [100,cursor], :width => 200, :height => 200 do
|
30
|
-
stroke do
|
31
|
-
circle [100,100], 100
|
32
|
-
line bounds.top_left, bounds.bottom_right
|
33
|
-
line bounds.top_right, bounds.bottom_left
|
34
|
-
end
|
35
|
-
|
36
|
-
# Generates a nested bonding box and strokes its boundaries. Note that
|
37
|
-
# this box is anchored relative to its parent bounding box, not the
|
38
|
-
# margin_box
|
39
|
-
bounding_box [50,150], :width => 100, :height => 100 do
|
40
|
-
stroke_bounds
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
#
|
3
|
-
# This example demonstrates the basic functionality of Prawn's bounding boxes.
|
4
|
-
# Note that top level bounding boxes are positioned relative to the margin_box.
|
5
|
-
#
|
6
|
-
require File.expand_path(File.join(File.dirname(__FILE__),
|
7
|
-
%w[.. example_helper]))
|
8
|
-
|
9
|
-
Prawn::Document.generate("indentation.pdf") do
|
10
|
-
|
11
|
-
text "No indentation"
|
12
|
-
indent(20) do
|
13
|
-
text "Some indentation"
|
14
|
-
# Generates a box with a top-left of [100,600] and a top-right of [300,600]
|
15
|
-
# The box automatically expands as the cursor moves down the page. Notice
|
16
|
-
# that the final coordinates are outlined by a top and bottom line drawn
|
17
|
-
# relatively using calculations from +bounds+.
|
18
|
-
#
|
19
|
-
bounding_box [100,600], :width => 200 do
|
20
|
-
text "A little more indentation"
|
21
|
-
indent(20) do
|
22
|
-
text "And some more indentation"
|
23
|
-
indent(20) do
|
24
|
-
text "And some deeper indentation"
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
text "Some indentation"
|
29
|
-
end
|
30
|
-
indent(10) do
|
31
|
-
text "A bit of indentation"
|
32
|
-
end
|
33
|
-
|
34
|
-
text "No indentation"
|
35
|
-
end
|
@@ -1,68 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
#
|
3
|
-
# This example demonstrates how nested bounding boxes work when the outer box is
|
4
|
-
# stretchy and includes several inner boxes of different sizes.
|
5
|
-
|
6
|
-
require File.expand_path(File.join(File.dirname(__FILE__),
|
7
|
-
%w[.. example_helper]))
|
8
|
-
|
9
|
-
Prawn::Document.generate("stretched_nesting.pdf", :page_layout => :landscape) do
|
10
|
-
|
11
|
-
def stroke_dashed_bounds
|
12
|
-
dash(1)
|
13
|
-
stroke_bounds
|
14
|
-
undash
|
15
|
-
end
|
16
|
-
|
17
|
-
bounding_box [100,400], :width => 500 do
|
18
|
-
|
19
|
-
bounding_box [0, bounds.top], :width => 200, :height => 100 do
|
20
|
-
stroke_bounds
|
21
|
-
end
|
22
|
-
|
23
|
-
bounding_box [200, bounds.top], :width => 150 do
|
24
|
-
indent(5) do
|
25
|
-
text "This box is longest, so it stretches the parent box. \n"*5
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
bounding_box [350, bounds.top], :width => 150 do
|
30
|
-
text "I AM SANTA CLAUS!!!"
|
31
|
-
end
|
32
|
-
|
33
|
-
stroke_dashed_bounds
|
34
|
-
|
35
|
-
end
|
36
|
-
|
37
|
-
bounding_box [100, 250], :width => 500 do
|
38
|
-
|
39
|
-
bounding_box [0, bounds.top], :width => 100, :height => 100 do
|
40
|
-
text "1"
|
41
|
-
stroke_bounds
|
42
|
-
end
|
43
|
-
|
44
|
-
bounding_box [125, bounds.top], :width => 50, :height => 25 do
|
45
|
-
text "2"
|
46
|
-
stroke_bounds
|
47
|
-
end
|
48
|
-
|
49
|
-
bounding_box [200, bounds.top - 50], :width => 50, :height => 125 do
|
50
|
-
text "3"
|
51
|
-
stroke_bounds
|
52
|
-
end
|
53
|
-
|
54
|
-
bounding_box [350, bounds.top - 100], :width => 20, :height => 20 do
|
55
|
-
text "4"
|
56
|
-
stroke_bounds
|
57
|
-
end
|
58
|
-
|
59
|
-
bounding_box [400, bounds.height - 150], :width => 100, :height => 100 do
|
60
|
-
text "5"
|
61
|
-
stroke_bounds
|
62
|
-
end
|
63
|
-
|
64
|
-
stroke_dashed_bounds
|
65
|
-
|
66
|
-
end
|
67
|
-
|
68
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
#
|
3
|
-
# This example demonstrates the use of the new :background option when
|
4
|
-
# generating a new Document. Image is assumed to be pre-fit for your page
|
5
|
-
# size, and will not be rescaled.
|
6
|
-
#
|
7
|
-
require File.expand_path(File.join(File.dirname(__FILE__),
|
8
|
-
%w[.. example_helper]))
|
9
|
-
|
10
|
-
img = "#{Prawn::BASEDIR}/data/images/letterhead.jpg"
|
11
|
-
|
12
|
-
Prawn::Document.generate("background.pdf", :background => img, :margin => 100) do
|
13
|
-
text "My report caption", :size => 18, :align => :right
|
14
|
-
|
15
|
-
move_down font.height * 2
|
16
|
-
|
17
|
-
text "Here is my text explaning this report. " * 20,
|
18
|
-
:size => 12, :align => :left, :leading => 2
|
19
|
-
|
20
|
-
move_down font.height
|
21
|
-
|
22
|
-
text "I'm using a soft background. " * 40,
|
23
|
-
:size => 12, :align => :left, :leading => 2
|
24
|
-
end
|
data/examples/general/canvas.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
#
|
3
|
-
# Demonstrates how to enable absolute positioning in Prawn by temporarily
|
4
|
-
# removing the margin_box via Document#canvas()
|
5
|
-
#
|
6
|
-
require File.expand_path(File.join(File.dirname(__FILE__),
|
7
|
-
%w[.. example_helper]))
|
8
|
-
|
9
|
-
Prawn::Document.generate("canvas.pdf") do
|
10
|
-
canvas do
|
11
|
-
text "This text should appear at the absolute top left"
|
12
|
-
|
13
|
-
# stroke a line to show that the relative coordinates are the same as absolute
|
14
|
-
stroke_line [bounds.left,bounds.bottom], [bounds.right,bounds.top]
|
15
|
-
end
|
16
|
-
end
|
data/examples/general/float.rb
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
require File.expand_path(File.join(File.dirname(__FILE__),
|
2
|
-
%w[.. example_helper]))
|
3
|
-
|
4
|
-
Prawn::Document.generate('float.pdf') do
|
5
|
-
float do
|
6
|
-
bounding_box [bounds.width / 2.0, bounds.top], :width => 100 do
|
7
|
-
text "Hello world. " * 50
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
text "Hello world again"
|
12
|
-
end
|
data/examples/general/margin.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
#
|
3
|
-
# This demonstrates the Prawn options for document and page margin, similar to CSS shorthand.
|
4
|
-
#
|
5
|
-
require File.expand_path(File.join(File.dirname(__FILE__),
|
6
|
-
%w[.. example_helper]))
|
7
|
-
|
8
|
-
LOREM = ("Lorem ipsum dolor sit amet, consectetur adipisicing elit, "+
|
9
|
-
"sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. "+
|
10
|
-
"Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris "+
|
11
|
-
"nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in "+
|
12
|
-
"reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla "+
|
13
|
-
"pariatur. Excepteur sint occaecat cupidatat non proident, sunt in " +
|
14
|
-
"culpa qui officia deserunt mollit anim id est laborum. ") * 20
|
15
|
-
|
16
|
-
Prawn::Document.generate("margin.pdf", :margin => 100) do |pdf|
|
17
|
-
|
18
|
-
pdf.text "100 on all sides", :style => :bold
|
19
|
-
pdf.text LOREM
|
20
|
-
|
21
|
-
pdf.start_new_page(:margin => 100, :left_margin => 0)
|
22
|
-
pdf.text "100 on all sides but 0 on the left", :style => :bold
|
23
|
-
pdf.text LOREM
|
24
|
-
|
25
|
-
pdf.start_new_page(:margin => [100, 0])
|
26
|
-
pdf.text "100 top and bottom, 0 left and right.", :style => :bold
|
27
|
-
pdf.text LOREM
|
28
|
-
|
29
|
-
pdf.start_new_page(:margin => [100, 0, 50])
|
30
|
-
pdf.text "100 top, 0 left and right, 50 bottom.", :style => :bold
|
31
|
-
pdf.text LOREM
|
32
|
-
|
33
|
-
pdf.start_new_page(:margin => [0, 50, 100, 150])
|
34
|
-
pdf.text "0 top, 50 right, 100 bottom, 150 left.", :style => :bold
|
35
|
-
pdf.text LOREM
|
36
|
-
|
37
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
#
|
3
|
-
# Generates a ruler and also demonstrates prawn/measurement_extensions.
|
4
|
-
# It's better to run this example and examine its output than to worry about
|
5
|
-
# its particular implementation, though some might find that interesting as
|
6
|
-
# well.
|
7
|
-
#
|
8
|
-
require File.expand_path(File.join(File.dirname(__FILE__),
|
9
|
-
%w[.. example_helper]))
|
10
|
-
|
11
|
-
require "prawn/measurement_extensions"
|
12
|
-
|
13
|
-
# this makes the following units available (Millimeters, Centimeters, Decimeters, Meters, Inches, Foot, Yards, Points)
|
14
|
-
# Methodname is the common abbravation for the unit (mm, cm, dm, m, in, ft, yd, pt)
|
15
|
-
# Usage: '10.mm'.
|
16
|
-
# This converts 10mm to PDF points, which Prawn uses internally.
|
17
|
-
|
18
|
-
pdf = Prawn::Document.new(
|
19
|
-
:page_size => "A4",
|
20
|
-
:left_margin => 10.mm, # different
|
21
|
-
:right_margin => 1.cm, # units
|
22
|
-
:top_margin => 0.1.dm, # work
|
23
|
-
:bottom_margin => 0.01.m) # well
|
24
|
-
|
25
|
-
pdf.font_size = 6
|
26
|
-
pdf.line_width = 0.05
|
27
|
-
|
28
|
-
units_long = %w[Millimeters Centimeters Decimeters Inches Foot Points]
|
29
|
-
units = %w[mm cm dm in ft pt]
|
30
|
-
offset_multiplier = 2.cm
|
31
|
-
temp = "Units\n"
|
32
|
-
|
33
|
-
units.each_with_index do |unit, unit_index| #iterate through all units that make sense to display on a sheet of paper
|
34
|
-
one_unit_in_pt = eval "1.#{unit}" # calc the width of one unit
|
35
|
-
temp << "1#{unit} => #{one_unit_in_pt}pt\n" #puts converted unit in points
|
36
|
-
|
37
|
-
offset = offset_multiplier * unit_index
|
38
|
-
pdf.draw_text units[unit_index], :at => [offset + 0.5.mm, pdf.bounds.top - 2.mm]
|
39
|
-
|
40
|
-
pdf.stroke_line(offset, pdf.bounds.top, offset, pdf.bounds.bottom)
|
41
|
-
|
42
|
-
0.upto(((pdf.bounds.height - 5.mm) / one_unit_in_pt).to_i) do |i| # checks, how many strokes can be drawn
|
43
|
-
pdf.stroke_line(offset, i * one_unit_in_pt, (i % 5 == 0 ? 6.mm : 3.mm) + offset, i * one_unit_in_pt) # every fifth stroke is twice as large like on a real ruler
|
44
|
-
pdf.draw_text "#{i}#{unit}", :at => [7.mm + offset, i * one_unit_in_pt] unless unit == "mm" && i % 5 != 0 || unit == "pt" && i % 10 != 0 # avoid text too close to each other
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
pdf.text_box temp,
|
49
|
-
:width => 5.cm, :height => pdf.font.height * units_long.length,
|
50
|
-
:at => [offset_multiplier * units_long.length, pdf.bounds.top]
|
51
|
-
|
52
|
-
pdf.render_file "measurement_units.pdf"
|