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

Second and subsequent table pages clipping with header #112

Closed
8vius opened this issue Feb 21, 2019 · 2 comments
Closed

Second and subsequent table pages clipping with header #112

8vius opened this issue Feb 21, 2019 · 2 comments

Comments

@8vius
Copy link

8vius commented Feb 21, 2019

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
Copy link
Member

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

@pointlessone
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants