prawnpdf / prawn-table

Provides support for tables in Prawn
Other
205 stars 101 forks source link

Second and subsequent table pages clipping with header #112

Closed 8vius closed 5 years ago

8vius commented 5 years ago

I have some header elements set in the upper corners of my PDFs, a logo and some text, on the first page they look fine since I manually move down to start rendering the table:

screen shot 2019-02-21 at 3 03 28 pm

But on every other page the top of the table is clipping with these elements:

screen shot 2019-02-21 at 3 03 24 pm

This is how I'm rendering the logo and header text:

pdf.repeat :all do
  pdf.image(
    open(logo.url),
    fit: [160, 40],
    at: [pdf.bounds.right - (logo.metadata['width'] + 10), pdf.bounds.top + 10],
  )
end

pdf.draw_text(
  header_text,
  at: pdf.bounds.top_left,
  size: 8
)

And this is how I'm rendering out the table:

pdf.table(
  data,
  header: true,
  cell_style: { overflow: :shrink_to_fit, size: 6 },
  column_widths: column_widths
)
gettalong commented 5 years ago

You could try setting the top margin so that it excludes your header area.

pointlessone commented 5 years ago

This is expected behaviour even if it might seem surprising.

Prawn doesn't really have any layout tools. It' very close to the PDF drawing model. Objects do not push other objects (like they do in HTML, for example). They rather get put wherever the current position is happen to be. Many operation advance current position in a somewhat expected manner but that's about the extent of what is provided by Prawn.

This is even more evident with repeaters. Repeaters are getting applied after everything else. Think of them as being a completely separate pass through all the pages. After your document is finished, Prawn goes through each page and paints over whatever is in the repeaters. So if you want to avoid overlap you have to make sure there's enough blank space for them. One way, as Thomas suggested, would be to add margins. Alternatively, you can specify ac block that would be called right after creating a page with on_page_create method or on_page_create_callback option to document constructor.


I'll close this issue now as it's not a bug. Feel free to reopen if you believe it wasn't resolved.