Thymeleaf and Flying Saucer - Date in Footer Not Showing on Last Page

55 Views Asked by At

I'm using Thymeleaf along with Flying Saucer to generate a PDF document. In my PDF, I have a footer that includes a dynamic date. I want this date to be displayed only on the last page.

I have tried placing the date inside a <div> with a specific ID and using JavaScript to check if it's the last page, updating the content dynamically.

However, the date is not appearing on the last page as expected. Right now it is showing on every page, and it should be on the last page only.

Here's my Thymeleaf/HTML code for the footer:

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8"/>
    <title>Footer</title>
</head>

<body>
<div id="footer" th:fragment="footer">
    <p class="last-page-date">Date: <span th:text="${#dates.format(#dates.createNow(), 'dd/MM/yyyy')}"></span></p>
    <hr/>
    <table class="footer-info">
        <tr>
            <td class="footer-description">
                Powered By: FlexEHR Healthcare Private Limited.
            </td>
            <td class="footer-pagination">
                Page <span id="page-number"></span> out of <span id="page-count"></span>
            </td>
        </tr>
    </table>
</div>
</body>
</html>

Here's my CSS for the Footer:

#footer {
    position: fixed;
    width: 100%;
    bottom: 0;
    left: 0;
}
#footer .footer-info {
    width: 100%;
    font-size: 0.36cm;
}

#footer .footer-description {
    text-align: left;
}

#footer .footer-pagination {
    text-align: right;
}

#page-number::after {
    counter-increment: page;
    counter-reset: page 1;
    content: counter(page);
}

#page-count::after {
    content: counter(pages);
}

How do I ensure that the date appears only on the last page of the generated PDF?

0

There are 0 best solutions below