We try to generate invoices with the PrinceXML library. An invoice consist of a header with invoice details, a table with the invoice specification and a footer with payment details. Users can provide input for this footer, so the length of the content varies.
We want to position the footer always on the bottom of the last page. This can easily be done with the flow attributes:
In this code example we assume each footer takes 150px of space, but due to the dynamic content in the footer this might not always be true. To position the footer in the right way on the invoice with paged media we should solve two problems:
To overcome these problems we found another solution, namely by placing the footer on an absolute bottom position. We only want to put the footer on the last page, so this is not a problem.
This positions the footer in the right position on the last page and considers the height of the text to be displayed. The only problem is an overlap between the footer and the content of the page. If the table with invoice details reaches to the bottom of the page and/or the footer is high, the text starts to overlap.
What is the best way to place a footer in a PDF with dynamic content and a varying height?
We want to position the footer always on the bottom of the last page. This can easily be done with the flow attributes:
<div id="footer">Some content, which can be short but also very long....</div>
@page {
margin-bottom: 150px;
@bottom-center {
content: flow(footer);
}
}
#footer {
flow: static(footer);
}
In this code example we assume each footer takes 150px of space, but due to the dynamic content in the footer this might not always be true. To position the footer in the right way on the invoice with paged media we should solve two problems:
- Find a way to calculate the height of the footer
- Find a way to address the last page of the PDF and only apply the margin-bottom. Otherwise each page gets an extra margin on the bottom for a footer that only exists on the last page. The page:last {} selector seems to be non-existant.
To overcome these problems we found another solution, namely by placing the footer on an absolute bottom position. We only want to put the footer on the last page, so this is not a problem.
#footer {
position: absolute;
bottom: 0px;
}
This positions the footer in the right position on the last page and considers the height of the text to be displayed. The only problem is an overlap between the footer and the content of the page. If the table with invoice details reaches to the bottom of the page and/or the footer is high, the text starts to overlap.
What is the best way to place a footer in a PDF with dynamic content and a varying height?