# Ruport combing tables and writing to PDF

**URL:** <https://www.ruby-forum.com/t/ruport-combing-tables-and-writing-to-pdf/174500>\
**Category:** Ruby\
**Created:** [August 27, 2009, 5:59pm UTC](https://www.ruby-forum.com/t/ruport-combing-tables-and-writing-to-pdf/174500 "2009-08-27T17:59:27Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![marcisco0](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3da27b/32.png) [@marcisco0](https://www.ruby-forum.com/u/marcisco0)\
**Post date:** [August 27, 2009, 5:59pm UTC](https://www.ruby-forum.com/t/ruport-combing-tables-and-writing-to-pdf/174500/1 "2009-08-27T17:59:27Z")

</div>

Hi there,

I’m still learning my way through Ruby and recently I’m really  
struggling with Ruport. I’ve referred to the lulu book, api docs,  
examples and I…just can’t get my head around this…

I want to specifically understand how to:  
how to combine tables,  
how to send more than 1 table to PDF  
how to send a jpeg inbetween each of the tables (assuming mulitple  
tables are sent)

I was successful in adding an image using the  
ChunkyBacon example…but woudld like to understand how to insert an  
image in between tables…

What I’ve tried…  
Using Groupings…using pivot tables (pretty neat)…

Here’s something nasty that I’d have to call my code…

require “ruport”  
table = Testrun.report\_table\_by\_sql(“some embarrasing sql here…”)  
table2 = Testrun.report\_table\_by\_sql(“further embarrasing sql”)

```
sorted_table = table.sort_rows_by("Name", :order => :descending)

```

sorted\_table2 = table2.sort\_rows\_by(“Name”, :order =\> :descending)

```
sorted_table.swap_column("resultMax","name")

```

sorted\_table2.swap\_column(“resultMax”,“name”)

group1 = sorted\_table.to\_group(“build\_number”)  
group2 = sorted\_table2.to\_group(“build\_number”)

grouping = Grouping(group1, :by =\> “build\_number”), Grouping(group2,  
:by =\> “build\_number”)

puts group1  
puts group2

#ok at this point I have two tables but I’ve only figured out how to  
send one to the PDF using save\_as only  
#which comes out badly formatted in terms of padding and spacing…

# 

#I’ve tried using the formatters, and setting up stages but I can  
never get them working…  
#I want to be able to print each group (really the tables) and if  
possible to insert an image inbetween

# each of the groups…

grouping[0].save\_as(“report.pdf”)

I realize I"m asking more than one question I’ve sat ont his for a few  
days…felt even worse after reading  
James’s comments regarding the Ruport book and how straight forward it  
is…I’ve read it through and I’m still confused. I even went to  
freenode…couldnt find anyone on there last night…

Can someone point me in the right direction?

Thanks.  
Isley
