dimon37 dimon37 - 4 years ago 171
Java Question

How do I add image with text inside PdfCell?

I'm trying to add an image followed by text inside PdfCell. So far the best I could achieve was to have the image ABOVE the text. I am, however, want the image to be on the left of the text in the same line. Here's my current code:

PdfCell cell = new PdfCell()
cell.addElement(myImage);
Chunk staffChunk = new Chunk("This is my text");
staffChunk.setFont(font);
Paragraph p = new Paragraph(staffChunk);
cell.addElement(p);


I already did
myImage.setAlignment(Image.LEFT)
. The text is still showing up below the image.

Answer Source

You need to add the image and the text as chunks to a paragrah and then add this paragraph to the cell:

Paragraph p = new Paragraph() { new Chunk(itextImg, 0, 0), "Hello World" };
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download