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

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.

On Thu, Jul 23, 2009 at 9:47 AM, Jim B.[email protected]
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/

On Thu, Jul 23, 2009 at 11:34 AM, Jim B.[email protected]
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

On Thu, Jul 23, 2009 at 12:11 PM, Gregory
Brown[email protected] wrote:

On Thu, Jul 23, 2009 at 11:34 AM, Jim B.[email protected] 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

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

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?

On Thu, Jul 23, 2009 at 12:31 PM, Jim B.[email protected]
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

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. :slight_smile:

-greg

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

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.

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