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 overflowing without needing to? #10

Open
floydj opened this issue Aug 11, 2014 · 4 comments
Open

Table overflowing without needing to? #10

floydj opened this issue Aug 11, 2014 · 4 comments
Assignees
Labels

Comments

@floydj
Copy link
Contributor

floydj commented Aug 11, 2014

I have a table with another table inside of it as shown in the picture below. My problem is that the red-bordered table won't fit in the blue table, and is thus overflowing to the following page. If I remove a colspan from the first row in the red-bordered table, it stops overflowing. How can I make the blue-bordered table stop overflowing and still use a colspan in the red-bordered table?

image

require "prawn/table"

class TestPdf < Prawn::Document
  def initialize
    super(margin: [ 30, 71, 55, 71 ])
    render_propaganda
  end

  def render_propaganda
    prop_table
  end

  def prop_table
    table  [[
      { content: "Placeholder text", width: 200 },
      { content: propaganda }
    ]], cell_style: { border_width: 1, border_color: '0000FF' } do
    end
  end

  def propaganda
    make_table(prop_rows, cell_style: { border_width: 1,
                                        border_color: 'FF0000',
                                        overflow: :expand}) do
     end
  end

  def prop_rows
    desc = "one\ntwo\nthree\nfour"
    desc.split("\n").map do |line|
      if line == get_line(desc)
        #[ { content: "#{line}", colspan: 2, size: 11, font_style: :bold}  ]
        [ { content: "#{line}", size: 11, font_style: :bold}  ] #taking out colspan fixes 
      else
        [ { content: "\u2022", padding_left: 10, font_style: :bold}, { content: "#{line}", size: 10, padding_left: 0 } ]
      end
    end
  end

  def get_line(desc, num = 0)
    lines = desc.split("\n")
    if lines.count < 2
      result = desc
    else
      result = lines[num]
    end
    result
  end

end
@hbrandl
Copy link
Contributor

hbrandl commented Aug 18, 2014

Thanks for reporting the bug and including code to reproduce it @floydj. Would it be possible for you to include a failing test case too?

@floydj
Copy link
Contributor Author

floydj commented Aug 18, 2014

Done

hbrandl added a commit that referenced this issue Aug 19, 2014
add failing spec for subtable with colspan > 1; issue #10
@hbrandl
Copy link
Contributor

hbrandl commented Aug 19, 2014

Thank you! I'll take a close look at the issue soon.

@hbrandl hbrandl self-assigned this Aug 20, 2014
@hbrandl hbrandl added the bug label Sep 1, 2014
@hbrandl hbrandl added this to the 0.1.2 milestone Sep 1, 2014
@practicingruby practicingruby removed this from the 0.1.2 milestone Nov 3, 2014
@lucas-nelson
Copy link

I hope I am helping and not being a bother, but I think I hit this bug in my work. If so, I have a simpler block that reproduces it:

Prawn::Document.generate('colspan-nested-bug.pdf') do
  table([[make_table([[{ content: 'r1c1-2', colspan: 2 }],
                      [make_table([['r2c1/r1c1'], ['r2c1/r2c1']]),
                       'r2c2']])]])
end

Change the r1c1-2 colspan to 1 and there's no bug. Remove the ['r2c1/r2c1'] row and there's no bug.

I don't want to mess with the spec that floydj created, but thought some extra info might help someday.

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

4 participants