| Class | Rupdf::Base |
| In: |
lib/rupdf/base.rb
|
| Parent: | Ruport::Formatter::PDF |
This class adds some more helpers to common pdf-writer functions
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.
# 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.
# 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.
# 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.
# 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
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.
# 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.
# 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.
# 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.
# 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