Blank PDF page convertion to PNG fails

Hello,

We have an issue trying to convert a blank pdf page to png.
With version 18.12.0, we get a NullReferenceException trying to read the ‘Contents’ property of an Aspose.PDF.Page :

bool hasContent = page.Contents.Any();

With version 19.9.0, we get an InvalidOperationException instead.

This issue seems to be related to the way the pdf was generated (with 2A55SAM Spool-a-Matic by Gumbo Software Inc V2R7M0). When we open the pdf file with notepad, we can see the blank page content is set to ‘null’ (/Type /Page /Parent 146 0 R /Contents null /Resources 2 0 R /MediaBox [ 0 0 595 841 ] >>) while other pdf generators usually set a blank page with an empty array (/Contents []).

blank.pdf (62.4 KB)

This is an example of a pdf with a blank page whose Contents is null.

@ThomasNk

We tested the scenario with Aspose.PDF for .NET 19.9 and were unable to replicate the issue that you have mentioned.

Document pdf = new Document(dataDir + "blank.pdf");
bool isEmpty = pdf.Pages[1].Contents.Any();

Above code snippet did not throw any exception. Would you please share complete code snippet and specific line of code where you are facing an error. It would also be helpful if you can please share a sample console application for our reference which is able to replicate the issue. We will test the scenario in our environment and address it accordingly.

I’ve run your code snippet with Aspose.PDF 19.9.0 and I do get an InvalidOperationException “Wrong format of page’s content.” with the second line.

I’ve tried it on my dev environment and also on a windows server 2012 R2.

Here’s the code i’m using :

public static void TestPdfToPng(string file)
{
try
{
Console.WriteLine($“Aspose.PDF : {typeof(Document).Assembly.GetName().Version}”);
Console.WriteLine($“File : {Path.GetFileName(file)}\n”);
var document = new Document(file);
bool isEmpty = document.Pages[1].Contents.Any();

            Console.WriteLine($"Empty? {isEmpty}");
        }

        catch (Exception ex)
        {
            Console.WriteLine(ex.ToString());
            Console.WriteLine("");
        }

        return;
    }

And here’s the output :

Aspose.PDF : 19.9.0.0
File : blank.pdf

System.InvalidOperationException: Wrong format of page’s content.
à #=ziCn8xkhpEvz81VUi9_dYA_yZQNtR7zAqDGg5V_iu8ca9.#=zyyIVi0_49tUt(#=z2oJIomNm6jGS8I6k0Bx3hzRyT0G3_TqT2w== #=zKsiV6Rc=, #=zklR7lxUuz8iQbde7HzYawJdEKEqGdG$4pRlD7YNWQJlL #=zxD8o_$JM4nwZILAVjw==, Boolean #=zJ2Zgm9OwjuQC, Boolean #=znFAXUWPV93so)
à #=ziCn8xkhpEvz81VUi9_dYA_yZQNtR7zAqDGg5V_iu8ca9.#=zyyIVi0_49tUt(#=z2oJIomNm6jGS8I6k0Bx3hzRyT0G3_TqT2w== #=zKsiV6Rc=, #=zklR7lxUuz8iQbde7HzYawJdEKEqGdG$4pRlD7YNWQJlL #=zxD8o_$JM4nwZILAVjw==)
à Aspose.Pdf.OperatorCollection.#=zm76UJ8dESQWI()
à Aspose.Pdf.OperatorCollection.#=zlqsA0i0bbLQ9()
à Aspose.Pdf.OperatorCollection.get_Count()
à Aspose.Pdf.OperatorCollection.#=zQElKRW8=.MoveNext()
à System.Linq.Enumerable.Any[TSource](IEnumerable`1 source)
à ConsoleApp1.Program.TestPdfToPng(String file) dans C:\00_VisualStudio\ConsoleApp1\ConsoleApp1\Program.cs:ligne 241

@ThomasNk

Would you kindly share complete details of your development environment i.e. OS Name and Version, Application Type, etc. We will test the scenario in our environment and address it accordingly.

OS : Windows 10 Pro x64
ApplicationType : Console x64
Framework .NET : 4.5.2

@ThomasNk

We tested the scenario in same environment and were unable to notice the issue. Which why we requested you to share a sample console project so that we can again test the scenario and address it accordingly.

I’ve attached the console project I’ve been using.
You’ll have to copy Aspose.PDF.dll in the directory though, as it was to big to upload.console.zip (5.3 KB)

@ThomasNk

Thanks for sharing the files.

We were able to notice that your executable console application was showing the error you mentioned. However, we requested you to share complete console VS project not just Debug/Release folder. You can share a simple and small VS Project without DLLs and License file which is able to replicate the issue. This would help us testing the scenario in our environment and address it accordingly.

Please find attached the VS solution I’ve been using.TesterLight.zip (223.9 KB)

@ThomasNk

Thanks for sharing sample project.

We were able to notice the issue in our environment and logged it as PDFNET-47053 in our issue tracking system. We will further look into details of the issue and keep you posted with the status of its correction. Please be patient and spare us little time.

We are sorry for the inconvenience.

The issues you have found earlier (filed as PDFNET-47053) have been fixed in Aspose.PDF for .NET 20.3.