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

J

Jim Burgess

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" , "<b>Last name</b>", "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 Ziegler'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.
 
J

Jim Burgess

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

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?
 
G

Gregory Brown

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.

There are actually three ways to do it:

# may require the 0.5 pre-release, can't remember
table [{ :text =3D> "blah", :font_style =3D> :bold }, "another field"]

and also:

require "prawn/format"
table [[ "<b>foo</b>", "..."]]

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
 
G

Gregory Brown

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 [[ "<b>foo</b>", "..."]]

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

Jim Burgess

# 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.
 
G

Gregory Brown

# 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. :)

-greg
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top