Creating a table with two rows in a pdf footer using itext

Hi I want to add a footer with two lines. 1st line will have document name with background color. The second line will have copyright notes. I tried to create using ColumnText. but i cant set the background color for the line (only the text gets the background color). Are there any measures to achieve this. I spend all night trying to find a solution, but I can't.
0


source to share


1 answer


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.

+1


source







All Articles