Kozea / WeasyPrint

The awesome document factory
https://weasyprint.org
BSD 3-Clause "New" or "Revised" License
7.14k stars 681 forks source link

Footer only on the bottom of last page #1033

Closed ghost closed 3 years ago

ghost commented 4 years ago

Is there a way to put an HTML footer so that it only appears on the last page, yet sticks to the bottom of the last page (without overlapping the page body)? The <footer>/position:fixed method puts it on all pages.

liZe commented 4 years ago

The easy part of your problem is to put the footer at the bottom of one page: you can use running elements that are supported since version 51.

The hard part is to target the last page. There’s a page selector for the first page, but not for the last one. You can use named pages as explained in this Stack Overflow question, but it may not be enough for your case.

MindFluid commented 4 years ago

Your options are also very dependent on how your HTML is being generated. The best option might be to use a div and only call it at the very end of your document, so that it falls into the flow of the document and you can position it from there.

outring commented 3 years ago

If you have a dynamic footer height you can go with the solution from here: https://github.com/Kozea/WeasyPrint/issues/1243#issuecomment-759661116 If the height is known beforehand you can simplify it by just having an empty placeholder with this height set instead of the first fake footer copy from the example above

ghost commented 3 years ago

I think we can close this now. Thanks for the answers, but we have switched to another solution.

nileshpal23 commented 3 years ago

@yujiri8 can you please let me know if you found the solution?

ghost commented 3 years ago

Sorry, by "another solution" I meant that we switched to another way of rendering PDFs (headless Chromium). We never achieved exactly what we wanted.

nileshpal23 commented 3 years ago

@yujiri8 can you share an example?

aqeelat commented 2 years ago

We found princexml to be helpful in this situation, but due to its hefty price, we're trying to solve this issue using weasyprint.

outring commented 2 years ago

Here's the solution which 100% works: https://github.com/Kozea/WeasyPrint/issues/1243#issuecomment-759661116 As I said in my last comment if you know your footer height beforehand you can simplify it by just setting the placeholder height explicitly instead of rendering footer content into it

RoeiMeiri9 commented 8 months ago

Although this issue is closed, this might help someone in the future: Try adding the footer as the last dom element on the HTML inside the body, it might just work.

For those who face the opposite problem, it is recommended to put the footer first in the HTML so that it will appear on every page (that appears to be the solution in my case)