How to resize an Image to fit it into a PdfPCell?

These charts look like this:

Color charts


vulnerabilityDetailsTable.AddCell(new PdfPCell(img) {
    Border = PdfPCell.RIGHT_BORDER,
    BorderColor = new BaseColor(79, 129, 189),
    BorderWidth = 1,
    Padding = 5, MinimumHeight = 30, PaddingTop = 10 });
The problem is that the chart image is too big for the cell and I obtain this horrible result:

Resulting PDF

So I have the following 2 questions:

  1. Can I resize the Image size into my code or do I have to do this with an image editor? If it's possible, where do have I to do this? Right after I load the image or when I put the image into my PDF table cell?
  2. When I look at the image using my Windows Photo Viewer at 100% of the size, I see it much smaller than in the PDF. Why is this?

Posted on StackOverflow on Mar 12, 2014 by Andrea Nobili

As documented, this option doesn't scale the image (which is what you want). If you want to scale the image, you could use this:

Cell cell = new Cell();

By adding the boolean parameter true, you ask iText to scale the image. My code is written in Java, but it won't take much time to port it to C#. Just replace the lower case with the upper while using methods.

Another option is to use addCell() like this:


This will also scale the image, but use the properties of the default cell. If you don't change these properties, there will be a padding of 2 user units.

You can also change the width percentage of the image, for instance:


This line will make sure that the width of the image is 50% of the available width of the cell.

Color charts

Color charts

Click this link if you want to see how to answer this question in iText 5.

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