# Pdf simpletable help needed

**URL:** <https://www.ruby-forum.com/t/pdf-simpletable-help-needed/63817>\
**Category:** Rails\
**Created:** [June 19, 2006, 5:27pm UTC](https://www.ruby-forum.com/t/pdf-simpletable-help-needed/63817 "2006-06-19T17:27:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jjkiesch](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc79bd/32.png) [@jjkiesch](https://www.ruby-forum.com/u/jjkiesch)\
**Post date:** [June 19, 2006, 5:27pm UTC](https://www.ruby-forum.com/t/pdf-simpletable-help-needed/63817/1 "2006-06-19T17:27:23Z")

</div>

i am trying to generate a pdf of all of the users in an application that  
i have built. i am still pretty new to ruby and rails so i don’t know  
the best way to go about it.

here is my controller code:

require ‘pdf/writer’  
require ‘pdf/simpletable’

class ReportsController \< ApplicationController

def test  
\_pdf = PDF::Writer.new  
table = PDF::SimpleTable.new  
user\_data = []  
for user in User.find(:all)  
user\_data \<\< user.attributes  
end  
table.data = user\_data  
table.render\_on(\_pdf)

```
send_data _pdf.render, :filename => 'hello.pdf', :type => 

```

‘application/pdf’  
end  
end

i couldn’t figure out a better way to get the data out of the user model  
than looping through and adding the attributes to an empty array. then i  
used the array as my data for creating the pdf table.

currently i am getting an error saying that my columns are not defined,  
yet using the console, i can see that my array is formatted just like  
the ones in the examples.

any help would be greatly appreciated.  
Thanks

---

<div class="post-metadata">

**Author:** ![jjkiesch](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc79bd/32.png) [@jjkiesch](https://www.ruby-forum.com/u/jjkiesch)\
**Post date:** [June 19, 2006, 6:34pm UTC](https://www.ruby-forum.com/t/pdf-simpletable-help-needed/63817/2 "2006-06-19T18:34:21Z")

</div>

On 6/19/06, Josh K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> def test  
> \_pdf = PDF::Writer.new  
> table = PDF::SimpleTable.new  
> user\_data = []  
> for user in User.find(:all)  
> user\_data \<\< user.attributes  
> end

You need to define your columns and column order here. You’re missing  
something. Your array may be complete, but your _table_ definition  
isn’t.

> ```
> table.data = user_data
> table.render_on(_pdf)
> 
> ```

After you define your columns, the above will work.

## -austin

Austin Z. \* removed\_email\_address@domain.invalid \* [http://www.halostatue.ca/](http://www.halostatue.ca/)  
\* removed\_email\_address@domain.invalid \* [You are in a maze of twisty little passages, all alike. // halo • statue](http://www.halostatue.ca/feed/)  
\* removed\_email\_address@domain.invalid
