# PDF:writer and Simpletable problem

**URL:** <https://www.ruby-forum.com/t/pdf-writer-and-simpletable-problem/120763>\
**Category:** Rails\
**Created:** [November 20, 2007, 1:28pm UTC](https://www.ruby-forum.com/t/pdf-writer-and-simpletable-problem/120763 "2007-11-20T13:28:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sudarshan\_Purohit](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/48db29/32.png) [@Sudarshan\_Purohit](https://www.ruby-forum.com/u/Sudarshan_Purohit)\
**Post date:** [November 20, 2007, 1:28pm UTC](https://www.ruby-forum.com/t/pdf-writer-and-simpletable-problem/120763/1 "2007-11-20T13:28:16Z")

</div>

Hi all,  
I’m facing a problem generating PDF documents using PDF:writer. My  
code generates a couple of dozen documents in a loop. Each contains  
something between 8 to 30 tables. Most of the documents generate just  
fine, but occasionally, say in one of a dozen documents, one of the  
tables gets printed wrongly. The heading of the table is printed with  
one column name per page - so if my table has 5 columns, there’ll be 5  
pages, each with just one column name printed at the top, no data. On  
the next page after these, the table will be printed correctly, with  
proper header and everything.  
Typically this happens to a table that’s going to be rolled over  
to the next page, just space for one row at the bottom of the page.  
However, many other tables in the same situation do get printed  
correctly, so that can’t be the only reason.  
I’m using an older Rails, 1.1.6, but PDF:Writer is 1.1.3. The code  
that’s generating the table is :

* * *

```
  answertab = PDF::SimpleTable.new
  answertab.width = 500
  answertab.protect_rows = 1
  answertab.split_rows = true
  answertab.shade_rows = :striped
  answertab.shade_color = Color::RGB::Grey90
  answertab.shade_color2 = Color::RGB::Grey90
  answertab.show_headings = true
  answertab.font_size = 12
  answertab.minimum_space = 40
  answertab.show_lines = :all

  line = {}
  ff_all = answer.form_fields.find(:all, :order=>"position")
  ff_titles = ["Number"].concat(ff_all.collect{|f| 

```

f.label.capitalize})  
answertab.column\_order = ff\_titles  
ff.each do |field\_id|  
field = FormField.find(field\_id)  
begin  
line[field.label.capitalize] =  
answer.responses.find(:first,  
:conditions=\>[“form\_field\_id=?”,field\_id]).response  
rescue NoMethodError  
line[field.label.capitalize] = " "  
end  
end  
line[“Number”] = mynumber  
answertab.data \<\< line  
end

```
  binder.text "\n"
  answertab.columns["Number"] =

```

PDF::SimpleTable::Column.new(“Number”) { |col|  
col.width = 60  
col.heading = “Neighbor”  
col.justification = :left  
}  
if answertab.data.size \> 0  
answertab.render\_on(binder)  
end

* * *

```
  The above code is repeated several times in each document, for

```

each ‘answertab’.

```
  Has anyone else seen/solved this problem? Several people have

```

mentioned that a patch to the Transaction package fixed their own  
problems. I have Transaction-simple-1.4.0 installed. I searched but  
did not find any patches that seemed relevant.

Thanks in advance!

Regards,  
Sudarshan

---

<div class="post-metadata">

**Author:** ![Sudarshan\_Purohit](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/48db29/32.png) [@Sudarshan\_Purohit](https://www.ruby-forum.com/u/Sudarshan_Purohit)\
**Post date:** [November 21, 2007, 1:52pm UTC](https://www.ruby-forum.com/t/pdf-writer-and-simpletable-problem/120763/2 "2007-11-21T13:52:31Z")

</div>

Hi,  
So it turns out this is a known issue with PDF:writer (  
[http://stonecode.svnrepository.com/ruby\_pdf/trac.cgi/ticket/7](http://stonecode.svnrepository.com/ruby_pdf/trac.cgi/ticket/7) ), which  
I didn’t find before posting. Apologies. In any case, I wrote a  
workaround that’s fixing the problem for me. Might save a few minutes  
for the next one like me, so here it is :

* * *

```
  if answertab.data.size > 0
    binder.start_new_page if binder.y - binder.bottom_margin < 80

```

# Make sure we don’t try to start a table dangerously close to the end

of the page.  
answertab.render\_on(binder)  
end

* * *

Regards,  
Sudarshan

On Nov 20, 5:27 pm, “Sudarshan Purohit” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
