Search code examples
javaimageitextcellcaption

Itextpdf adding a caption under an image


Is it possible in the same cell to add an image and it's caption ?

I've tried with a paragraph but with no luck.

            Image img = null;
            try {
                img = Image.getInstance(Base64.decode(val));
            } catch (Exception e) {
                throw new Exception("Problem in decoding image");
            }

            Paragraph paragraph = new Paragraph("this is a Caption");
            valueCell.setImage(img);
            valueCell.addElement(paragraph);

Create a subtable with two cell, one with the image and the other one with the caption I think Is gonna mess with some logic used in this table that is composed of key/value pair cells.


Solution

  • I resolved using the addElement method.

     PdfPCell valueCell = new PdfPCell();
     
     Paragraph paragraph = new Paragraph("this is a Caption");
     valueCell.addElement(img);
     valueCell.addElement(paragraph);