I’m creating a pdf in java using iText
Everything seems to we working the way I thought except when I use a loop, the paragraph I’m using seems to hold all data I store in it. to be a little bit more clear this is what I’m trying to do:
PdfPTable table = new PdfPTable();
for(int k=0; k < 3; k++){
Paragraph leftPar = new Paragraph();
leftPar.add(new Paragraph("\n List Object " + k, topicFont));
table_cell = new PdfPCell(leftPar)
table.addCell(table_cell);
}
the output I want for my table is:
List Object 0
-------------
List Object 1
-------------
List Object 2
but the output I’m getting is:
List Object 0
-------------
List Object 0
List Object 1
-------------
List Object 0
List Object 1
List Object 2
-------------
I have to put the info in different cells, so My problem is I would think when I declare the leftpar = new paragraph it would create a new instance of it, but It seems to keep other stuff I added. I even tried leftPar = null; then leftpar = new paragraph and still nothing? any ideas?
Thanks!
The answer was that the Table itself was keeping all other information on it. so I had to use the method flushContent(); at the end of the loop, after adding the table to the document.