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
@@ -0,0 +1,18 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# Demonstrates vertical and horizontal positioning of images.
|
4
|
+
#
|
5
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
|
6
|
+
require "prawn"
|
7
|
+
|
8
|
+
Prawn::Document.generate("image_position.pdf", :page_layout => :landscape) do
|
9
|
+
|
10
|
+
dice = "#{Prawn::BASEDIR}/data/images/dice.png"
|
11
|
+
|
12
|
+
image dice, :scale => 0.2, :position => :left, :vposition => :top
|
13
|
+
image dice, :scale => 0.2, :position => :right, :vposition => :top
|
14
|
+
image dice, :scale => 0.2, :position => :center, :vposition => :top
|
15
|
+
image dice, :scale => 0.2, :position => :center, :vposition => :center
|
16
|
+
image dice, :scale => 0.2, :position => :center, :vposition => :bottom
|
17
|
+
|
18
|
+
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
|
3
|
-
|
2
|
+
#
|
3
|
+
# The very first Prawn example. Here for nostalgia's sake.
|
4
|
+
#
|
5
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
|
4
6
|
require "prawn"
|
5
7
|
|
6
8
|
pdf = Prawn::Document.new
|
@@ -1,9 +1,9 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
|
2
|
+
#
|
3
3
|
# PNG files come in different flavours - 5 of them. This example embeds
|
4
4
|
# one of each type as proof that they all work.
|
5
|
-
|
6
|
-
$LOAD_PATH
|
5
|
+
#
|
6
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
|
7
7
|
require "prawn"
|
8
8
|
|
9
9
|
images = [
|
@@ -20,4 +20,4 @@ Prawn::Document.generate("png_types.pdf", :page_size => "A5") do
|
|
20
20
|
text header
|
21
21
|
image file, :at => [50,450]
|
22
22
|
end
|
23
|
-
end
|
23
|
+
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
|
3
|
-
|
2
|
+
#
|
3
|
+
# Basic polygon drawing example. See also: hexagon.rb
|
4
|
+
#
|
5
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
|
4
6
|
require "prawn"
|
5
7
|
|
6
8
|
pdf = Prawn::Document.new
|
@@ -12,5 +14,4 @@ pdf = Prawn::Document.new
|
|
12
14
|
pdf.stroke_rectangle [0,600], 5*i, 10*i
|
13
15
|
end
|
14
16
|
|
15
|
-
pdf.render_file "pretty_polygons.pdf"
|
16
|
-
|
17
|
+
pdf.render_file "pretty_polygons.pdf"
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# Demonstrates how to use open-uri and Document#image to embed remote image
|
4
|
+
# files.
|
5
|
+
#
|
6
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
|
7
|
+
require "prawn"
|
8
|
+
require "open-uri"
|
9
|
+
|
10
|
+
Prawn::Document.generate("remote_images.pdf") do
|
11
|
+
image open("http://prawn.majesticseacreature.com/media/prawn_logo.png")
|
12
|
+
end
|
@@ -1,6 +1,9 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
|
3
|
-
|
2
|
+
#
|
3
|
+
# These helpers will be familiar to Ruport users, and now are supported
|
4
|
+
# directly in Prawn. Run the example to see how they work.
|
5
|
+
#
|
6
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
|
4
7
|
require "prawn"
|
5
8
|
|
6
9
|
# Demonstrates some features stolen from Ruport::Formatter::PDF
|
@@ -12,6 +15,6 @@ Prawn::Document.generate("ruport.pdf") do
|
|
12
15
|
pad(50) { text "I'm Padded" }
|
13
16
|
text "I'm far away"
|
14
17
|
stroke_horizontal_line 50, 100
|
15
|
-
|
16
|
-
|
17
|
-
end
|
18
|
+
stroke_horizontal_line 50, 100, :at => 300
|
19
|
+
stroke_vertical_line 300, 50, :at => 250
|
20
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# Demonstrates Document#stroke_bounds, which will stroke a rectange outlining
|
4
|
+
# the boundaries of the current bounding box. This is useful for debugging
|
5
|
+
# and can also be used as a light-weight and lower level alternative to
|
6
|
+
# Cells.
|
7
|
+
#
|
8
|
+
# Feature borrowed from Josh Knowle's pt at:
|
9
|
+
# http://github.com/joshknowles/pt/tree/master
|
10
|
+
#
|
11
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
|
12
|
+
require 'prawn'
|
13
|
+
|
14
|
+
Prawn::Document.generate("stroke_bounds.pdf") do
|
15
|
+
stroke_bounds
|
16
|
+
|
17
|
+
bounding_box [100,500], :width => 200, :height => 300 do
|
18
|
+
padded_box(10) do
|
19
|
+
text "Hey there, here's some text. " * 10
|
20
|
+
end
|
21
|
+
stroke_bounds
|
22
|
+
end
|
23
|
+
end
|
@@ -1,6 +1,9 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# Some text is not usefully wrapped by our naive_wrap which depends on
|
4
|
+
# spaces. This example shows how to wrap by character instead.
|
5
|
+
#
|
6
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
|
4
7
|
require "prawn"
|
5
8
|
|
6
9
|
start = Time.now
|
@@ -14,4 +17,4 @@ Prawn::Document.generate("chinese_flow.pdf") do
|
|
14
17
|
text_options.update(:wrap => :spaces)
|
15
18
|
long_text = "Text with some spaces " * 25
|
16
19
|
text long_text
|
17
|
-
end
|
20
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# As of Prawn 0.3, it is possible to generate a Euro using the built-in
|
4
|
+
# AFM files. However, you need to be sure to manually add spacing around it,
|
5
|
+
# as its calculated width in the AFM files seem to be wrong.
|
6
|
+
#
|
7
|
+
# We are investigating this issue, but it does not seem to be Prawn specific.
|
8
|
+
# If you need precision spacing, use a TTF file instead and the issue will
|
9
|
+
# go away.
|
10
|
+
#
|
11
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
|
12
|
+
require "prawn"
|
13
|
+
|
14
|
+
Prawn::Document.generate "euro.pdf" do
|
15
|
+
text "A Euro! € ©", :size => 32
|
16
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# FIXME: Introducing TTFunk into Prawn broke this example and a cooresponding
|
4
|
+
# test. Ticket: #139
|
5
|
+
#
|
6
|
+
# Tests passing non utf-8 data into Prawns text function. Should
|
7
|
+
# be transparently converted to utf-8 and rendered as usual.
|
8
|
+
#
|
9
|
+
# NOTE: only works on ruby1.9 compatible VMs, and requires the current
|
10
|
+
# font to include japanese glyphs. On 1.8.x comaptible VMs, an exception
|
11
|
+
# will be raised.
|
12
|
+
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
|
14
|
+
require "prawn"
|
15
|
+
|
16
|
+
begin
|
17
|
+
ruby_19 do
|
18
|
+
datafile = File.join(File.dirname(__FILE__), "..", "..", "data",
|
19
|
+
"shift_jis_text.txt")
|
20
|
+
sjis_str = File.open(datafile, "r:shift_jis") { |f| f.gets }
|
21
|
+
|
22
|
+
Prawn::Document.generate("sjis.pdf") do
|
23
|
+
font "#{Prawn::BASEDIR}/data/fonts/gkai00mp.ttf"
|
24
|
+
text sjis_str
|
25
|
+
end
|
26
|
+
end
|
27
|
+
rescue
|
28
|
+
puts "\n FIXME: SJIS Broken due to TTFunk integration."
|
29
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# Shows that Prawn works out of the box with UTF-8 text, so long as you use
|
4
|
+
# a TTF file with the necessary glyphs for your content.
|
5
|
+
#
|
6
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
|
7
|
+
require "prawn"
|
8
|
+
|
9
|
+
Prawn::Document.generate("utf8.pdf") do
|
10
|
+
font "#{Prawn::BASEDIR}/data/fonts/DejaVuSans.ttf"
|
11
|
+
text "ὕαλον ϕαγεῖν δύναμαι· τοῦτο οὔ με βλάπτει." * 20
|
12
|
+
end
|
13
|
+
|
14
|
+
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# Prints a list of all of the glyphs that can be rendered by Adobe's built
|
4
|
+
# in fonts, along with their character widths and WinAnsi codes. Be sure
|
5
|
+
# to pass these glyphs as UTF-8, and Prawn will transcode them for you.
|
6
|
+
#
|
7
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
|
8
|
+
require 'prawn'
|
9
|
+
|
10
|
+
FONT_SIZE = 9.5
|
11
|
+
|
12
|
+
Prawn::Document.generate("win-ansi.pdf") do
|
13
|
+
@skip_encoding = true
|
14
|
+
|
15
|
+
x = 0
|
16
|
+
y = bounds.top
|
17
|
+
|
18
|
+
fields = [[20, :right], [8, :left], [12, :center], [30, :right], [8, :left], [0, :left]]
|
19
|
+
|
20
|
+
font "Helvetica", :size => FONT_SIZE
|
21
|
+
|
22
|
+
Prawn::Encoding::WinAnsi::CHARACTERS.each_with_index do |name, index|
|
23
|
+
next if name == ".notdef"
|
24
|
+
y -= FONT_SIZE
|
25
|
+
|
26
|
+
if y < FONT_SIZE
|
27
|
+
y = bounds.top - FONT_SIZE
|
28
|
+
x += 170
|
29
|
+
end
|
30
|
+
|
31
|
+
code = "%d." % index
|
32
|
+
char = index.chr
|
33
|
+
|
34
|
+
width = 1000 * font.metrics.string_width(char, FONT_SIZE) / FONT_SIZE
|
35
|
+
size = "%d" % width
|
36
|
+
|
37
|
+
data = [code, nil, char, size, nil, name]
|
38
|
+
dx = x
|
39
|
+
fields.zip(data).each do |(total_width, align), field|
|
40
|
+
if field
|
41
|
+
width = font.metrics.string_width(field, FONT_SIZE)
|
42
|
+
|
43
|
+
case align
|
44
|
+
when :left then offset = 0
|
45
|
+
when :right then offset = total_width - width
|
46
|
+
when :center then offset = (total_width - width)/2
|
47
|
+
end
|
48
|
+
|
49
|
+
text(field, :at => [dx + offset, y])
|
50
|
+
end
|
51
|
+
|
52
|
+
dx += total_width
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
File without changes
|
@@ -1,18 +1,20 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
|
3
|
-
|
2
|
+
#
|
3
|
+
# Low level cell and row implementation, which form the basic building
|
4
|
+
# blocks for Prawn tables. Only necessary to know about if you plan on
|
5
|
+
# building your own table implementation from scratch or heavily modify
|
6
|
+
# the existing table system.
|
7
|
+
#
|
8
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
|
4
9
|
require "prawn"
|
5
10
|
|
6
|
-
# If this looks a somewhat Byzantine, don't worry. It's a temporary interface
|
7
|
-
# to low level objects I'll be using for table building support (and other fun
|
8
|
-
# stuff )
|
9
11
|
Prawn::Document.generate("cell.pdf") do
|
10
12
|
cell = Prawn::Graphics::Cell.new(
|
11
13
|
:border_width => 3, :padding => 10, :width => 75,
|
12
14
|
:text => "You know that kittens are made of mud!", :document => self)
|
13
15
|
cell2 = Prawn::Graphics::Cell.new(
|
14
16
|
:border_width => 3, :padding => 10,
|
15
|
-
:text => "And that puppies are made of gravy", :document => self)
|
17
|
+
:text => "And that puppies are made of gravy", :document => self, :font_size => 9)
|
16
18
|
cell3 = Prawn::Graphics::Cell.new(
|
17
19
|
:border_width => 3, :padding => 10, :width => 100,
|
18
20
|
:text => "This is simply the way of the world", :document => self)
|
File without changes
|
@@ -1,6 +1,8 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
|
3
|
-
|
2
|
+
#
|
3
|
+
# Demonstrates various table and cell features.
|
4
|
+
#
|
5
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
|
4
6
|
require "prawn"
|
5
7
|
require "rubygems"
|
6
8
|
|
@@ -8,17 +10,18 @@ headers, body = nil, nil
|
|
8
10
|
|
9
11
|
ruby_18 do
|
10
12
|
require "fastercsv"
|
11
|
-
headers, *body = FasterCSV.read("#{Prawn::BASEDIR}/examples/addressbook.csv")
|
13
|
+
headers, *body = FasterCSV.read("#{Prawn::BASEDIR}/examples/table/addressbook.csv")
|
12
14
|
end
|
13
15
|
|
14
16
|
ruby_19 do
|
15
17
|
require "csv"
|
16
|
-
headers, *body = CSV.read("#{Prawn::BASEDIR}/examples/addressbook.csv"
|
17
|
-
|
18
|
-
body.map! { |e| e.map! { |x| x.encode("UTF-8") } }
|
18
|
+
headers, *body = CSV.read("#{Prawn::BASEDIR}/examples/table/addressbook.csv",
|
19
|
+
:encoding => "utf-8")
|
19
20
|
end
|
20
21
|
|
21
22
|
Prawn::Document.generate("fancy_table.pdf", :page_layout => :landscape) do
|
23
|
+
|
24
|
+
#font "#{Prawn::BASEDIR}/data/fonts/DejaVuSans.ttf"
|
22
25
|
|
23
26
|
mask(:y) { table body, :headers => headers,
|
24
27
|
:align => :center,
|
@@ -1,6 +1,9 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
|
3
|
-
|
2
|
+
#
|
3
|
+
# A simple proof of concept of building a Prawn based PDF formatter for
|
4
|
+
# Ruport tables. Requires Ruby Reports to run.
|
5
|
+
#
|
6
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
|
4
7
|
require "prawn"
|
5
8
|
|
6
9
|
ruby_18 do
|
@@ -43,7 +46,7 @@ ruby_18 do
|
|
43
46
|
end
|
44
47
|
|
45
48
|
if __FILE__ == $PROGRAM_NAME
|
46
|
-
t = Table("#{Prawn::BASEDIR}/examples/addressbook.csv")
|
49
|
+
t = Table("#{Prawn::BASEDIR}/examples/table/addressbook.csv")
|
47
50
|
headers = t.column_names.map { |c| c.capitalize }
|
48
51
|
t.save_as "addressbook_ruport.pdf", :headers => headers
|
49
52
|
end
|
@@ -1,6 +1,10 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
|
3
|
-
|
2
|
+
#
|
3
|
+
# Generates a couple simple tables, including some UTF-8 text cells.
|
4
|
+
# Although this does not show all of the options available to table, the most
|
5
|
+
# common are used here. See fancy_table.rb for a more comprehensive example.
|
6
|
+
#
|
7
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
|
4
8
|
require "prawn"
|
5
9
|
|
6
10
|
Prawn::Document.generate("table.pdf") do
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# Demonstrates the many controls over alignment and positioning in Prawn
|
4
|
+
# tables.
|
5
|
+
#
|
6
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
|
7
|
+
require "prawn"
|
8
|
+
|
9
|
+
Prawn::Document.generate "table_header_align.pdf" do
|
10
|
+
table [ ['01/01/2008', 'John Doe', '4.2', '125.00', '525.00'],
|
11
|
+
['01/12/2008', 'Jane Doe', '3.2', '75.50', '241.60'] ] * 20,
|
12
|
+
:position => :center,
|
13
|
+
:headers => ['Date', 'Employee', 'Hours', 'Rate', 'Total'],
|
14
|
+
:widths => { 0 => 75, 1 => 100, 2 => 50, 3 => 50, 4 => 50},
|
15
|
+
:border_style => :grid,
|
16
|
+
:align => { 0 => :right, 1 => :left, 2 => :right, 3 => :right, 4 => :right },
|
17
|
+
:align_headers => { 0 => :center, 2 => :left, 3 => :left, 4 => :right }
|
18
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# Demonstrates how to set the table border color with the :border_color
|
4
|
+
# attribute.
|
5
|
+
#
|
6
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
|
7
|
+
require "prawn"
|
8
|
+
|
9
|
+
Prawn::Document.generate "table_border_color.pdf" do
|
10
|
+
table [ ['01/01/2008', 'John Doe', '4.2', '125.00', '525.00'],
|
11
|
+
['01/12/2008', 'Jane Doe', '3.2', '75.50', '241.60'] ] * 20,
|
12
|
+
:position => :center,
|
13
|
+
:headers => ['Date', 'Employee', 'Hours', 'Rate', 'Total'],
|
14
|
+
:widths => { 0 => 75, 1 => 100, 2 => 50, 3 => 50, 4 => 50},
|
15
|
+
:border_style => :grid,
|
16
|
+
:border_color => "ff0000"
|
17
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# Demonstrates the use of the :col_span option when using Document#table
|
4
|
+
#
|
5
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
|
6
|
+
require "prawn"
|
7
|
+
|
8
|
+
Prawn::Document.generate "table_colspan.pdf" do
|
9
|
+
data = [ ['01/01/2008', 'John Doe', '4.2', '125.00', '525.00'],
|
10
|
+
['01/12/2008', 'Jane Doe', '3.2', '75.50', '241.60'] ] * 5
|
11
|
+
|
12
|
+
data << [{:text => 'Total', :colspan => 2}, '37.0', '1002.5', '3833']
|
13
|
+
|
14
|
+
table data,
|
15
|
+
:position => :center,
|
16
|
+
:headers => ['Date', 'Employee', 'Hours', 'Rate', 'Total'],
|
17
|
+
:widths => { 0 => 75, 1 => 100, 2 => 50, 3 => 50, 4 => 50},
|
18
|
+
:border_style => :grid
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# Demonstrates explicitly setting the :header_color rather than inferring
|
4
|
+
# it from :row_colors in Document#table
|
5
|
+
#
|
6
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
|
7
|
+
require "prawn"
|
8
|
+
|
9
|
+
Prawn::Document.generate "table_header_color.pdf" do
|
10
|
+
table [ ['01/01/2008', 'John Doe', '4.2', '125.00', '525.00'],
|
11
|
+
['01/12/2008', 'Jane Doe', '3.2', '75.50', '241.60'] ] * 20,
|
12
|
+
:position => :center,
|
13
|
+
:headers => ['Date', 'Employee', 'Hours', 'Rate', 'Total'],
|
14
|
+
:widths => { 0 => 75, 1 => 100, 2 => 50, 3 => 50, 4 => 50},
|
15
|
+
:border_style => :grid,
|
16
|
+
:header_color => 'f07878',
|
17
|
+
:header_text_color => "990000",
|
18
|
+
:row_colors => ["FFCCFF","CCFFCC"]
|
19
|
+
end
|