Legacy notice!

iText 5 is the previous major version of iText's leading PDF SDK. iText 5 has been EOL, and is no longer developed. Switch your project to iText 7, integrating the latest developments.
Check related iText 7 content!

Here's my scenario: I create a PdfPTable with 6 columns. However, when I add only 1 or 2 cells to the table, it's not rendering those cells. It only renders the cells if I add 6 or a multiple of 6 cells.

I know that makes total sense but in my case, I am adding image cells based on an imagelist that may not contain 6 or 12 or 18 images. The number of images can be 1 or 7 or anything. Below is my Q> snippet:

try {
    Document document = new Document(PageSize.A4.rotate());
    PdfWriter writer = PdfWriter.getInstance(document,
        new FileOutputStream(new File(sourcePath, AppText.FILE_NAME)));
    PdfPTable table = new PdfPTable(6);
    Paragraph paragraph = new Paragraph("Diary Report");
    for (String imageFile : imageFiles) {
        Image image = Image.getInstance(new File(imageFile).getAbsolutePath());
        PdfPCell cell = new PdfPCell(image, true);
    return "successful";
} catch (DocumentException | IOException e) {
Any help would be so great.

Posted on StackOverflow on Nov 20, 2015 by prashantwosti

iText ignores every row that isn't complete. When you define a table with 6 columns and you only add 1 (or 2 or 3 or 4 or 5) cell(s), then the row isn't rendered.

If you want to avoid this behavior, you have to complete the row. This can be done using a single line:


Now iText will add empty cells to complete the row.