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.
164bad3bfc412e3d0442d199a3780eff?d=identicon&s=25 oom tuinstoel (Guest)
on 2006-05-24 16: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
15c43b9d84557e8547eea759ee3ba016?d=identicon&s=25 Victor Fan (victorfan)
on 2006-05-24 17:49
Hi oom tuinstoel

See if this tutorial helps you,

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

Victor
6b655cbfb773c06803214fdf03fa8d1c?d=identicon&s=25 Tom Wilcoxen (Guest)
on 2006-05-24 18:37
(Received via mailing list)
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...

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
31ab75f7ddda241830659630746cdd3a?d=identicon&s=25 Austin Ziegler (Guest)
on 2006-05-24 19:12
(Received via mailing list)
On 5/24/06, Tom Wilcoxen <tomwilcoxen@gmail.com> 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
164bad3bfc412e3d0442d199a3780eff?d=identicon&s=25 oom tuinstoel (Guest)
on 2006-06-04 17:00
Tom Wilcoxen 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)
This topic is locked and can not be replied to.