Creating a table with two rows in a pdf footer using itext
source to share
You could have saved yourself a sleepless night by reading the documentation. You would find that you can set the background of a cell using the method setBackgroundColor()
and that you can add the table at an absolute position using the method writeSelectedRows()
.
Take a look at TableFooter example:
PdfPTable table = new PdfPTable(1);
table.setTotalWidth(523);
PdfPCell cell = new PdfPCell(new Phrase("This is a test document"));
cell.setBackgroundColor(BaseColor.ORANGE);
table.addCell(cell);
cell = new PdfPCell(new Phrase("This is a copyright notice"));
cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
table.addCell(cell);
If you have multiple cells in a row, you need to set a background for all cells. Note that I am determining the total table width (523 is the page width minus the margins). The total width is needed because we will add the table with writeSelectedRows()
:
footer.writeSelectedRows(0, -1, 36, 64, writer.getDirectContent());
The resulting PDF looks like this . Make sure you define your page margins so that the footer column does not overlap with the page content.
source to share