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

**URL:** <https://www.ruby-forum.com/t/how-to-do-that-with-pdf-writer-text-inside-a-box/125834>\
**Category:** Rails\
**Created:** [January 12, 2008, 5:26pm UTC](https://www.ruby-forum.com/t/how-to-do-that-with-pdf-writer-text-inside-a-box/125834 "2008-01-12T17:26:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![captaffy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f04885/32.png) [@captaffy](https://www.ruby-forum.com/u/captaffy)\
**Post date:** [January 12, 2008, 5:26pm UTC](https://www.ruby-forum.com/t/how-to-do-that-with-pdf-writer-text-inside-a-box/125834/1 "2008-01-12T17:26:18Z")

</div>

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

```
       -----------------
       - text inside -
       -----------------
```

---

<div class="post-metadata">

**Author:** ![captaffy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f04885/32.png) [@captaffy](https://www.ruby-forum.com/u/captaffy)\
**Post date:** [January 12, 2008, 6:07pm UTC](https://www.ruby-forum.com/t/how-to-do-that-with-pdf-writer-text-inside-a-box/125834/2 "2008-01-12T18:07:11Z")

</div>

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 -
> -----------------
> ```
