I am trying to generate a PDF from HTML using Flying Saucer's OpenPDF Library.
The PDF has a header which includes user-provided data. Since the user--provided data may vary in length, I would like a solution that moves the main content down on the page if the header is larger than usual.
However, the header is actually so big typically that on subsequent pages, we want to show a reduced header with fewer fields displayed.
I have been able to solve each of these problems separately, but not at the same time.
If I put the header into a table header and apply the -fs-table-paginate: paginate style via CSS, then the header pushes down all of the other content, but I can't see any way to render differently on subsequent pages.
If I make the header a running element, I can set one header as a running element using @page :first , and a different header on the regular @page. However, this puts the header in the page margins, and the text will overlap the body if the header is larger than expected.
I investigated using th:first-child but that affects all pages (which makes sense).
The only thing I can think of is to render the header, calculate the height, and then render the whole document with the margin for the header set to the actual height, but I'd prefer a simpler solution.
I should note that the body of the report also has user-provided content, so I can't just put an explicit page break at the right spot and start a new table.
Does anyone have any ideas or suggestions for solving both of these problems at once?