Scanned PDF incorrectly rendered into PNG with unreadable pages using Aspose.PDF (C#)

Hello!!
I’m having an issue when converting a PDF to PNG with some scanned documents. Some pages are unreadable, no matter which resolution I use with the PngDevice. I’ve tried several resolution settings or rendering options, with no better results.
This is the code I’m using:

public static void ImageConverter(String nameMask){
	Document doc = new Document(System.Web.HttpContext.Current.Server.MapPath("/DoctosAspose/Convert/output" + nameMask + ".pdf"));
	int TotalPages = doc.Pages.Count;

	for (int pageCount = 1; pageCount <= TotalPages; pageCount++)
	{
		using (FileStream imageStream = new FileStream(System.Web.HttpContext.Current.Server.MapPath("/DoctosAspose/Input/image" + nameMask + "-1" + pageCount + ".png"), FileMode.Create))
		{
			//I've tried with different resolution settings.
		//create PNG device with specified attributes
			//var res = new Resolution(300);
			//var res = new Resolution(300,300);
			//PngDevice pngDevice = new PngDevice(res);
			
			PngDevice pngDevice = new PngDevice(); //default constructor at 150dpi
			
			//pngDevice.RenderingOptions.UseNewImagingEngine = true;
			//pngDevice.RenderingOptions.ScaleImagesToFitPageWidth = true;
			//pngDevice.RenderingOptions.InterpolationHighQuality = true;

			//Convert a particular page and save the image to stream
			pngDevice.Process(doc.Pages[pageCount], imageStream);

			//Close stream
			imageStream.Close();			
		}This text will be hidden
	}	
}

The original document and the first four pages converted to png. Just the first page is readable:
input3742019020654491112010420.pdf (574.3 KB)
image3742019020654491112010420-2.jpg (247.3 KB)
image3742019020654491112010420-1.png (128.8 KB)
image3742019020654491112010420-4.png (67.0 KB)
image3742019020654491112010420-3.png (229.4 KB)

Any help will be appreciated, because I have my clients urging me for this, and is the only issue that I’ve been unable to fix.

@anbernardi

Thank you for contacting support.

We have worked with the data shared by you and have been able to reproduce the issue in our environment. A ticket with ID PDFNET-46011 has been logged in our issue management system for further investigation and resolution. The ticket ID has been linked with this thread so that you will receive notification as soon as the ticket is resolved.

We are sorry for the inconvenience.

Is there any news about this? Is this issue present in version 19?

anbernardi

Please note PDFNET-46011 was reproduced with Aspose.PDF for .NET 19.1 and has not been resolved yet owing to previously logged tickets.

It has been logged under free support model where issues have low priority and are resolved on first come first serve basis. The resolution of the logged issue may take several months depending upon how long is the queue of previously logged issues. Whereas, issues have high priority in paid support model and are dealt with high precedence. Paid support option is recommended for the customers who want their issues to be resolved on urgent basis.

As soon as we have significant updates regarding resolution of your issue, we will surely inform you in this very thread. Please be patient and spare us little time.

Thanks for your answer. I’ll keep waiting.

@abernardi

We appreciate your patience and comprehension in this regard.

Is there any news? I’m still facing this problem, and I’ve updated my lib version to 19.10.0.AposePDF unreadable VS Acrobat PDF.png (384.6 KB)

@abernardi

We are afraid PDFNET-46011 is still unresolved owing to previously logged and critical tickets. However, we have recorded your concerns and will let you know once any update will be available in this regard.

For the moment, using
p.RenderingOptions.UseNewImagingEngine = false;
solved the issue with version 20.1.0.

Anyway, I’ll be pleased if you find a solution.

@abernardi,

I like to inform that we are working on this and will share good news with you soon.

This issue is still broken in v22.8. When will this issue be fixed?? The issue is fixed when UseNewImagingEngine = false, but we need to set UseNewImagingEngine = true when rendering to fix other issues present in the library. Please provide a fix for this ASAP, this issue is almost three years old!!!

@ted-1

Would you please share a sample PDF and code snippet that you are using? We will create a separate ticket for your files and case and share it with you.

Please see attached “TestImage.pdf” as input, TestImage.jpg as output, and code below. Setting jpegDevice.RenderingOptions.UseNewImagingEngine = false corrects the issue, but we need to leave jpegDevice.RenderingOptions.UseNewImagingEngine = true for other issues with Aspose rendering.

TestImage.pdf (71.5 KB)
TestImage.jpg (57.8 KB)

        using (var memStream = new WslMemoryStream(inputPdfFileContent))
        {
            using (var doc = new Aspose.Pdf.Document(memStream))
            {
                numPages = doc.Pages.Count;
                var exportPage = doc.Pages[1];
                var pageRect = exportPage.GetPageRect(true);
                int exportWidth, exportHeight;
                if (pageRect.Height > pageRect.Width)
                {
                    if (pageRect.Height > maxWidthOrHeight)
                    {
                        exportHeight = maxWidthOrHeight;
                        exportWidth = (int)((pageRect.Width / pageRect.Height) * maxWidthOrHeight);
                    }
                    else
                    {
                        exportWidth = (int)pageRect.Width;
                        exportHeight = (int)pageRect.Height;
                    }
                }
                else
                {
                    if (pageRect.Width > maxWidthOrHeight)
                    {
                        exportWidth = maxWidthOrHeight;
                        exportHeight = (int)((pageRect.Height / pageRect.Width) * maxWidthOrHeight);
                    }
                    else
                    {
                        exportWidth = (int)pageRect.Width;
                        exportHeight = (int)pageRect.Height;
                    }
                }
                var resolution = new Aspose.Pdf.Devices.Resolution(96);
                var jpegDevice = new Aspose.Pdf.Devices.JpegDevice(exportWidth, exportHeight, resolution, 90);
                jpegDevice.RenderingOptions.InterpolationHighQuality = true;
                jpegDevice.RenderingOptions.UseNewImagingEngine = true;
                using (var exportStream = new WslMemoryStream())
                {
                    jpegDevice.Process(exportPage, exportStream);
                    exportStream.Flush();
                    return exportStream.ToArray();
                }
            }
        }

@windsorsolutions

A separate ticket as PDFNET-52672 has been logged in our issue tracking system for your files along with your concerns. We will definitely pay attention to this issue and let you know as soon as it is resolved. Please spare us some time.

We apologize for the inconvenience.

Is there any fix? Been waiting since 2019

@abernardi

The issues have already been escalated to the next level of priority and your concerns have been recorded as well. We will surely inform you once the attached tickets are resolved. We apologize for the inconvenience.