Class Rupdf::Base
In: lib/rupdf/base.rb
Parent: Ruport::Formatter::PDF

This class adds some more helpers to common pdf-writer functions

Methods

Public Class methods

Extend this class and call this method in a block format to define the body. Default margins are set. Please redefine by calling the margins method.

[Source]

    # File lib/rupdf/base.rb, line 80
80:     def self.define_body &block
81:       define_method "build_body" do 
82:         margins(150, 70, 150, 70)
83:         instance_eval(&block)
84:       end
85:     end

Extend this class and call this method to define a footer.

[Source]

    # File lib/rupdf/base.rb, line 88
88:     def self.define_footer &block
89:       define_method "build_footer" do
90:         add_persistent_object do
91:           instance_eval(&block)
92:         end
93:       end
94:     end

Extend this class and call this method in a block format to define the header.

[Source]

    # File lib/rupdf/base.rb, line 69
69:     def self.define_header &block
70:       define_method "build_header" do
71:         add_persistent_object do
72:           instance_eval(&block)
73:         end
74:       end
75:     end

Define configuration variables which can be passed at runtime when generating the pdf.

[Source]

     # File lib/rupdf/base.rb, line 105
105:     def self.define_variables(*args)
106:       args.each do |var|
107:         self.opt_reader var
108:         Renderer.option var
109:       end
110:     end

Public Instance methods

This is useful for adding a persistent page objects such as a header or a footer to all pages. Not this is not required when calling the define_header and define_footer class methods.

[Source]

    # File lib/rupdf/base.rb, line 35
35:     def add_persistent_object
36:       pdf_writer.open_object do |object|
37:         yield
38:         pdf_writer.close_object
39:         pdf_writer.add_object(object, :all_pages)
40:       end
41:     end

This makes the call to actually render the pdf.

[Source]

     # File lib/rupdf/base.rb, line 98
 98:     def finalize_document
 99:       render_pdf
100:     end

Simple images addition in line with the current pdf point please refer to pdfwriter rdoc for options list.

[Source]

    # File lib/rupdf/base.rb, line 52
52:     def image(image_path, options = {})
53:       pdf_writer.image(image_path, options)
54:     end

Positioned image. You must pass the coordinates where the image is to be added. Coordinates define the position of the top right of the image.

[Source]

    # File lib/rupdf/base.rb, line 58
58:     def image_positioned(image_path, x, y, width = nil, height = nil)
59:       pdf_writer.add_image_from_file(image_path, x, y, width, height)
60:     end

Set the margins in points. This is useful for the main body. To avoid overlapping the headers and footers.

[Source]

    # File lib/rupdf/base.rb, line 45
45:     def margins(top, left, bottom, right)
46:       pdf_writer.margins_pt(top, left, bottom, right)
47:     end

Start a new page

[Source]

    # File lib/rupdf/base.rb, line 63
63:     def new_page
64:       pdf_writer.start_new_page
65:     end

[Validate]