Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Row spans in multi-row table header are lost after page break #721

Closed
dmeranda opened this issue May 12, 2014 · 6 comments
Closed

Row spans in multi-row table header are lost after page break #721

dmeranda opened this issue May 12, 2014 · 6 comments
Assignees

Comments

@dmeranda
Copy link

If you render a table that has a header of more than one row, say :header=>2, any rowspans within that header will not be preserved when re-drawing that header on the second and following pages. It is as if the :rowspan property gets reset to 1.

Also, it might be nice to automatically infer the number of header rows when :header is passed as true, based on any rowspans.

Consider this simple example with a two-row header which does not render the second page correctly (with Prawn 1.0.0):

require 'prawn'

pdf = Prawn::Document.generate("sample.pdf") do |pdf|
  rows = [ [{:content=>"The\nNumber", :rowspan=>2}, {:content=>"Prefixed", :colspan=>2} ],
           ["A's", "B's"] ]

  (1..50).each do |n|
    rows.push( ["#{n}", "A#{n}", "B#{n}"] )
  end

  pdf.table( rows, :header=>2 ) do
    row(0..1).style :background_color=>"FFFFCC"
  end
end
@practicingruby
Copy link
Member

@hbrandl: Please investigate

@hbrandl hbrandl self-assigned this May 13, 2014
@hbrandl
Copy link
Contributor

hbrandl commented May 13, 2014

Assigned to myself. I'll look into this issue.
I'll be a lot faster if anyone can provide a failing test case for it.

@dmeranda
Copy link
Author

The initial bug report contains the complete source to a simple failing test case.

@hbrandl
Copy link
Contributor

hbrandl commented May 13, 2014

I was thinking of an rspec test but nevermind, I found the time to create one.

  describe "headers should allow for rowspan" do 
    it "should remember rowspans accross multiple pages", :unresolved, :issue => 721 do 
      pdf = Prawn::Document.new({:page_size => "A4", :page_layout => :portrait})
      rows = [ [{:content=>"The\nNumber", :rowspan=>2}, {:content=>"Prefixed", :colspan=>2} ],
           ["A's", "B's"] ]

      (1..50).each do |n|
        rows.push( ["#{n}", "A#{n}", "B#{n}"] )
      end

      pdf.table( rows, :header=>2 ) do
         row(0..1).style :background_color=>"FFFFCC"
      end

      #ensure that the header on page 1 is identical to the header on page 0
      output = PDF::Inspector::Page.analyze(pdf.render)
      output.pages[0][:strings][0..4].should == output.pages[1][:strings][0..4]
    end
  end

I'll keep you posted.

@hbrandl
Copy link
Contributor

hbrandl commented May 14, 2014

Fixed in branch issue_721. @dmeranda can you confirm this?

@sandal Once @dmeranda has confirmed the fix, pull request #723 should be ready to merge.

@dmeranda
Copy link
Author

@hbrandl Yes, I've verified this patch works in the real application where I had detected this bug, and which is more complicated than the very simple test case I made for this bug report.

The Prawn manual should probably be updated to note that the :header option to the table can be a number-of-rows, and not just true or false.

Also, how easy would it be to automatically determine the number of header rows, based on any rowspans within it, if :header is passed as true rather than a specific number?

practicingruby added a commit that referenced this issue May 28, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants