The Basic Format uses template files (.tlf) created with the Thinreports Basic Editor. You can initialize a report with a layout and manipulate items on a page.
Item Finder
You can access items in a template using page.item(:id) or the shorthand page[:id].
Text Blocks
Set values for text blocks using .value('text'), .value = 'text', or the shorthand page[:id] = 'text'. You can also use .set('value', color: '#hex') for specific attributes.
Image Blocks
Set image sources using .src('/path/to/image') or page[:id] = '/path/to/image'. It supports file paths and IO objects (e.g., from open-uri).
Attributes and Visibility
.hide / .show: Toggle visibility..visible(true/false): Set visibility explicitly..visible?: Check visibility status..id: Get the item ID.
Styling
Apply styles to items using the .style method:
- Text Styles:
:color, :bold, :italic, :linethrough, :underline, :font_size, :align (:left, :center, :right), and :valign (:top, :center, :bottom). - Rectangle Styles:
:border_color, :border_width, :fill_color. - Bulk Styling: Use
.styles(key: value, ...) to set multiple attributes at once.
Bulk Value Setting
Use page.values to set multiple item values simultaneously using a hash.
require 'thinreports'
report = Thinreports::Report.new layout: 'report.tlf'
report.start_new_page do |page|
# Item Finder
page.item(:text_block).value('Pure Ruby')
page[:text_block] = 'Pure Ruby'
# Image block
page[:image_block] = '/path/to/image.png'
# Styles
page.item(:text).style(:color, 'red').style(:bold, true)
page.item(:text).styles(color: '#00000', align: :right)
# Bulk setting
page.values text_block_a: 'value', text_block_b: 'value'
end
report.generate(filename: 'report.pdf')