# Pdf on the fly

**URL:** <https://www.ruby-forum.com/t/pdf-on-the-fly/95197>\
**Category:** Rails\
**Created:** [May 24, 2006, 4:37pm UTC](https://www.ruby-forum.com/t/pdf-on-the-fly/95197 "2006-05-24T16:37:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [May 24, 2006, 4:37pm UTC](https://www.ruby-forum.com/t/pdf-on-the-fly/95197/1 "2006-05-24T16:37:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [May 24, 2006, 5:49pm UTC](https://www.ruby-forum.com/t/pdf-on-the-fly/95197/2 "2006-05-24T17:49:22Z")

</div>

Hi oom tuinstoel

See if this tutorial helps you,

[http://www.artima.com/rubycs/articles/pdf\_writer.html](http://www.artima.com/rubycs/articles/pdf_writer.html)

Victor

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [May 24, 2006, 6:37pm UTC](https://www.ruby-forum.com/t/pdf-on-the-fly/95197/3 "2006-05-24T18:37:12Z")

</div>

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](http://convergentarts.com/articles/2006/03/21/rtex-pdf-mojo-on-windows)

And the link to rtex:

[http://codefluency.com/pages/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/](http://ruby-pdf.rubyforge.org/pdf-writer/)

-Tom

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [May 24, 2006, 7:12pm UTC](https://www.ruby-forum.com/t/pdf-on-the-fly/95197/4 "2006-05-24T19:12:40Z")

</div>

On 5/24/06, Tom W. [removed\_email\_address@domain.invalid](mailto: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

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 4, 2006, 5:00pm UTC](https://www.ruby-forum.com/t/pdf-on-the-fly/95197/5 "2006-06-04T17:00:48Z")

</div>

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)
