We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Real poor image quality after conversion from PDF

We are converting PDF file to png image file, generally the image is in good quality, however somehow we just could not get a good quality image from one PDF file. Here is test program:


namespace AsposeTester
{
class Program
{
static void Main(string[] args)
{
string pdfFileName = @"\10.1.1.25.6812.pdf";
int resolution = 94
int quality = 70;
using (var pdfStream = new FileStream(pdfFileName, FileMode.Open, FileAccess.Read))
{
Document pdfDocument = new Document(pdfStream);
for (int pageCount = 1; pageCount <= 4 && pageCount <= pdfDocument.Pages.Count; pageCount++)
{
Stream imageStream = new FileStream(pdfFileName + “.” + pageCount + “.png”, FileMode.CreateNew, FileAccess.Write);
JpegDevice jpegDevice = new JpegDevice((int)(pdfDocument.Pages[1].MediaBox.Width + pdfDocument.Pages[1].PageInfo.Margin.Left + pdfDocument.Pages[1].PageInfo.Margin.Right), (int)(pdfDocument.Pages[1].MediaBox.Height + pdfDocument.Pages[1].PageInfo.Margin.Bottom + pdfDocument.Pages[1].PageInfo.Margin.Top), new Resolution(resolution), quality);
jpegDevice.Process(pdfDocument.Pages[pageCount], imageStream);
imageStream.Close();
}
}
}
}
}

Note that there are 2 parameters we could adjust: resolution and quality and here are some testing result:
1. resolution: 94, quality: 70, generated png for one page file pixel size: 792 * 936, png file size: 155.9 KB
2. resolution: 94, quality: 100, generated png file for one page pixel size: 792 * 936, png file size: 468.8 KB
3. resolution: 94*16, quality: 100, generated png file for one page pixel size: 792 * 936, png file size: 468.8 KB

So basically quality would increase the file size, but not the file pixel size and it generally improve the image quality as well, however it doesn’t seem to have an effect on this PDF file.

Resolution does not seem have any effect which seems by design from this post in forum: https://forum.aspose.com/t/78728

I know that this is related with original PDF file as well, its font is with small size and light color, however with zoom 130%, it is readable at Adobe Reader, however the generated image is not readable at all no matter how I zoom it in, basically it is blurred. I could give the original PDF file if required. Any idea how we can generate a high quality image here? If so, how we could adapt this at our code to basically use different parameter for different PDF files?

The Aspose.pdf version we are using is: 8.9.0.0.

Thanks very much for your help.

Hi Pingzhong.


Thanks for contacting support.

Can you please share the source PDF file causing this problem so that we can test the scenario at our end. We are sorry for this inconvenience.

Thanks Nayyer.


I attached the original PDF file at this reply. By the way, after I double the size of height/width of the generated picture, now the png file looks much better. Here is the change at code ( bold):
static void Main(string[] args)
{
string pdfFileName = @“C:\Users\Pingzhong.Li\Downloads\SP_APP_Testing_Docs\10.1.1.25.6812.pdf”;
int resolution = 94*16;
int quality = 100;
int scale = 2;
using (var pdfStream = new FileStream(pdfFileName, FileMode.Open, FileAccess.Read))
{
Document pdfDocument = new Document(pdfStream);
for (int pageCount = 1; pageCount <= 4 && pageCount <= pdfDocument.Pages.Count; pageCount++)
{
Stream imageStream = new FileStream(pdfFileName + “.” + pageCount + “.png”, FileMode.CreateNew, FileAccess.Write);
JpegDevice jpegDevice = new JpegDevice((int)(pdfDocument.Pages[1].MediaBox.Width + pdfDocument.Pages[1].PageInfo.Margin.Left + pdfDocument.Pages[1].PageInfo.Margin.Right) * scale, (int)(pdfDocument.Pages[1].MediaBox.Height + pdfDocument.Pages[1].PageInfo.Margin.Bottom + pdfDocument.Pages[1].PageInfo.Margin.Top) * scale, new Resolution(resolution), quality);
jpegDevice.Process(pdfDocument.Pages[pageCount], imageStream);
imageStream.Close();
}
}
}

I guess the question would be how we would know when we need to increase the size of generated picture.
Regards,
Pingzhong

Hi Pingzhong,


Thanks for sharing the resource file.

I
have tested the scenario and I am able to notice the same problem that when using 1 as scale factor, the quality of image is not correct. For the sake
of correction, I have logged this problem as PDFNEWNET-36652 in
our issue tracking system. We will further look into the details of this
problem and will keep you updated on the status of correction. Please be
patient and spare us little time. We are sorry for this inconvenience.<o:p></o:p>


PS, I am afraid we cannot determine the time/scenario to increase image scale value.

Thanks very much Nayyer for looking into this. We will wait for the response then.

The issues you have found earlier (filed as PDFNEWNET-36652) have been fixed in Aspose.Pdf for .NET 9.2.0.

The blog post for this release is created over this link


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.