Hi,
We have looked into the sample project you sent to us. There is no quality loss in the image. The reason that you see it not as clear as on the screen is because Adobe Reader scaled it. For example, if the original image is 100 pixels by 100 pixels, Adobe Reader might display it as 120 pixels by 120 pixels when you view the PDF file depending on your zoom level in the Adobe Reader.
Most of the time Adobe Reader produces very good result when it scales contents ---- this is especially true for text. As you can see your text in the PDF file actually look much smoother than what you see in a browser window. For most bitmap images, such as a scenic view, Adobe Reader can scale it without any noticeable quality loss. However for simple bitmaps with shapes, lines and text, you will notice artifacts when it is scaled. Unfortunately Adobe Reader does not have a true "100%" mode (you will notice the image size is still different than what you see in a browser even if you set Adobe Reader's zoom level to 100%). As a result, the chart image will almost always be scaled thus produces a noticeable fuzzy result.
There are two ways to resolve this issue:
1. Use a higher resolution on your chart image. Most chart control allows you to set the chart image resolution --- unfortunately this is not the case for ASP.NET Chart controls. For ASP.NET Chart control, you must first save the image into a separate image with something like this:
Code: C#
//Create a new bitmap that is the same size as the chart control
Bitmap bmp = new Bitmap(584, 338);
//Set the bitmap resolution. Here we use 120, which is higher than
//the standard resolution (standard is 96 DPI)
bmp.SetResolution(120, 120);
//Paint the Chart into the bitmap and save it
using (Graphics g = bmp.FromImage(bmp))
{
Chart1.Paint(g, new Rectangle(0, 0, bmp.Width, bmp.Height));
}
bmp.Save(MapPath("~/test.bmp"));
Now you can reference the image in your page directly through an asp:Image control:
Code: HTML/ASPX
<asp:Image runat="server" id="ChartImg" NavigateUrl="~/test.bmp">
This image has a higher resolution and when it is converted into PDF you will notice that it has better quality.
Note that when you use this approach you will probably need to:
1. Use dynamically generated file names for each request and have some code to clean up these images files on your server;
2. Use a query string argument to distinguish regular browser request and the HTML to PDF converter request so that you only use this high resolution image logic when the request comes from HTML to PDF converter;
The above code saves the image as bmp files, which are bigger than jpeg. This is
not a concern. The HTML to PDF converter will convert bmp as jpeg automatically (and apply JpegQualityLevel during the conversion). So the final PDF file size will not be affected (it will still be slightly bigger than before since now you have a higher resolution image).
2. Alternatively, you can use a different chart control that output chart in vector format such as svg instead of as bitmap format. Vector format chart can produce stunning result because it can be scaled up/down infinitely;
Hope this helps to meet your customers' requirement. Please let us know if it works for you.
Thanks!