I'm trying to add a table as a footer containing all the copyright text, page number etc. But I can't find any supporting method that'll accept a PdfPTable
For a phrase there is code like:
ColumnText.showTextAligned(writer.getDirectContent(),
Element.ALIGN_CENTER, new Phrase(
String.format("%d", document.getPageNumber())),
(document.getPageSize().getLeft() + document.getPageSize().getRight())/2,
document.getPageSize().getBottom() + 18, 0);
The examples posted by Bruno are a good pointer, here's an example without magic numbers:
This will write the PdfPTable within the document margins at the bottom overlapping any text you have at the bottom. If you wish to write the table in the margin, use:
document.bottom()
instead ofdocument.bottom()+table.getTotalHeight()
.Header/Footer Example
As a relevant note if you're following the example on this link, the "art" box does not appear to be required and the magic numbers 36, 54, 559, 788 correspond to:
The
PdfPTable
class has a methodwriteSelectedRows()
that can be used to add (a selection of columns and) rows at an absolute position.Examples:
ColumnText
object.To implement a custom footer you need to implement the PdfPageEventHelper.