prawn-git 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.yardopts +10 -0
- data/COPYING +2 -0
- data/GPLv2 +340 -0
- data/GPLv3 +674 -0
- data/Gemfile +11 -0
- data/LICENSE +56 -0
- data/Rakefile +55 -0
- data/data/fonts/Courier-Bold.afm +342 -0
- data/data/fonts/Courier-BoldOblique.afm +342 -0
- data/data/fonts/Courier-Oblique.afm +342 -0
- data/data/fonts/Courier.afm +342 -0
- data/data/fonts/Helvetica-Bold.afm +2827 -0
- data/data/fonts/Helvetica-BoldOblique.afm +2827 -0
- data/data/fonts/Helvetica-Oblique.afm +3051 -0
- data/data/fonts/Helvetica.afm +3051 -0
- data/data/fonts/MustRead.html +19 -0
- data/data/fonts/Symbol.afm +213 -0
- data/data/fonts/Times-Bold.afm +2588 -0
- data/data/fonts/Times-BoldItalic.afm +2384 -0
- data/data/fonts/Times-Italic.afm +2667 -0
- data/data/fonts/Times-Roman.afm +2419 -0
- data/data/fonts/ZapfDingbats.afm +225 -0
- data/data/images/16bit.alpha +0 -0
- data/data/images/16bit.color +0 -0
- data/data/images/16bit.png +0 -0
- data/data/images/arrow.png +0 -0
- data/data/images/arrow2.png +0 -0
- data/data/images/dice.alpha +0 -0
- data/data/images/dice.color +0 -0
- data/data/images/dice.png +0 -0
- data/data/images/dice_interlaced.png +0 -0
- data/data/images/fractal.jpg +0 -0
- data/data/images/indexed_color.dat +0 -0
- data/data/images/indexed_color.png +0 -0
- data/data/images/letterhead.jpg +0 -0
- data/data/images/license.md +8 -0
- data/data/images/page_white_text.alpha +0 -0
- data/data/images/page_white_text.color +0 -0
- data/data/images/page_white_text.png +0 -0
- data/data/images/pal_bk.png +0 -0
- data/data/images/pigs.jpg +0 -0
- data/data/images/prawn.png +0 -0
- data/data/images/ruport.png +0 -0
- data/data/images/ruport_data.dat +0 -0
- data/data/images/ruport_transparent.png +0 -0
- data/data/images/ruport_type0.png +0 -0
- data/data/images/stef.jpg +0 -0
- data/data/images/tru256.bmp +0 -0
- data/data/images/web-links.dat +1 -0
- data/data/images/web-links.png +0 -0
- data/data/pdfs/complex_template.pdf +0 -0
- data/data/pdfs/contains_ttf_font.pdf +0 -0
- data/data/pdfs/encrypted.pdf +0 -0
- data/data/pdfs/form.pdf +820 -0
- data/data/pdfs/hexagon.pdf +61 -0
- data/data/pdfs/indirect_reference.pdf +86 -0
- data/data/pdfs/multipage_template.pdf +127 -0
- data/data/pdfs/nested_pages.pdf +118 -0
- data/data/pdfs/page_without_mediabox.pdf +193 -0
- data/data/pdfs/resources_as_indirect_object.pdf +83 -0
- data/data/pdfs/two_hexagons.pdf +90 -0
- data/data/pdfs/version_1_6.pdf +61 -0
- data/data/shift_jis_text.txt +1 -0
- data/lib/prawn.rb +89 -0
- data/lib/prawn/document.rb +706 -0
- data/lib/prawn/document/bounding_box.rb +539 -0
- data/lib/prawn/document/column_box.rb +144 -0
- data/lib/prawn/document/internals.rb +58 -0
- data/lib/prawn/document/span.rb +57 -0
- data/lib/prawn/encoding.rb +87 -0
- data/lib/prawn/errors.rb +80 -0
- data/lib/prawn/font.rb +413 -0
- data/lib/prawn/font/afm.rb +256 -0
- data/lib/prawn/font/dfont.rb +43 -0
- data/lib/prawn/font/ttf.rb +355 -0
- data/lib/prawn/font_metric_cache.rb +46 -0
- data/lib/prawn/graphics.rb +646 -0
- data/lib/prawn/graphics/cap_style.rb +47 -0
- data/lib/prawn/graphics/color.rb +232 -0
- data/lib/prawn/graphics/dash.rb +109 -0
- data/lib/prawn/graphics/join_style.rb +49 -0
- data/lib/prawn/graphics/patterns.rb +126 -0
- data/lib/prawn/graphics/transformation.rb +157 -0
- data/lib/prawn/graphics/transparency.rb +101 -0
- data/lib/prawn/grid.rb +279 -0
- data/lib/prawn/image_handler.rb +44 -0
- data/lib/prawn/images.rb +199 -0
- data/lib/prawn/images/image.rb +49 -0
- data/lib/prawn/images/jpg.rb +91 -0
- data/lib/prawn/images/png.rb +290 -0
- data/lib/prawn/measurement_extensions.rb +50 -0
- data/lib/prawn/measurements.rb +77 -0
- data/lib/prawn/outline.rb +289 -0
- data/lib/prawn/repeater.rb +124 -0
- data/lib/prawn/security.rb +288 -0
- data/lib/prawn/security/arcfour.rb +54 -0
- data/lib/prawn/soft_mask.rb +94 -0
- data/lib/prawn/stamp.rb +136 -0
- data/lib/prawn/text.rb +437 -0
- data/lib/prawn/text/box.rb +141 -0
- data/lib/prawn/text/formatted.rb +7 -0
- data/lib/prawn/text/formatted/arranger.rb +290 -0
- data/lib/prawn/text/formatted/box.rb +614 -0
- data/lib/prawn/text/formatted/fragment.rb +264 -0
- data/lib/prawn/text/formatted/line_wrap.rb +277 -0
- data/lib/prawn/text/formatted/parser.rb +224 -0
- data/lib/prawn/text/formatted/wrap.rb +160 -0
- data/lib/prawn/utilities.rb +46 -0
- data/lib/prawn/version.rb +5 -0
- data/lib/prawn/view.rb +91 -0
- data/manual/absolute_position.pdf +0 -0
- data/manual/basic_concepts/adding_pages.rb +27 -0
- data/manual/basic_concepts/basic_concepts.rb +36 -0
- data/manual/basic_concepts/creation.rb +39 -0
- data/manual/basic_concepts/cursor.rb +33 -0
- data/manual/basic_concepts/measurement.rb +25 -0
- data/manual/basic_concepts/origin.rb +38 -0
- data/manual/basic_concepts/other_cursor_helpers.rb +40 -0
- data/manual/basic_concepts/view.rb +42 -0
- data/manual/bounding_box/bounding_box.rb +39 -0
- data/manual/bounding_box/bounds.rb +49 -0
- data/manual/bounding_box/canvas.rb +24 -0
- data/manual/bounding_box/creation.rb +23 -0
- data/manual/bounding_box/indentation.rb +46 -0
- data/manual/bounding_box/nesting.rb +45 -0
- data/manual/bounding_box/russian_boxes.rb +40 -0
- data/manual/bounding_box/stretchy.rb +31 -0
- data/manual/contents.rb +29 -0
- data/manual/cover.rb +39 -0
- data/manual/document_and_page_options/background.rb +27 -0
- data/manual/document_and_page_options/document_and_page_options.rb +32 -0
- data/manual/document_and_page_options/metadata.rb +23 -0
- data/manual/document_and_page_options/page_margins.rb +38 -0
- data/manual/document_and_page_options/page_size.rb +34 -0
- data/manual/document_and_page_options/print_scaling.rb +20 -0
- data/manual/example_helper.rb +7 -0
- data/manual/graphics/circle_and_ellipse.rb +22 -0
- data/manual/graphics/color.rb +24 -0
- data/manual/graphics/common_lines.rb +30 -0
- data/manual/graphics/fill_and_stroke.rb +42 -0
- data/manual/graphics/fill_rules.rb +37 -0
- data/manual/graphics/gradients.rb +37 -0
- data/manual/graphics/graphics.rb +58 -0
- data/manual/graphics/helper.rb +24 -0
- data/manual/graphics/line_width.rb +35 -0
- data/manual/graphics/lines_and_curves.rb +41 -0
- data/manual/graphics/polygon.rb +29 -0
- data/manual/graphics/rectangle.rb +21 -0
- data/manual/graphics/rotate.rb +28 -0
- data/manual/graphics/scale.rb +41 -0
- data/manual/graphics/soft_masks.rb +46 -0
- data/manual/graphics/stroke_cap.rb +31 -0
- data/manual/graphics/stroke_dash.rb +48 -0
- data/manual/graphics/stroke_join.rb +30 -0
- data/manual/graphics/translate.rb +29 -0
- data/manual/graphics/transparency.rb +35 -0
- data/manual/how_to_read_this_manual.rb +40 -0
- data/manual/images/absolute_position.rb +23 -0
- data/manual/images/fit.rb +21 -0
- data/manual/images/horizontal.rb +25 -0
- data/manual/images/images.rb +40 -0
- data/manual/images/plain_image.rb +18 -0
- data/manual/images/scale.rb +22 -0
- data/manual/images/vertical.rb +28 -0
- data/manual/images/width_and_height.rb +25 -0
- data/manual/layout/boxes.rb +27 -0
- data/manual/layout/content.rb +25 -0
- data/manual/layout/layout.rb +28 -0
- data/manual/layout/simple_grid.rb +23 -0
- data/manual/outline/add_subsection_to.rb +61 -0
- data/manual/outline/insert_section_after.rb +47 -0
- data/manual/outline/outline.rb +32 -0
- data/manual/outline/sections_and_pages.rb +67 -0
- data/manual/repeatable_content/alternate_page_numbering.rb +32 -0
- data/manual/repeatable_content/page_numbering.rb +54 -0
- data/manual/repeatable_content/repeatable_content.rb +32 -0
- data/manual/repeatable_content/repeater.rb +55 -0
- data/manual/repeatable_content/stamp.rb +41 -0
- data/manual/security/encryption.rb +31 -0
- data/manual/security/permissions.rb +38 -0
- data/manual/security/security.rb +28 -0
- data/manual/table.rb +16 -0
- data/manual/text/alignment.rb +44 -0
- data/manual/text/color.rb +24 -0
- data/manual/text/column_box.rb +32 -0
- data/manual/text/fallback_fonts.rb +37 -0
- data/manual/text/font.rb +41 -0
- data/manual/text/font_size.rb +45 -0
- data/manual/text/font_style.rb +23 -0
- data/manual/text/formatted_callbacks.rb +60 -0
- data/manual/text/formatted_text.rb +50 -0
- data/manual/text/free_flowing_text.rb +51 -0
- data/manual/text/inline.rb +41 -0
- data/manual/text/kerning_and_character_spacing.rb +39 -0
- data/manual/text/leading.rb +25 -0
- data/manual/text/line_wrapping.rb +41 -0
- data/manual/text/paragraph_indentation.rb +34 -0
- data/manual/text/positioned_text.rb +38 -0
- data/manual/text/registering_families.rb +48 -0
- data/manual/text/rendering_and_color.rb +37 -0
- data/manual/text/right_to_left_text.rb +47 -0
- data/manual/text/rotation.rb +43 -0
- data/manual/text/single_usage.rb +37 -0
- data/manual/text/text.rb +73 -0
- data/manual/text/text_box_excess.rb +32 -0
- data/manual/text/text_box_extensions.rb +45 -0
- data/manual/text/text_box_overflow.rb +48 -0
- data/manual/text/utf8.rb +28 -0
- data/manual/text/win_ansi_charset.rb +60 -0
- data/prawn.gemspec +45 -0
- data/spec/acceptance/png.rb +25 -0
- data/spec/annotations_spec.rb +74 -0
- data/spec/bounding_box_spec.rb +510 -0
- data/spec/column_box_spec.rb +65 -0
- data/spec/data/curves.pdf +66 -0
- data/spec/destinations_spec.rb +15 -0
- data/spec/document_spec.rb +748 -0
- data/spec/extensions/encoding_helpers.rb +11 -0
- data/spec/extensions/mocha.rb +46 -0
- data/spec/font_metric_cache_spec.rb +52 -0
- data/spec/font_spec.rb +474 -0
- data/spec/formatted_text_arranger_spec.rb +421 -0
- data/spec/formatted_text_box_spec.rb +705 -0
- data/spec/formatted_text_fragment_spec.rb +298 -0
- data/spec/graphics_spec.rb +683 -0
- data/spec/grid_spec.rb +96 -0
- data/spec/image_handler_spec.rb +54 -0
- data/spec/images_spec.rb +153 -0
- data/spec/inline_formatted_text_parser_spec.rb +564 -0
- data/spec/jpg_spec.rb +25 -0
- data/spec/line_wrap_spec.rb +367 -0
- data/spec/measurement_units_spec.rb +25 -0
- data/spec/outline_spec.rb +430 -0
- data/spec/png_spec.rb +245 -0
- data/spec/reference_spec.rb +25 -0
- data/spec/repeater_spec.rb +160 -0
- data/spec/security_spec.rb +158 -0
- data/spec/soft_mask_spec.rb +79 -0
- data/spec/span_spec.rb +44 -0
- data/spec/spec_helper.rb +54 -0
- data/spec/stamp_spec.rb +160 -0
- data/spec/stroke_styles_spec.rb +211 -0
- data/spec/text_at_spec.rb +143 -0
- data/spec/text_box_spec.rb +1043 -0
- data/spec/text_rendering_mode_spec.rb +45 -0
- data/spec/text_spacing_spec.rb +93 -0
- data/spec/text_spec.rb +557 -0
- data/spec/text_with_inline_formatting_spec.rb +35 -0
- data/spec/transparency_spec.rb +91 -0
- data/spec/view_spec.rb +43 -0
- metadata +509 -0
@@ -0,0 +1,25 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# Now that we know how to access the boxes we might as well add some content
|
4
|
+
# to them.
|
5
|
+
#
|
6
|
+
# This can be done by taping into the bounding box for a given grid box or
|
7
|
+
# multi-box with the <code>bounding_box</code> method.
|
8
|
+
#
|
9
|
+
require File.expand_path(File.join(File.dirname(__FILE__),
|
10
|
+
%w[.. example_helper]))
|
11
|
+
|
12
|
+
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
13
|
+
Prawn::ManualBuilder::Example.generate(filename) do
|
14
|
+
# The grid only need to be defined once, but since all the examples should be
|
15
|
+
# able to run alone we are repeating it on every example
|
16
|
+
define_grid(:columns => 5, :rows => 8, :gutter => 10)
|
17
|
+
|
18
|
+
grid([5,0], [7,1]).bounding_box do
|
19
|
+
text "Adding some content to this multi_box.\n" + " _ " * 200
|
20
|
+
end
|
21
|
+
|
22
|
+
grid(6,3).bounding_box do
|
23
|
+
text "Just a little snippet here.\n" + " _ " * 10
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# Examples for using grid layouts.
|
4
|
+
#
|
5
|
+
require File.expand_path(File.join(File.dirname(__FILE__),
|
6
|
+
%w[.. example_helper]))
|
7
|
+
|
8
|
+
Prawn::ManualBuilder::Example.generate("layout.pdf", :page_size => "FOLIO") do
|
9
|
+
|
10
|
+
package "layout" do |p|
|
11
|
+
|
12
|
+
p.example "simple_grid"
|
13
|
+
p.example "boxes"
|
14
|
+
p.example "content"
|
15
|
+
|
16
|
+
p.intro do
|
17
|
+
prose("Prawn has support for two-dimensional grid based layouts out of the box.
|
18
|
+
|
19
|
+
The examples show:")
|
20
|
+
|
21
|
+
list( "How to define the document grid",
|
22
|
+
"How to configure the grid rows and columns gutters",
|
23
|
+
"How to create boxes according to the grid"
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# The document grid on Prawn is just a table-like structure with a defined
|
4
|
+
# number of rows and columns. There are some helpers to create boxes of content
|
5
|
+
# based on the grid coordinates.
|
6
|
+
#
|
7
|
+
# <code>define_grid</code> accepts the following options which are pretty much
|
8
|
+
# self-explanatory: <code>:rows</code>, <code>:columns</code>,
|
9
|
+
# <code>:gutter</code>, <code>:row_gutter</code>, <code>:column_gutter</code>
|
10
|
+
#
|
11
|
+
require File.expand_path(File.join(File.dirname(__FILE__),
|
12
|
+
%w[.. example_helper]))
|
13
|
+
|
14
|
+
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
15
|
+
Prawn::ManualBuilder::Example.generate(filename) do
|
16
|
+
# The grid only need to be defined once, but since all the examples should be
|
17
|
+
# able to run alone we are repeating it on every example
|
18
|
+
define_grid(:columns => 5, :rows => 8, :gutter => 10)
|
19
|
+
text "We defined the grid, roll over to the next page to see its outline"
|
20
|
+
|
21
|
+
start_new_page
|
22
|
+
grid.show_all
|
23
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# We have already seen how to define an outline tree sequentially.
|
4
|
+
#
|
5
|
+
# If you'd like to add nodes to the middle of an outline tree the
|
6
|
+
# <code>add_subsection_to</code> may help you.
|
7
|
+
#
|
8
|
+
# It allows you to insert sections to the outline tree at any point. Just
|
9
|
+
# provide the <code>title</code> of the parent section, the
|
10
|
+
# <code>position</code> you want the new subsection to be inserted
|
11
|
+
# <code>:first</code> or <code>:last</code> (defaults to <code>:last</code>)
|
12
|
+
# and a block to declare the subsection.
|
13
|
+
#
|
14
|
+
# The <code>add_subsection_to</code> block doesn't necessarily create new
|
15
|
+
# sections, it may also create new pages.
|
16
|
+
#
|
17
|
+
# If the parent title provided is the title of a page. The page will be
|
18
|
+
# converted into a section to receive the subsection created.
|
19
|
+
#
|
20
|
+
require File.expand_path(File.join(File.dirname(__FILE__),
|
21
|
+
%w[.. example_helper]))
|
22
|
+
|
23
|
+
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
24
|
+
Prawn::ManualBuilder::Example.generate(filename) do
|
25
|
+
# First we create 10 pages and some default outline
|
26
|
+
(1..10).each do |index|
|
27
|
+
text "Page #{index}"
|
28
|
+
start_new_page
|
29
|
+
end
|
30
|
+
|
31
|
+
outline.define do
|
32
|
+
section("Section 1", :destination => 1) do
|
33
|
+
page :title => "Page 2", :destination => 2
|
34
|
+
page :title => "Page 3", :destination => 3
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Now we will start adding nodes to the previous outline
|
39
|
+
outline.add_subsection_to("Section 1", :first) do
|
40
|
+
outline.section("Added later - first position") do
|
41
|
+
outline.page :title => "Page 4", :destination => 4
|
42
|
+
outline.page :title => "Page 5", :destination => 5
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
outline.add_subsection_to("Section 1") do
|
47
|
+
outline.page :title => "Added later - last position",
|
48
|
+
:destination => 6
|
49
|
+
end
|
50
|
+
|
51
|
+
outline.add_subsection_to("Added later - first position") do
|
52
|
+
outline.page :title => "Another page added later",
|
53
|
+
:destination => 7
|
54
|
+
end
|
55
|
+
|
56
|
+
# The title provided is for a page which will be converted into a section
|
57
|
+
outline.add_subsection_to("Page 3") do
|
58
|
+
outline.page :title => "Last page added",
|
59
|
+
:destination => 8
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# Another way to insert nodes into an existing outline is the
|
4
|
+
# <code>insert_section_after</code> method.
|
5
|
+
#
|
6
|
+
# It accepts the title of the node that the new section will go after and a
|
7
|
+
# block declaring the new section.
|
8
|
+
#
|
9
|
+
# As is the case with <code>add_subsection_to</code> the section added
|
10
|
+
# doesn't need to be a section, it may be just a page.
|
11
|
+
#
|
12
|
+
require File.expand_path(File.join(File.dirname(__FILE__),
|
13
|
+
%w[.. example_helper]))
|
14
|
+
|
15
|
+
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
16
|
+
Prawn::ManualBuilder::Example.generate(filename) do
|
17
|
+
# First we create 10 pages and some default outline
|
18
|
+
(1..10).each do |index|
|
19
|
+
text "Page #{index}"
|
20
|
+
start_new_page
|
21
|
+
end
|
22
|
+
|
23
|
+
outline.define do
|
24
|
+
section("Section 1", :destination => 1) do
|
25
|
+
page :title => "Page 2", :destination => 2
|
26
|
+
page :title => "Page 3", :destination => 3
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# Now we will start adding nodes to the previous outline
|
31
|
+
outline.insert_section_after("Page 2") do
|
32
|
+
outline.section("Section after Page 2") do
|
33
|
+
outline.page :title => "Page 4", :destination => 4
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
outline.insert_section_after("Section 1") do
|
38
|
+
outline.section("Section after Section 1") do
|
39
|
+
outline.page :title => "Page 5", :destination => 5
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# Adding just a page
|
44
|
+
outline.insert_section_after("Page 3") do
|
45
|
+
outline.page :title => "Page after Page 3", :destination => 6
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# Examples for defining the document outline.
|
4
|
+
#
|
5
|
+
require File.expand_path(File.join(File.dirname(__FILE__),
|
6
|
+
%w[.. example_helper]))
|
7
|
+
|
8
|
+
Prawn::ManualBuilder::Example.generate("outline.pdf", :page_size => "FOLIO") do
|
9
|
+
|
10
|
+
package "outline" do |p|
|
11
|
+
|
12
|
+
p.section "Basics" do |s|
|
13
|
+
s.example "sections_and_pages", :eval_source => false
|
14
|
+
end
|
15
|
+
|
16
|
+
p.section "Adding nodes later" do |s|
|
17
|
+
s.example "add_subsection_to", :eval_source => false
|
18
|
+
s.example "insert_section_after", :eval_source => false
|
19
|
+
end
|
20
|
+
|
21
|
+
p.intro do
|
22
|
+
prose("The outline of a PDF document is the table of contents tab you see to the right or left of your PDF viewer.
|
23
|
+
|
24
|
+
The examples include:")
|
25
|
+
|
26
|
+
list( "How to define sections and pages",
|
27
|
+
"How to insert sections and/or pages to a previously defined outline structure"
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# The document outline tree is the set of links used to navigate through the
|
4
|
+
# various document sections and pages.
|
5
|
+
#
|
6
|
+
# To define the document outline we first use the <code>outline</code>
|
7
|
+
# method to lazily instantiate an outline object. Then we use the
|
8
|
+
# <code>define</code> method with a block to start the outline tree.
|
9
|
+
#
|
10
|
+
# The basic methods for creating outline nodes are <code>section</code> and
|
11
|
+
# <code>page</code>. The only difference between the two is that
|
12
|
+
# <code>page</code> doesn't accept a block and will only create leaf nodes
|
13
|
+
# while <code>section</code> accepts a block to create nested nodes.
|
14
|
+
#
|
15
|
+
# <code>section</code> accepts the title of the section and two options:
|
16
|
+
# <code>:destination</code> - a page number to link and <code>:closed</code> -
|
17
|
+
# a boolean value that defines if the nested outline nodes are shown when the
|
18
|
+
# document is open (defaults to true).
|
19
|
+
#
|
20
|
+
# <code>page</code> is very similar to section. It requires a
|
21
|
+
# <code>:title</code> option to be set and accepts a <code>:destination</code>.
|
22
|
+
#
|
23
|
+
# <code>section</code> and <code>page</code> may also be used without the
|
24
|
+
# <code>define</code> method but they will need to instantiate the
|
25
|
+
# <code>outline</code> object every time.
|
26
|
+
#
|
27
|
+
require File.expand_path(File.join(File.dirname(__FILE__),
|
28
|
+
%w[.. example_helper]))
|
29
|
+
|
30
|
+
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
31
|
+
Prawn::ManualBuilder::Example.generate(filename) do
|
32
|
+
# First we create 10 pages just to have something to link to
|
33
|
+
(1..10).each do |index|
|
34
|
+
text "Page #{index}"
|
35
|
+
start_new_page
|
36
|
+
end
|
37
|
+
|
38
|
+
outline.define do
|
39
|
+
section("Section 1", :destination => 1) do
|
40
|
+
page :title => "Page 2", :destination => 2
|
41
|
+
page :title => "Page 3", :destination => 3
|
42
|
+
end
|
43
|
+
|
44
|
+
section("Section 2", :destination => 4) do
|
45
|
+
page :title => "Page 5", :destination => 5
|
46
|
+
|
47
|
+
section("Subsection 2.1", :destination => 6, :closed => true) do
|
48
|
+
page :title => "Page 7", :destination => 7
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# Outside of the define block
|
54
|
+
outline.section("Section 3", :destination => 8) do
|
55
|
+
outline.page :title => "Page 9", :destination => 9
|
56
|
+
end
|
57
|
+
|
58
|
+
outline.page :title => "Page 10", :destination => 10
|
59
|
+
|
60
|
+
# Section and Pages without links. While a section without a link may be
|
61
|
+
# useful to group some pages, a page without a link is useless
|
62
|
+
outline.update do # update is an alias to define
|
63
|
+
section("Section without link") do
|
64
|
+
page :title => "Page without link"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# Below is the code to generate page numbers that alternate being rendered
|
4
|
+
# on the right and left side of the page. The first page will have a "1" in
|
5
|
+
# the bottom right corner. The second page will have a "2" in the bottom
|
6
|
+
# left corner of the page. The third a "3" in the bottom right, etc.
|
7
|
+
require File.expand_path(File.join(File.dirname(__FILE__),
|
8
|
+
%w[.. example_helper]))
|
9
|
+
|
10
|
+
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
11
|
+
Prawn::ManualBuilder::Example.generate(filename) do
|
12
|
+
text "This is the first page!"
|
13
|
+
|
14
|
+
10.times do
|
15
|
+
start_new_page
|
16
|
+
text "Here comes yet another page."
|
17
|
+
end
|
18
|
+
|
19
|
+
string = "<page>"
|
20
|
+
odd_options = { :at => [bounds.right - 150, 0],
|
21
|
+
:width => 150,
|
22
|
+
:align => :right,
|
23
|
+
:page_filter => :odd,
|
24
|
+
:start_count_at => 1 }
|
25
|
+
even_options = { :at => [0, bounds.left],
|
26
|
+
:width => 150,
|
27
|
+
:align => :left,
|
28
|
+
:page_filter => :even,
|
29
|
+
:start_count_at => 2 }
|
30
|
+
number_pages string, odd_options
|
31
|
+
number_pages string, even_options
|
32
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# The <code>number_pages</code> method is a simple way to number the pages of
|
4
|
+
# your document. It should be called towards the end of the document since
|
5
|
+
# pages created after the call won't be numbered.
|
6
|
+
#
|
7
|
+
# It accepts a string and a hash of options:
|
8
|
+
#
|
9
|
+
# <code>start_count_at</code> is the value from which to start numbering pages
|
10
|
+
#
|
11
|
+
# <code>total_pages</code> If provided, will replace <code>total</code> with
|
12
|
+
# the value given. Useful for overriding the total number of pages when using
|
13
|
+
# the start_count_at option.
|
14
|
+
#
|
15
|
+
# <code>page_filter</code>, which is one of: <code>:all</code>,
|
16
|
+
# <code>:odd</code>, <code>:even</code>, an array, a range, or a Proc that
|
17
|
+
# receives the page number as an argument and should return true if the page
|
18
|
+
# number should be printed on that page.
|
19
|
+
#
|
20
|
+
# <code>color</code> which accepts the same values as <code>fill_color</code>
|
21
|
+
#
|
22
|
+
# As well as any option accepted by <code>text_box</code>
|
23
|
+
#
|
24
|
+
require File.expand_path(File.join(File.dirname(__FILE__),
|
25
|
+
%w[.. example_helper]))
|
26
|
+
|
27
|
+
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
28
|
+
Prawn::ManualBuilder::Example.generate(filename) do
|
29
|
+
text "This is the first page!"
|
30
|
+
|
31
|
+
10.times do
|
32
|
+
start_new_page
|
33
|
+
text "Here comes yet another page."
|
34
|
+
end
|
35
|
+
|
36
|
+
string = "page <page> of <total>"
|
37
|
+
# Green page numbers 1 to 7
|
38
|
+
options = { :at => [bounds.right - 150, 0],
|
39
|
+
:width => 150,
|
40
|
+
:align => :right,
|
41
|
+
:page_filter => (1..7),
|
42
|
+
:start_count_at => 1,
|
43
|
+
:color => "007700" }
|
44
|
+
number_pages string, options
|
45
|
+
|
46
|
+
# Gray page numbers from 8 on up
|
47
|
+
options[:page_filter] = lambda{ |pg| pg > 7}
|
48
|
+
options[:start_count_at] = 8
|
49
|
+
options[:color] = "333333"
|
50
|
+
number_pages string, options
|
51
|
+
|
52
|
+
start_new_page
|
53
|
+
text "See. This page isn't numbered and doesn't count towards the total."
|
54
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# Examples for stamps and repeaters.
|
4
|
+
#
|
5
|
+
require File.expand_path(File.join(File.dirname(__FILE__),
|
6
|
+
%w[.. example_helper]))
|
7
|
+
|
8
|
+
Prawn::ManualBuilder::Example.generate("repeatable_content.pdf", :page_size => "FOLIO") do
|
9
|
+
|
10
|
+
package "repeatable_content" do |p|
|
11
|
+
|
12
|
+
p.example "repeater", :eval_source => false
|
13
|
+
p.example "stamp"
|
14
|
+
p.example "page_numbering", :eval_source => false
|
15
|
+
p.example "alternate_page_numbering", :eval_source => false
|
16
|
+
|
17
|
+
p.intro do
|
18
|
+
prose("Prawn offers two ways to handle repeatable content blocks. Repeater is useful for content that gets repeated at well defined intervals while Stamp is more appropriate if you need better control of when to repeat it.
|
19
|
+
|
20
|
+
There is also one very specific helper for numbering pages.
|
21
|
+
|
22
|
+
The examples show:")
|
23
|
+
|
24
|
+
list( "How to repeat content on several pages with a single invocation",
|
25
|
+
"How to create a new Stamp",
|
26
|
+
'How to "stamp" the content block on the page',
|
27
|
+
"How to number the document pages with one simple call"
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# The <code>repeat</code> method is quite versatile when it comes to define
|
4
|
+
# the intervals at which the content block should repeat.
|
5
|
+
#
|
6
|
+
# The interval may be a symbol (<code>:all</code>, <code>:odd</code>,
|
7
|
+
# <code>:even</code>), an array listing the pages, a range or a
|
8
|
+
# <code>Proc</code> that receives the page number as an argument and should
|
9
|
+
# return true if the content is to be repeated on the given page.
|
10
|
+
#
|
11
|
+
# You may also pass an option <code>:dynamic</code> to reevaluate the code block
|
12
|
+
# on every call which is useful when the content changes based on the page
|
13
|
+
# number.
|
14
|
+
#
|
15
|
+
# It is also important to say that no matter where you define the repeater it
|
16
|
+
# will be applied to all matching pages.
|
17
|
+
#
|
18
|
+
require File.expand_path(File.join(File.dirname(__FILE__),
|
19
|
+
%w[.. example_helper]))
|
20
|
+
|
21
|
+
filename = File.basename(__FILE__).gsub('.rb', '.pdf')
|
22
|
+
Prawn::ManualBuilder::Example.generate(filename) do
|
23
|
+
repeat(:all) do
|
24
|
+
draw_text "All pages", :at => bounds.top_left
|
25
|
+
end
|
26
|
+
|
27
|
+
repeat(:odd) do
|
28
|
+
draw_text "Only odd pages", :at => [0,0]
|
29
|
+
end
|
30
|
+
|
31
|
+
repeat(:even) do
|
32
|
+
draw_text "Only even pages", :at => [0,0]
|
33
|
+
end
|
34
|
+
|
35
|
+
repeat([1,3,7]) do
|
36
|
+
draw_text "Only on pages 1, 3 and 7", :at => [100,0]
|
37
|
+
end
|
38
|
+
|
39
|
+
repeat(2..4) do
|
40
|
+
draw_text "From the 2nd to the 4th page", :at => [300,0]
|
41
|
+
end
|
42
|
+
|
43
|
+
repeat(lambda { |pg| pg % 3 == 0 }) do
|
44
|
+
draw_text "Every third page", :at => [250, 20]
|
45
|
+
end
|
46
|
+
|
47
|
+
repeat(:all, :dynamic => true) do
|
48
|
+
draw_text page_number, :at => [500, 0]
|
49
|
+
end
|
50
|
+
|
51
|
+
10.times do
|
52
|
+
start_new_page
|
53
|
+
draw_text "A wonderful page", :at => [400,400]
|
54
|
+
end
|
55
|
+
end
|