Class: ReportBuilder::Builder::Pdf
- Inherits:
-
ReportBuilder::Builder
- Object
- ReportBuilder::Builder
- ReportBuilder::Builder::Pdf
- Defined in:
- lib/reportbuilder/builder/pdf.rb
Overview
Rtf Builder. Based on Prawn
Instance Attribute Summary collapse
-
#pdf ⇒ Object
Pdf object.
Attributes inherited from ReportBuilder::Builder
Class Method Summary collapse
Instance Method Summary collapse
- #at_end ⇒ Object
- #default_options ⇒ Object
-
#header(level, t) ⇒ Object
Add a header of level
level
with textt
Level works similar to h. -
#html(t) ⇒ Object
Do nothing on this builder.
-
#initialize(builder, options) ⇒ Pdf
constructor
Creates a new Pdf object Params: *
builder
: A ReportBuilder::Builder object or other with same interface *options
: Hash of options. -
#new_page ⇒ Object
Start a new page! (duh).
-
#out ⇒ Object
Returns pdf code for report.
- #parse ⇒ Object
-
#preformatted(t) ⇒ Object
Add preformatted text.
-
#save(filename) ⇒ Object
Save pdf file.
-
#text(t) ⇒ Object
Add a paragraph of text.
Methods inherited from ReportBuilder::Builder
#graph, #graph_entry, #image, #image_blob, #image_filename, inherited, inherited_classes, #parse_cycle, #parse_element, #section, #table, #table_entry, #toc_entry
Constructor Details
#initialize(builder, options) ⇒ Pdf
Creates a new Pdf object Params:
-
builder
: A ReportBuilder::Builder object or other with same interface -
options
: Hash of options.
16 17 18 19 20 21 |
# File 'lib/reportbuilder/builder/pdf.rb', line 16 def initialize(builder, ) super @pdf=Prawn::Document.new() @pdf.font_size=@options[:font_size] end |
Instance Attribute Details
#pdf ⇒ Object
Pdf object.
11 12 13 |
# File 'lib/reportbuilder/builder/pdf.rb', line 11 def pdf @pdf end |
Class Method Details
.code ⇒ Object
23 24 25 |
# File 'lib/reportbuilder/builder/pdf.rb', line 23 def self.code %w{pdf} end |
Instance Method Details
#at_end ⇒ Object
59 60 61 62 |
# File 'lib/reportbuilder/builder/pdf.rb', line 59 def at_end @pdf.number_pages(@options[:number_pages], [@pdf.bounds.right - 50, 0] ) if @options[:numerate_pages] end |
#default_options ⇒ Object
33 34 35 36 37 |
# File 'lib/reportbuilder/builder/pdf.rb', line 33 def { :font_size=>12 } end |
#header(level, t) ⇒ Object
Add a header of level level
with text t
Level works similar to h
44 45 46 47 48 |
# File 'lib/reportbuilder/builder/pdf.rb', line 44 def header(level, t) @pdf.pad 5 do @pdf.text t, {:size=>15-level*1.5,:align=>:center} end end |
#html(t) ⇒ Object
Do nothing on this builder
74 75 76 |
# File 'lib/reportbuilder/builder/pdf.rb', line 74 def html(t) # Nothing end |
#new_page ⇒ Object
Start a new page! (duh)
50 51 52 |
# File 'lib/reportbuilder/builder/pdf.rb', line 50 def new_page @pdf.start_new_page end |
#out ⇒ Object
Returns pdf code for report
64 65 66 67 |
# File 'lib/reportbuilder/builder/pdf.rb', line 64 def out at_end @pdf.render end |
#parse ⇒ Object
26 27 28 29 30 31 |
# File 'lib/reportbuilder/builder/pdf.rb', line 26 def parse unless @builder.no_title header(0,@builder.name) end parse_cycle(@builder) end |
#preformatted(t) ⇒ Object
Add preformatted text.
54 55 56 57 58 |
# File 'lib/reportbuilder/builder/pdf.rb', line 54 def preformatted(t) @pdf.font("Courier") do @pdf.text t end end |
#save(filename) ⇒ Object
Save pdf file
69 70 71 72 |
# File 'lib/reportbuilder/builder/pdf.rb', line 69 def save(filename) at_end @pdf.render_file(filename) end |
#text(t) ⇒ Object
Add a paragraph of text.
39 40 41 |
# File 'lib/reportbuilder/builder/pdf.rb', line 39 def text(t) @pdf.text(t) end |