How to do that with PDF Writer? (text inside a box)

How can I make appear text inside a box, something like this:

       -----------------
       -         text inside        -
       -----------------

This should get you started. This is some partial code that I had
written for me a few years ago while trying to solve similar seemingly
simple tasks. Call the add_boxed_text function which in turn calls the
add_cell function. I think there are no other dependencies from my
source file in this - hopefully self contained. If not, let me know and
I’ll dig in further.

Michael

Adds a one cell table

def add_cell(text, options = {})
# Check basic parameters
width = options.delete(:width) || @pdf.margin_width
justification = options.delete(:justification) || :left
# Define table defaults and current options
defaults = {
:font_size => 11,
:inner_line_style => PDFRapport::stroke,
:line_color => Color::RGB::Black,
:orientation => :center,
:outer_line_style => PDFRapport::stroke,
:position => :center,
:shade_color => Color::RGB::Grey80,
:shade_color2 => Color::RGB::Grey70,
:shade_rows => :none,
:show_headings => false,
:show_lines => :all,
:text_color => Color::RGB::Black,
}
options = defaults.merge options if options.is_a? Hash
options = defaults unless options.is_a? Hash
# Create SimpleTable
PDF::SimpleTable.new do |tab|
# Columns names and orders
tab.column_order = [“1”]
# Create SimpleColumns for this table with provided widths and
justifications
tab.columns[“1”] = PDF::SimpleTable::Column.new(“1”) do |col|
col.width = width
col.justification = justification
end
# Set preferences for the table and cells
apply_table_options tab, options
# Insert text into message
container = [ { “1” => text.to_s } ]
log “add_cell :: replacing row with #{container.inspect}”
tab.data.replace container
# Render the table on the
tab.render_on @pdf
end
end

Adds a cell with no

def add_boxed_text(text, options = {})
defaults = { :show_lines => :all, :font_size => 11, :shade_rows =>
:none, }
add_cell text, defaults.merge(options)
end

John S. wrote:

How can I make appear text inside a box, something like this:

       -----------------
       -         text inside        -
       -----------------

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs