# Forum: Ruby on Rails pdf on the fly

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
on 2006-05-24 18:37
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
on 2006-05-24 19:49
Hi oom tuinstoel

See if this tutorial helps you,

http://www.artima.com/rubycs/articles/pdf_writer.html

Victor
on 2006-05-24 20:37
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...

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|
birthdate))

t.columns["player"] = PDF::SimpleTable::Column.new("player") {
|col|
}
...

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 2006-05-24 21:12
On 5/24/06, Tom W. <removed_email_address@domain.invalid> 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
on 2006-06-04 19:00
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|
>         }
> ...
>
> 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|
table.render_on(pdf)