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

Table header breaks up on multipage pdfs #8

Closed
Bharat311 opened this issue Jul 25, 2014 · 8 comments
Closed

Table header breaks up on multipage pdfs #8

Bharat311 opened this issue Jul 25, 2014 · 8 comments
Labels

Comments

@Bharat311
Copy link
Contributor

Hi, I was using an earlier version of the prawn gem and used it to render the following pdf:

issue4_fix

But recently, when i upgraded to the latest master of prawn and prawn-tables for a fix of another issue, the following issue cropped up in the existing pdfs (which was not seen earlier).

Using the option { header: true }, the header was not properly rendered for the subsequent pages, here's a preview of the same pdf now (using the same code base):

issue4

Upon investigating, i found the below commit to be the reason for this broken behaviour:
prawnpdf/prawn@ed3d144

I am not completely sure as to how it works but it maybe due to using rowspans in the header. Any help in this regard would be greatly appreciated.

Thanks.

@hbrandl
Copy link
Contributor

hbrandl commented Jul 25, 2014

@Bharat311 Can you provide the code that causes this unexpected behaviour? Maybe even a failing test case?

@johnnyshields
Copy link
Contributor

I work with @Bharat311. Here's code that reproduces the issue (see pages 2+):

        rows = []
        rows << [{content: '', borders: []}] * 6
        rows << [{content: 'foo', colspan: 6, height: 20, borders: []}]
        rows << [{content: 'bar', colspan: 2}] * 3
        100.times { rows << [{content: 'baz'}] * 6 }

        pdf.table(rows,
                  width: pdf.bounds.width,
                  header: 3, cell_style: {padding: 1}) do |table|
          table.row(1).columns(0...-1).borders = [:bottom]
        end

In particular it's the line table.row(1).columns(0...-1).borders = [:bottom] which seems to cause it.

@hbrandl
Copy link
Contributor

hbrandl commented Jul 25, 2014

@johnnyshields Thank you very much. I'll try to find some time next week to look into this issue. If you can provide a failing test case it will greatly speed up my work.

@johnnyshields
Copy link
Contributor

I'm not really sure how to test this, but we can try to give it a look in the next week.

@Bharat311
Copy link
Contributor Author

@hbrandl, i tried for several hours but couldn't add a failing test case for it. However, here's the minimal code that can be used to reproduce the issue:

pdf = Prawn::Document.new

rows = []
rows << [{content: "Header1", colspan: 6}]
rows << [{content: "Header2 (i)", colspan: 3}, {content: "Header2 (ii)", colspan: 3}]

50.times { rows << ["text"] * 6 }

pdf.table(rows, header: 2, cell_style: { borders: []}) do |table|
  table.rows(1).columns(0...-1).style(background_color: '888888')
  table.rows(1).columns(0...-1).borders = [:bottom]
end

The issue is because of the incorrect calculation of the header height for the 2nd page, i think this maybe due to multiple colspan rows in the header.

The above was working fine before and has been introduced in this commit:
prawnpdf/prawn@ed3d144

Currently, we are using the latest prawn-tables master without the above commit and it is working fine.

@hbrandl
Copy link
Contributor

hbrandl commented Aug 18, 2014

@Bharat311 @johnnyshields can you confirm that this fixes your issue?

@hbrandl hbrandl added the bug label Aug 18, 2014
@Bharat311
Copy link
Contributor Author

@hbrandl, Thanks, this fixes our issue.

@johnnyshields
Copy link
Contributor

@hbrandl looks good to me, thank you!

hbrandl added a commit that referenced this issue Aug 19, 2014
Fixed multi line table headers that involve cells that span multiple columns (fixes #8)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants