There are different strategies for adding an Image
to a PdfPCell
. These strategies are explained in chapter 4 of my book, and the XMen example demonstrates all possible options. If you don't understand Java, you'll find the C# port of the examples of chapter 4 here.
You are using this:
// we wrap he image in a PdfPCell
PdfPCell cell = new PdfPCell(img[0]);
table.AddCell(cell);
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:
// we wrap the image in a PdfPCell and let iText scale it
cell = new PdfPCell(img[1], true);
table.AddCell(cell);
By adding the boolean parameter true
, you ask iText to scale the image.
Another option is to use addCell()
like this:
// we add the image with addCell()
table.AddCell(img[2]);
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 also have the option to use composite mode:
cell = new PdfPCell();
cell.AddElement(img[3]);
table.AddCell(cell);
This will make sure the image is scaled to fill 100 percent of the cell width, unless you change the width percentage of the image, for instance:
img[3].WidthPercentage = 50;
This line will make sure that the width of the image is 50% of the available width of the cell.
Finally, you can scale the image before adding it to the cell as explained in your own (incomplete) answer.
Out of 5 possible options, you picked the single option that doesn't scale the image ;-)