Closed ghost closed 3 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.
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.
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
I think we can close this now. Thanks for the answers, but we have switched to another solution.
@yujiri8 can you please let me know if you found the solution?
Sorry, by "another solution" I meant that we switched to another way of rendering PDFs (headless Chromium). We never achieved exactly what we wanted.
@yujiri8 can you share an example?
We found princexml to be helpful in this situation, but due to its hefty price, we're trying to solve this issue using weasyprint.
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
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)
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.