I am pretty new in iText nd iTextSharp (the C# version of iText) and I have the following problem.
I am inserting some jpg charts inside my PDF. These charts are rapresented by some jpg like this one:
I insert it into a table of my PDF in this way:
iTextSharp.text.Image img = null;
..........................................
..........................................
..........................................
if (currentVuln.UrgencyRating > 0)
{
img = ChartHelper.GetPdfChartV2((int)currentVuln.UrgencyRating * 10, _folderImages);
vulnerabilityDetailsTable.AddCell(new PdfPCell(img) { Border = PdfPCell.RIGHT_BORDER, BorderColor = new BaseColor(79, 129, 189), BorderWidth = 1, Padding = 5, MinimumHeight = 30, PaddingTop = 10 });
}
And this is a section of the GetPdfChartV2() method in which I load a chart immage:
public static iTextSharp.text.Image GetPdfChartV2(int percentage, string _folderImmages)
{
iTextSharp.text.Image chart = null;
string folderImmages = _folderImmages;
if (percentage == 0)
{
return null;
}
else if (percentage == 10)
{
chart = iTextSharp.text.Image.GetInstance(_folderImmages + "1.jpg");
}
else if (percentage == 20)
{
chart = iTextSharp.text.Image.GetInstance(_folderImmages + "2.jpg");
}
....................................................
....................................................
....................................................
else if (percentage == 100)
{
chart = iTextSharp.text.Image.GetInstance(_folderImmages + "10.jpg");
}
return chart;
}
}
The problem is that the chart immage is too big for my PDF and I obtain this orrible result:
So I have the following 2 questions:
1) Can I resize the iTextSharp.text.Image size into my code or have I to do it with an image editor? If is it possible where have I to do it? when I load the immage into GetPdfChartV2() by the lines as:
chart = iTextSharp.text.Image.GetInstance(_folderImmages + "1.jpg");
or when I put the immage into my PDF table cell:
vulnerabilityDetailsTable.AddCell(new PdfPCell(img) { Border = PdfPCell.RIGHT_BORDER, BorderColor = new BaseColor(79, 129, 189), BorderWidth = 1, Padding = 5, MinimumHeight = 30, PaddingTop = 10 });
Can you help me to solve this issue?
2) Why when I see the previous chart immage on my Windows Photo Viewer (100% of the size) I see it much smaller or here in the StackOverflow page?