Hi,
So it turns out this is a known issue with PDF:writer (
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"
<sudarshan.puro...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> 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
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---