prawn 0.2.3 → 0.3.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/README +6 -10
- data/Rakefile +4 -13
- data/data/encodings/win_ansi.txt +29 -0
- data/data/images/fractal.jpg +0 -0
- data/data/images/letterhead.jpg +0 -0
- data/examples/bounding_box/bounding_boxes.rb +44 -0
- data/examples/bounding_box/lazy_bounding_boxes.rb +28 -0
- data/examples/bounding_box/padded_box.rb +24 -0
- data/examples/{russian_boxes.rb → bounding_box/russian_boxes.rb} +9 -6
- data/examples/general/background.rb +20 -0
- data/examples/{canvas.rb → general/canvas.rb} +6 -2
- data/examples/general/measurement_units.rb +52 -0
- data/examples/{multi_page_layout.rb → general/multi_page_layout.rb} +6 -3
- data/examples/{page_geometry.rb → general/page_geometry.rb} +6 -2
- data/examples/{image.rb → graphics/basic_images.rb} +8 -4
- data/examples/graphics/cmyk.rb +13 -0
- data/examples/graphics/curves.rb +12 -0
- data/examples/{hexagon.rb → graphics/hexagon.rb} +5 -5
- data/examples/graphics/image_fit.rb +16 -0
- data/examples/graphics/image_flow.rb +38 -0
- data/examples/graphics/image_position.rb +18 -0
- data/examples/{line.rb → graphics/line.rb} +4 -2
- data/examples/{png_types.rb → graphics/png_types.rb} +4 -4
- data/examples/{polygons.rb → graphics/polygons.rb} +5 -4
- data/examples/graphics/remote_images.rb +12 -0
- data/examples/{ruport_helpers.rb → graphics/ruport_style_helpers.rb} +8 -5
- data/examples/graphics/stroke_bounds.rb +23 -0
- data/examples/{chinese_text_wrapping.rb → m17n/chinese_text_wrapping.rb} +7 -4
- data/examples/m17n/euro.rb +16 -0
- data/examples/m17n/sjis.rb +29 -0
- data/examples/m17n/utf8.rb +14 -0
- data/examples/m17n/win_ansi_charset.rb +55 -0
- data/examples/{addressbook.csv → table/addressbook.csv} +0 -0
- data/examples/{cell.rb → table/cell.rb} +8 -6
- data/examples/{currency.csv → table/currency.csv} +0 -0
- data/examples/{fancy_table.rb → table/fancy_table.rb} +9 -6
- data/examples/{ruport_formatter.rb → table/ruport_formatter.rb} +6 -3
- data/examples/{table.rb → table/table.rb} +6 -2
- data/examples/table/table_alignment.rb +18 -0
- data/examples/table/table_border_color.rb +17 -0
- data/examples/table/table_colspan.rb +19 -0
- data/examples/table/table_header_color.rb +19 -0
- data/examples/table/table_header_underline.rb +15 -0
- data/examples/{alignment.rb → text/alignment.rb} +5 -2
- data/examples/text/family_based_styling.rb +25 -0
- data/examples/{flowing_text_with_header_and_footer.rb → text/flowing_text_with_header_and_footer.rb} +19 -8
- data/examples/text/font_calculations.rb +91 -0
- data/examples/text/font_size.rb +34 -0
- data/examples/{kerning.rb → text/kerning.rb} +5 -1
- data/examples/text/simple_text.rb +18 -0
- data/examples/text/simple_text_ttf.rb +18 -0
- data/examples/{span.rb → text/span.rb} +5 -2
- data/examples/text/text_box.rb +26 -0
- data/examples/{text_flow.rb → text/text_flow.rb} +5 -2
- data/lib/prawn.rb +26 -20
- data/lib/prawn/compatibility.rb +5 -8
- data/lib/prawn/document.rb +29 -13
- data/lib/prawn/document/annotations.rb +63 -0
- data/lib/prawn/document/bounding_box.rb +18 -3
- data/lib/prawn/document/destinations.rb +81 -0
- data/lib/prawn/document/internals.rb +16 -2
- data/lib/prawn/document/page_geometry.rb +58 -57
- data/lib/prawn/document/span.rb +8 -0
- data/lib/prawn/document/table.rb +81 -31
- data/lib/prawn/document/text.rb +66 -21
- data/lib/prawn/document/text/box.rb +77 -0
- data/lib/prawn/encoding.rb +121 -0
- data/lib/prawn/errors.rb +4 -0
- data/lib/prawn/font.rb +70 -42
- data/lib/prawn/font/metrics.rb +64 -119
- data/lib/prawn/graphics.rb +105 -87
- data/lib/prawn/graphics/cell.rb +55 -28
- data/lib/prawn/graphics/color.rb +8 -0
- data/lib/prawn/images.rb +55 -12
- data/lib/prawn/images/jpg.rb +2 -1
- data/lib/prawn/images/png.rb +2 -1
- data/lib/prawn/literal_string.rb +14 -0
- data/lib/prawn/measurement_extensions.rb +46 -0
- data/lib/prawn/measurements.rb +71 -0
- data/lib/prawn/name_tree.rb +165 -0
- data/lib/prawn/pdf_object.rb +8 -1
- data/spec/annotations_spec.rb +90 -0
- data/spec/destinations_spec.rb +15 -0
- data/spec/document_spec.rb +39 -2
- data/spec/font_spec.rb +22 -0
- data/spec/graphics_spec.rb +99 -87
- data/spec/images_spec.rb +29 -1
- data/spec/measurement_units_spec.rb +23 -0
- data/spec/metrics_spec.rb +3 -2
- data/spec/name_tree_spec.rb +103 -0
- data/spec/pdf_object_spec.rb +15 -5
- data/spec/png_spec.rb +14 -14
- data/spec/spec_helper.rb +8 -6
- data/spec/table_spec.rb +40 -0
- data/spec/text_spec.rb +6 -4
- data/vendor/ttfunk/data/fonts/DejaVuSans.ttf +0 -0
- data/vendor/ttfunk/data/fonts/comicsans.ttf +0 -0
- data/vendor/ttfunk/example.rb +5 -0
- data/vendor/ttfunk/lib/ttfunk.rb +48 -0
- data/vendor/ttfunk/lib/ttfunk/table.rb +27 -0
- data/vendor/ttfunk/lib/ttfunk/table/cmap.rb +94 -0
- data/vendor/ttfunk/lib/ttfunk/table/directory.rb +25 -0
- data/vendor/ttfunk/lib/ttfunk/table/head.rb +25 -0
- data/vendor/ttfunk/lib/ttfunk/table/hhea.rb +27 -0
- data/vendor/ttfunk/lib/ttfunk/table/hmtx.rb +20 -0
- data/vendor/ttfunk/lib/ttfunk/table/kern.rb +48 -0
- data/vendor/ttfunk/lib/ttfunk/table/maxp.rb +17 -0
- data/vendor/ttfunk/lib/ttfunk/table/name.rb +52 -0
- metadata +93 -62
- data/examples/bounding_boxes.rb +0 -30
- data/examples/curves.rb +0 -10
- data/examples/family_based_styling.rb +0 -21
- data/examples/font_size.rb +0 -19
- data/examples/image2.rb +0 -13
- data/examples/image_flow.rb +0 -29
- data/examples/lazy_bounding_boxes.rb +0 -19
- data/examples/remote_images.rb +0 -7
- data/examples/simple_text.rb +0 -15
- data/examples/simple_text_ttf.rb +0 -16
- data/examples/sjis.rb +0 -21
- data/examples/utf8.rb +0 -12
- data/vendor/font_ttf/ttf.rb +0 -20
- data/vendor/font_ttf/ttf/datatypes.rb +0 -189
- data/vendor/font_ttf/ttf/encodings.rb +0 -140
- data/vendor/font_ttf/ttf/exceptions.rb +0 -28
- data/vendor/font_ttf/ttf/file.rb +0 -290
- data/vendor/font_ttf/ttf/fontchunk.rb +0 -77
- data/vendor/font_ttf/ttf/table/cmap.rb +0 -408
- data/vendor/font_ttf/ttf/table/cvt.rb +0 -49
- data/vendor/font_ttf/ttf/table/fpgm.rb +0 -48
- data/vendor/font_ttf/ttf/table/gasp.rb +0 -88
- data/vendor/font_ttf/ttf/table/glyf.rb +0 -452
- data/vendor/font_ttf/ttf/table/head.rb +0 -86
- data/vendor/font_ttf/ttf/table/hhea.rb +0 -96
- data/vendor/font_ttf/ttf/table/hmtx.rb +0 -98
- data/vendor/font_ttf/ttf/table/kern.rb +0 -186
- data/vendor/font_ttf/ttf/table/loca.rb +0 -75
- data/vendor/font_ttf/ttf/table/maxp.rb +0 -81
- data/vendor/font_ttf/ttf/table/name.rb +0 -222
- data/vendor/font_ttf/ttf/table/os2.rb +0 -172
- data/vendor/font_ttf/ttf/table/post.rb +0 -120
- data/vendor/font_ttf/ttf/table/prep.rb +0 -27
- data/vendor/font_ttf/ttf/table/vhea.rb +0 -45
- data/vendor/font_ttf/ttf/table/vmtx.rb +0 -36
data/README
CHANGED
@@ -12,6 +12,11 @@ Website:
|
|
12
12
|
|
13
13
|
http://prawn.majesticseacreature.com
|
14
14
|
|
15
|
+
Examples:
|
16
|
+
http://github.com/sandal/prawn/tree/master/examples
|
17
|
+
|
18
|
+
(or gem unpack prawn, if you want to run them locally)
|
19
|
+
|
15
20
|
Bug Tracker / Wiki:
|
16
21
|
|
17
22
|
http://prawn.lighthouseapp.com/projects/9398-prawn/home
|
@@ -32,13 +37,4 @@ Find us in #prawn on irc.freenode.net
|
|
32
37
|
|
33
38
|
NOTES TO DEVELOPERS:
|
34
39
|
|
35
|
-
|
36
|
-
the specs on both Ruby 1.8.6 and the latest Ruby 1.9 snapshot, as both versions
|
37
|
-
are supported. 1.8.7 is *not* officially supported.
|
38
|
-
|
39
|
-
Prawn relies on PDF::Inspector, a collection of PDF::Reader backed classes
|
40
|
-
for analyzing PDF output. This is provided as a submodule in Prawn's git
|
41
|
-
repository, so be sure to do the following before running the specs:
|
42
|
-
|
43
|
-
git submodule init
|
44
|
-
git submodule update
|
40
|
+
See HACKING file for details on getting set up with a local build.
|
data/Rakefile
CHANGED
@@ -4,7 +4,7 @@ require 'rake/testtask'
|
|
4
4
|
require "rake/rdoctask"
|
5
5
|
require "rake/gempackagetask"
|
6
6
|
|
7
|
-
PRAWN_VERSION = "0.
|
7
|
+
PRAWN_VERSION = "0.3.0"
|
8
8
|
|
9
9
|
task :default => [:test]
|
10
10
|
|
@@ -26,7 +26,8 @@ desc "genrates documentation"
|
|
26
26
|
Rake::RDocTask.new do |rdoc|
|
27
27
|
rdoc.rdoc_files.include( "README",
|
28
28
|
"COPYING",
|
29
|
-
"LICENSE",
|
29
|
+
"LICENSE",
|
30
|
+
"HACKING", "lib/" )
|
30
31
|
rdoc.main = "README"
|
31
32
|
rdoc.rdoc_dir = "doc/html"
|
32
33
|
rdoc.title = "Prawn Documentation"
|
@@ -35,22 +36,12 @@ end
|
|
35
36
|
desc "run all examples, and then diff them against reference PDFs"
|
36
37
|
task :examples do
|
37
38
|
mkdir_p "output"
|
38
|
-
examples = Dir["examples
|
39
|
+
examples = Dir["examples/**/*.rb"]
|
39
40
|
t = Time.now
|
40
41
|
puts "Running Examples"
|
41
42
|
examples.each { |file| `ruby -Ilib #{file}` }
|
42
43
|
puts "Ran in #{Time.now - t} s"
|
43
44
|
`mv *.pdf output`
|
44
|
-
|
45
|
-
unless RUBY_VERSION < "1.9"
|
46
|
-
puts "Checking for differences..."
|
47
|
-
output = Dir["output/*.pdf"]
|
48
|
-
ref = Dir["reference_pdfs/*.pdf"]
|
49
|
-
output.zip(ref).each do |o,r|
|
50
|
-
system "diff -q #{o} #{r}"
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
45
|
end
|
55
46
|
|
56
47
|
spec = Gem::Specification.new do |spec|
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# A mapping of WinAnsi (win-1252) characters to unicode. Anything
|
2
|
+
# not specified is left unchanged
|
3
|
+
80;20AC
|
4
|
+
82;201A
|
5
|
+
83;0192
|
6
|
+
84;201E
|
7
|
+
85;2026
|
8
|
+
86;2020
|
9
|
+
87;2021
|
10
|
+
88;02C6
|
11
|
+
89;2030
|
12
|
+
8A;0160
|
13
|
+
8B;2039
|
14
|
+
8C;0152
|
15
|
+
8E;017D
|
16
|
+
91;2018
|
17
|
+
92;2019
|
18
|
+
93;201C
|
19
|
+
94;201D
|
20
|
+
95;2022
|
21
|
+
96;2013
|
22
|
+
97;2014
|
23
|
+
98;02DC
|
24
|
+
99;2122
|
25
|
+
9A;0161
|
26
|
+
9B;203A
|
27
|
+
9C;0152
|
28
|
+
9E;017E
|
29
|
+
9F;0178
|
Binary file
|
Binary file
|
@@ -0,0 +1,44 @@
|
|
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
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
|
7
|
+
require 'prawn'
|
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_at [100,100], :radius => 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
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# This example demonstrates Document#lazy_bounding_box, which is used for
|
4
|
+
# storing a set of drawing instructions to be executed later. This is used
|
5
|
+
# for header and footer support in Prawn, and can be used for repeating page
|
6
|
+
# elements in general.
|
7
|
+
#
|
8
|
+
# Note that once a lazy bounding box is positioned, it calculates its anchor
|
9
|
+
# relative to its parent bounding box. It will be positioned at this exact
|
10
|
+
# location each time it is redrawn, regardless of the bounds
|
11
|
+
# LazyBoundingBox#draw is in.
|
12
|
+
#
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
|
14
|
+
require "prawn"
|
15
|
+
|
16
|
+
file = "lazy_bounding_boxes.pdf"
|
17
|
+
Prawn::Document.generate(file, :skip_page_creation => true) do
|
18
|
+
point = [bounds.right-50, bounds.bottom + 25]
|
19
|
+
page_counter = lazy_bounding_box(point, :width => 50) do
|
20
|
+
text "Page: #{page_count}"
|
21
|
+
end
|
22
|
+
|
23
|
+
10.times do
|
24
|
+
start_new_page
|
25
|
+
text "Some filler text for the page"
|
26
|
+
page_counter.draw
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# Padded box is a kind of bounding box which places padding on all sides of
|
4
|
+
# the current bounds. This is easier to see than explain, so please run the
|
5
|
+
# example.
|
6
|
+
#
|
7
|
+
# Feature borrowed from Josh Knowle's pt at:
|
8
|
+
# http://github.com/joshknowles/pt/tree/master
|
9
|
+
#
|
10
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
|
11
|
+
require 'prawn'
|
12
|
+
|
13
|
+
Prawn::Document.generate('padded_box.pdf') do
|
14
|
+
stroke_bounds
|
15
|
+
text "Margin box"
|
16
|
+
padded_box(25) do
|
17
|
+
stroke_bounds
|
18
|
+
text "Bounding box padded by 25 on all sides from the margins"
|
19
|
+
padded_box(50) do
|
20
|
+
stroke_bounds
|
21
|
+
text "Bounding box padded by 50 on all sides from the parent bounds"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -1,4 +1,10 @@
|
|
1
|
-
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# This example is mostly just for fun, and shows how nested bounding boxes
|
4
|
+
# can simplify calculations. See the other files in examples/bounding_box
|
5
|
+
# for more basic uses.
|
6
|
+
|
7
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
|
2
8
|
require 'prawn'
|
3
9
|
|
4
10
|
class Array
|
@@ -20,15 +26,12 @@ def recurse_bounding_box(pdf, max_depth=5, depth=1)
|
|
20
26
|
left_top_corners = [5, box.right-width-5].combine [box.top-5, height+5]
|
21
27
|
left_top_corners.each do |lt|
|
22
28
|
pdf.bounding_box(lt, :width=>width, :height=>height) do
|
23
|
-
pdf.
|
29
|
+
pdf.stroke_bounds
|
24
30
|
recurse_bounding_box(pdf, max_depth, depth+1) if depth<max_depth
|
25
31
|
end
|
26
32
|
end
|
27
33
|
end
|
28
34
|
|
29
|
-
|
30
35
|
Prawn::Document.generate("russian_boxes.pdf") do |pdf|
|
31
36
|
recurse_bounding_box(pdf)
|
32
|
-
end
|
33
|
-
|
34
|
-
|
37
|
+
end
|
@@ -0,0 +1,20 @@
|
|
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
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
|
8
|
+
require "prawn"
|
9
|
+
|
10
|
+
img = "#{Prawn::BASEDIR}/data/images/letterhead.jpg"
|
11
|
+
|
12
|
+
Prawn::Document.generate("background.pdf", :background => img) do
|
13
|
+
text_options.update(:size => 18, :align => :right)
|
14
|
+
text "My report caption"
|
15
|
+
text_options.update(:size => 12, :align => :left, :spacing => 2)
|
16
|
+
move_down font.height * 2
|
17
|
+
text "Here is my text explaning this report. " * 20
|
18
|
+
move_down font.height
|
19
|
+
text "I'm using a soft background. " * 40
|
20
|
+
end
|
@@ -1,11 +1,15 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
|
3
|
-
|
2
|
+
#
|
3
|
+
# Demonstrates how to enable absolute positioning in Prawn by temporarily
|
4
|
+
# removing the margin_box via Document#canvas()
|
5
|
+
#
|
6
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
|
4
7
|
require "prawn"
|
5
8
|
|
6
9
|
Prawn::Document.generate("canvas.pdf") do
|
7
10
|
canvas do
|
8
11
|
text "This text should appear at the absolute top left"
|
12
|
+
|
9
13
|
# stroke a line to show that the relative coordinates are the same as absolute
|
10
14
|
stroke_line [bounds.left,bounds.bottom], [bounds.right,bounds.top]
|
11
15
|
end
|
@@ -0,0 +1,52 @@
|
|
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
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
|
9
|
+
require "prawn"
|
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.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.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"
|
@@ -1,6 +1,9 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# This demonstrates that Prawn can modify page size, margins and layout for
|
4
|
+
# each individual page, via Document#start_new_page()
|
5
|
+
#
|
6
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
|
4
7
|
require "prawn"
|
5
8
|
|
6
9
|
Prawn::Document.generate("multi-layout.pdf", :page_layout => :landscape) do |pdf|
|
@@ -1,6 +1,10 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
|
3
|
-
|
2
|
+
#
|
3
|
+
# This demonstrates basic page layout and landscape options for Prawn
|
4
|
+
# documents. The style used here is a bit out of date, see
|
5
|
+
# multi_page_layout.rb for a more modern example.
|
6
|
+
#
|
7
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
|
4
8
|
require "prawn"
|
5
9
|
|
6
10
|
def pdf(*options)
|
@@ -1,9 +1,13 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
|
3
|
-
|
2
|
+
#
|
3
|
+
# Demonstrates basic image embedding and positioning functionality.
|
4
|
+
# For positioning images alongside flowing text, see the image_flow.rb
|
5
|
+
# example.
|
6
|
+
#
|
7
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
|
4
8
|
require "prawn"
|
5
9
|
|
6
|
-
Prawn::Document.generate("
|
10
|
+
Prawn::Document.generate("basic_images.pdf", :page_layout => :landscape) do
|
7
11
|
pigs = "#{Prawn::BASEDIR}/data/images/pigs.jpg"
|
8
12
|
image pigs, :at => [50,450], :scale => 0.5
|
9
13
|
|
@@ -20,4 +24,4 @@ Prawn::Document.generate("image.pdf", :page_layout => :landscape) do
|
|
20
24
|
|
21
25
|
ruport = "#{Prawn::BASEDIR}/data/images/ruport_transparent.png"
|
22
26
|
image ruport, :at => [50,525]
|
23
|
-
end
|
27
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# Demonstrates Prawn's support for CMYK images and colors.
|
4
|
+
#
|
5
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
|
6
|
+
require "prawn"
|
7
|
+
|
8
|
+
Prawn::Document.generate("cmyk.pdf", :page_layout => :landscape) do
|
9
|
+
fill_color 50, 100, 0, 0
|
10
|
+
text "Prawn is CYMK Friendly"
|
11
|
+
fractal = "#{Prawn::BASEDIR}/data/images/fractal.jpg"
|
12
|
+
image fractal, :at => [50,450]
|
13
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# Demonstrates simple curve and circle usage
|
4
|
+
#
|
5
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
|
6
|
+
require "prawn"
|
7
|
+
|
8
|
+
pdf = Prawn::Document.new
|
9
|
+
pdf.move_to [100,100]
|
10
|
+
pdf.stroke_curve_to [50,50], :bounds => [[20,90], [90,90]]
|
11
|
+
pdf.fill_circle_at [200,200], :radius => 10
|
12
|
+
pdf.render_file "curves.pdf"
|
@@ -1,6 +1,8 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
|
3
|
-
|
2
|
+
#
|
3
|
+
# Draws and fills a Hexagon using Document#polygon
|
4
|
+
#
|
5
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
|
4
6
|
require "prawn"
|
5
7
|
|
6
8
|
pdf = Prawn::Document.new
|
@@ -8,7 +10,5 @@ pdf = Prawn::Document.new
|
|
8
10
|
pdf.fill_color "ff0000"
|
9
11
|
pdf.fill_polygon [100, 250], [200, 300], [300, 250],
|
10
12
|
[300, 150], [200, 100], [100, 150]
|
11
|
-
|
12
|
-
pdf.render_file "hexagon.pdf"
|
13
|
-
|
14
13
|
|
14
|
+
pdf.render_file "hexagon.pdf"
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# Demonstrates fitting an image within a rectangular width and height.
|
4
|
+
# The image will be scaled down to fit within the box, while preserving
|
5
|
+
# the aspect ratio.
|
6
|
+
#
|
7
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
|
8
|
+
require "prawn"
|
9
|
+
|
10
|
+
Prawn::Document.generate("image_fit.pdf", :page_layout => :landscape) do
|
11
|
+
|
12
|
+
pigs = "#{Prawn::BASEDIR}/data/images/pigs.jpg"
|
13
|
+
stroke_rectangle [50,450], 200, 200
|
14
|
+
image pigs, :at => [50,450], :fit => [200,200]
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# Demonstrates automated flowing and positioning of images, as well as
|
4
|
+
# aligining images along the x-axis via the :position argument. This is
|
5
|
+
# useful when used in combination with flowing text, where the exact final
|
6
|
+
# position of the image is not known ahead of time.
|
7
|
+
#
|
8
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
|
9
|
+
require "prawn"
|
10
|
+
|
11
|
+
Prawn::Document.generate("image-flow.pdf", :page_layout => :landscape) do
|
12
|
+
font.size = 8
|
13
|
+
stef = "#{Prawn::BASEDIR}/data/images/stef.jpg"
|
14
|
+
|
15
|
+
text "Image at default position with no arguments"
|
16
|
+
|
17
|
+
move_down 10
|
18
|
+
|
19
|
+
image stef
|
20
|
+
|
21
|
+
text "Centered image flowing"
|
22
|
+
|
23
|
+
image stef, :position => :center
|
24
|
+
|
25
|
+
text "Right aligned image flowing"
|
26
|
+
|
27
|
+
image stef, :position => :right
|
28
|
+
|
29
|
+
text "Explicitly left aligned image flowing"
|
30
|
+
|
31
|
+
move_down 10
|
32
|
+
|
33
|
+
image stef, :position => :left
|
34
|
+
|
35
|
+
text "Flowing image at x=50"
|
36
|
+
|
37
|
+
image stef, :position => 50
|
38
|
+
end
|