iText pdf library
Website search

How to prevent images from resizing in a table cell?

I would like to create a table that has a list of dots. I don't know ahead of time how many dots I have, but if they overflow the cell, I want them to wrap, just like text would. My code is something like this:

PdfPTable table = new PdfPTable(1);
table.setTotalWidth(new float[]{80});
Phrase listOfDots = new Phrase();
for (int i = 0; i  40; i++) {
  listOfDots.add(new Chunk(pdf.correct, 0, 0));
  listOfDots.add(new Chunk(" "));
The dots wrap, like I expect, but they don't all have the same size. There are 7 rows of 5 dots each, and all 35 dots have the same size. The last row of 5 dots are roughly half the size of the others. Is there a way to make all the images the same size?

Posted on StackOverflow on Aug 20, 2015 by D. Cooper

Please take a look at the ImagesInChunkInCell example. Instead of a bullet, I took the image of a light bulb.

Images in cell
Images in cell

I was able to reproduce the problem you described, but as you can see in list_with_images.pdf, I added one extra line to prevent the undesired behavior:

Image image = Image.getInstance(IMG);
PdfPTable table = new PdfPTable(1);
table.setTotalWidth(new float[]{120});
Phrase listOfDots = new Phrase();
for (int i = 0; i 

The extra line is:


This prevents that the image is scaled.

Ready to use iText?

Try our iText 7 Library and add-ons FREE for 30 days. Test your proof of concept, and see if our solution is right for you.

Get my FREE trial

Still have questions? 

We're happy to answer your questions. Reach out to us and we'll get back to you shortly.

Contact us
Stay updated

Join 11,000+ subscribers and become an iText PDF expert by staying up to date with our new products, updates, tips, technical solutions and happenings.

Subscribe Now