In my rails app I need to create pdf reports on the fly. I have
installed railspdf, wich is working fine. But, how can I create tables
and paragraphs and stuff? Can I mimic an .rhtml file (using <% for
…%> etc? Or is it wise to use Ruby::PDF directly? Is there anyone out
there with experience in this, and who is willing to share his findings?
Thx
Hi oom tuinstoel
See if this tutorial helps you,
http://www.artima.com/rubycs/articles/pdf_writer.html
Victor
I switched to using rtex from PDF::Writer due to conflicts with
Transaction::Simple (which is used by both ActiveRecord and
PDF::Writer). I
think those conflicts may be gone now, but I like the rtex system in any
case. I wrote a bit about it here:
http://convergentarts.com/articles/2006/03/21/rtex-pdf-mojo-on-windows
And the link to rtex:
http://codefluency.com/pages/rtex
On my site I mention posting a sample table, which I haven’t done yet.
Here’s a very simple table:
\begin{tabular}{l V{3.5cm} r}
foo & blah & bar \
foo & blah blah & bar \
foo & blah blah blah blah blah blah
& bar \
\end{tabular}
That would be in the context of a .rtex page. See my blog if you’re
interested.
And now, to address your original question :)… to create a table using
PDF::Writer, try SimpleTable:
t = PDF::SimpleTable.new do |t|
t.column_order.push(*%w(player parents email address citystzip
birthdate))
t.columns["player"] = PDF::SimpleTable::Column.new("player") {
|col|
col.heading = “Player”
}
…
Then you render it to a pdf:
t.render_on(@pdf)
PDF::Writer has pretty good documentation for this:
http://ruby-pdf.rubyforge.org/pdf-writer/
-Tom
On 5/24/06, Tom W. [email protected] wrote:
I switched to using rtex from PDF::Writer due to conflicts with
Transaction::Simple (which is used by both ActiveRecord and PDF::Writer). I
think those conflicts may be gone now, but I like the rtex system in any
case. I wrote a bit about it here:
It would be useful if someone could verify that this is the case. The
current version of Transaction::Simple should now be bundled with
Rails, with the long-term goal of removing it from the bundle.
-austin
Tom W. wrote:
And now, to address your original question :)… to create a table using
PDF::Writer, try SimpleTable:t = PDF::SimpleTable.new do |t|
t.column_order.push(*%w(player parents email address citystzip
birthdate))t.columns["player"] = PDF::SimpleTable::Column.new("player") {
|col|
col.heading = “Player”
}
…Then you render it to a pdf:
This is what I do:
table = PDF::SimpleTable.new
table.data = @children
table.column_order.push(*%w(firstname group_id))
table.columns[“firstname”] = PDF::SimpleTable::Column.new(“firstname”) {
|col|
col.heading = “Firstname”
}
to get a table. My problem is: how do I get values in there? Imean,
children belong to groups, and to parents (real tablenames). What would
be the easiest way to get groups.name and parent.lastname etc in the
table?
table.render_on(pdf)