# Is it possible to justify table title using PDF::SimpleTable

**URL:** <https://www.ruby-forum.com/t/is-it-possible-to-justify-table-title-using-pdf-simpletable/172584>\
**Category:** Ruby\
**Created:** [July 23, 2009, 3:47pm UTC](https://www.ruby-forum.com/t/is-it-possible-to-justify-table-title-using-pdf-simpletable/172584 "2009-07-23T15:47:19Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jimb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f4b2a3/32.png) [@jimb](https://www.ruby-forum.com/u/jimb)\
**Post date:** [July 23, 2009, 3:47pm UTC](https://www.ruby-forum.com/t/is-it-possible-to-justify-table-title-using-pdf-simpletable/172584/1 "2009-07-23T15:47:19Z")

</div>

Hi,

I’m making a pdf using the PDF::Writer gem.  
In the pdf I need a table, which I make using PDF::SimpleTable

The code:

pdf = PDF::Writer.new  
PDF::SimpleTable.new do |tab|  
tab.title = “My title”  
tab.column\_order.push(\*%w(field entry))  
tab.columns[“field”] = PDF::SimpleTable::Column.new(“field”)  
tab.columns[“entry”] = PDF::SimpleTable::Column.new(“entry”)  
tab.show\_lines = :none  
tab.show\_headings = false  
tab.shade\_rows = :none  
tab.position = :left  
tab.orientation = :right  
data = [  
{ “field” , “ **Last name** ”, “entry” , “#{applicant.last\_name}” }

etc …

Is it possible to justify the title of the table to the left. Currently  
it positions itself above the table in the dead center of the table.  
I would like to have the title above the table, but on the left hand  
side.

I’ve downloaded and read Austin Z.'s pdf manual from rubyforge, but  
I can only find commands to change the title’s color, font size and gap  
to table contents.

I’ve also tried:  
tab.title = “My title”, :justify =\> left  
tab.title\_justify = left

both of which throw errors.

Would be very appreciative of any help.

---

<div class="post-metadata">

**Author:** ![jimb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f4b2a3/32.png) [@jimb](https://www.ruby-forum.com/u/jimb)\
**Post date:** [July 23, 2009, 3:54pm UTC](https://www.ruby-forum.com/t/is-it-possible-to-justify-table-title-using-pdf-simpletable/172584/2 "2009-07-23T15:54:24Z")

</div>

On Thu, Jul 23, 2009 at 9:47 AM, Jim B.[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Would be very appreciative of any help.

Use Prawn instead. PDF::Writer is no longer supported, except for  
critical bug fixes.

[http://prawn.majesticseacreature.com/](http://prawn.majesticseacreature.com/)

---

<div class="post-metadata">

**Author:** ![jimb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f4b2a3/32.png) [@jimb](https://www.ruby-forum.com/u/jimb)\
**Post date:** [July 23, 2009, 6:13pm UTC](https://www.ruby-forum.com/t/is-it-possible-to-justify-table-title-using-pdf-simpletable/172584/3 "2009-07-23T18:13:00Z")

</div>

On Thu, Jul 23, 2009 at 11:34 AM, Jim B.[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> get font\_style on a per cell basis within a table.  
> There are actually three ways to do it:

# may require the 0.5 pre-release, can’t remember

table [{ :text =\> “blah”, :font\_style =\> :bold }, “another field”]

and also:

require “prawn/format”  
table [[“ **foo** ”, “…”]]

Both of these have some issues, but work fine for basic needs.  
Patches welcome if you run into problems.

> What does ‘no longer supported’ actually mean?  
> No longer being developed or is there some other compatibility issue to  
> consider?

Well, PDF::Writer will never really support UTF-8, the patches to make  
it run on Ruby 1.9 that appeared recently only do so in a very basic  
level, and there are many subtle oddities / bugs that never got fixed.  
The API is very poor by modern Ruby standards (even if it was great  
in its time), and performance is abysmal. Also, technically speaking  
I’m the maintainer of PDF::Writer right now, and my solution to ‘fix’  
it was to build Prawn, after I did some minor cleanup and bug fixes  
that were collecting dust for a couple years.

The only reason PDF::Writer isn’t officially dead yet is because Prawn  
isn’t officially alive yet. But folks keep on contributing, and I  
shave off time where I can. I’m hoping to have something ready by the  
year end.

-greg

---

<div class="post-metadata">

**Author:** ![jimb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f4b2a3/32.png) [@jimb](https://www.ruby-forum.com/u/jimb)\
**Post date:** [July 23, 2009, 6:14pm UTC](https://www.ruby-forum.com/t/is-it-possible-to-justify-table-title-using-pdf-simpletable/172584/4 "2009-07-23T18:14:45Z")

</div>

On Thu, Jul 23, 2009 at 12:11 PM, Gregory  
Brown[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> On Thu, Jul 23, 2009 at 11:34 AM, Jim B.[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> There are actually three ways to do it:
> 
> # may require the 0.5 pre-release, can’t remember
> 
> table [{ :text =\> “blah”, :font\_style =\> :bold }, “another field”]
> 
> and also:
> 
> require “prawn/format”  
> table [[“ **foo** ”, “…”]]

- but the third way (manually building a Prawn::Table::Cell), is not  
recommended

---

<div class="post-metadata">

**Author:** ![jimb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f4b2a3/32.png) [@jimb](https://www.ruby-forum.com/u/jimb)\
**Post date:** [July 23, 2009, 5:34pm UTC](https://www.ruby-forum.com/t/is-it-possible-to-justify-table-title-using-pdf-simpletable/172584/5 "2009-07-23T17:34:25Z")

</div>

> Use Prawn instead. PDF::Writer is no longer supported, except for  
> critical bug fixes.
> 
> [http://prawn.majesticseacreature.com/](http://prawn.majesticseacreature.com/)

Thanks for that.  
I just downloaded and installed the prawn gem and have spent the past  
hour and a half recreating my table using prawn.

One issue which puts me off using it however, is that there is no way to  
get font\_style on a per cell basis within a table.

What does ‘no longer supported’ actually mean?  
No longer being developed or is there some other compatibility issue to  
consider?

---

<div class="post-metadata">

**Author:** ![jimb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f4b2a3/32.png) [@jimb](https://www.ruby-forum.com/u/jimb)\
**Post date:** [July 23, 2009, 6:39pm UTC](https://www.ruby-forum.com/t/is-it-possible-to-justify-table-title-using-pdf-simpletable/172584/6 "2009-07-23T18:39:56Z")

</div>

On Thu, Jul 23, 2009 at 12:31 PM, Jim B.[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > # may require the 0.5 pre-release, can’t remember
> > 
> > table [{ :text =\> “blah”, :font\_style =\> :bold }, “another field”]
> 
> Great, that works perfectly (also on prawn 0.5.0.1)  
> I had based my previous statement that this was not possible on one of  
> your posts to google groups:  
> [http://groups.google.com/group/prawn-ruby/browse\_thread/thread/4dbd89db83c35c85](http://groups.google.com/group/prawn-ruby/browse_thread/thread/4dbd89db83c35c85)

Ah, I see. Yeah, I’ve been quitely merging patchs and adding things,  
probably not the best of practices.  
Prawn will have a renaissance of activity and buzz after 0.5.1,  
because I’ll be doing a better job of keeping folks informed of what’s  
to come and what’s there by then.

That’s why it’s taking me so long, I’m trying to transition from an  
alpha product to something that looks like it might actually see a 1.0  
someday.  
Things will get better soon. 🙂

-greg

---

<div class="post-metadata">

**Author:** ![jimb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f4b2a3/32.png) [@jimb](https://www.ruby-forum.com/u/jimb)\
**Post date:** [July 23, 2009, 6:31pm UTC](https://www.ruby-forum.com/t/is-it-possible-to-justify-table-title-using-pdf-simpletable/172584/7 "2009-07-23T18:31:48Z")

</div>

> # may require the 0.5 pre-release, can’t remember
> 
> table [{ :text =\> “blah”, :font\_style =\> :bold }, “another field”]

Great, that works perfectly (also on prawn 0.5.0.1)  
I had based my previous statement that this was not possible on one of  
your posts to google groups:  
[http://groups.google.com/group/prawn-ruby/browse\_thread/thread/4dbd89db83c35c85](http://groups.google.com/group/prawn-ruby/browse_thread/thread/4dbd89db83c35c85)

Thanks also for your answer as to why PDF::Writer isn’t such a good  
option.  
I will use prawn for pdf generation from now on.

Thanks again.
