Goal
I need to increase the quality of the bitmap that is being added to a pdf. I have a 300dpi image, but looks really bad when itextsharp adds it to pdf.
Description
I am working on a project which takes a bitmap and writes it to a pdf using itextSharp. The problem is that the project makes a graph, saves it as a bitmap, writes it to the pdf, and the graph appears to be low quality. I am unable to attach the picture here of what is being graphed, but will do my best to describe what is going on. Here is the code below:
//Declare chart object
private static System.Windows.Forms.DataVisualization.Charting.Chart chart_runs;
//Start the PDF Document
Document pdfDocument = new Document(PageSize.LETTER);
private static System.Drawing.Bitmap GetChartBitmap()
{
chart_runs.Width = 2269;
chart_runs.Height = 1406;
System.Drawing.Bitmap bitmap1 = new System.Drawing.Bitmap(2269, 1406);
bitmap1.SetResolution(300, 300);
chart_runs.DrawToBitmap(bitmap1, new System.Drawing.Rectangle(0, 0, 2269, 1406));
string path = System.IO.Path.GetTempPath();
bitmap1.Save(path + @"\Image.png");
return bitmap1;
}
Here is how the bitmap and image is added to the pdf.
System.Drawing.Bitmap img = GetChartBitmap();
img.Dispose();
string path = System.IO.Path.GetTempPath();
iTextSharp.text.Image imag
= iTextSharp.text.Image.GetInstance(path + @"\Image.bmp");
//imag.ScaleAbsolute(chart_runs.Width, chart_runs.Height);
//imag.ScaleToFit(550, 330);
imag.ScaleAbsolute(550, 350);
//imag.ScaleAbsolute(650, 450);
//imag.ScaleAbsolute(100f, 100f);
pdfDocument.Add(imag);
pdfDocument.Close();
pdfDocument.Dispose();
Attempts
I have spent considerable time trying to fix this, here are some of the highlights.
- At first, it was believed this was a DPI issue. However, when I made the bitmap (and itext image) 300DPI, no quality difference was noticed.
- I then added more pixels by enlarging the targetBounds object above. This had the weird effect of shrinking my graph on my PDF? Why?
- I have attempted many manipulations with itext.scale functions as I found here.
- Another justification why I am trying to make my bitmap larger is on here.
As I said above, I seem to be making my image even smaller with the current approach. I am just trying to increase the quality of the bitmap so when people print it off or zoom in on the pdf it doesn't look terrible. I appreciate any help.