Free Support Forum - aspose.com

Latest Aspose.PDF nuget package throwing errors on some pdf

Hi Aspose Support,

We are using latest Aspose.PDF nuget package i.e. 21.3.0 released on March 21, 2021 to flatten the PDFs but its throwing an error on some pdf with this exception message “Object reference not set to an instance of an object”

Here is the sample code snippet

SampleInputFile.pdf (58.3 KB)

   public static void FlattenPdf(string pdfFilePath)

    {

        try

        {

            if (string.IsNullOrWhiteSpace(pdfFilePath))

            {

                return;

            }



            using var document = new Document(pdfFilePath);

            document.Flatten();

            document.Save(pdfFilePath);

            document.FreeMemory();

        }

        catch (Exception ex)

        {

            throw ex;

        }

    }

Stack trace of error:

at Aspose.Pdf.Page.#=zNvIePhg=(Boolean #=zR$IgorztICpHAjrGLw==)

at Aspose.Pdf.Document.#=zTmx6GwQ=()

at Aspose.Pdf.Document.Flatten(FlattenSettings flattenSettings)

at Aspose.Pdf.Document.Flatten()

@IRISNDT

I have been able to reproduce the issue shared and a ticket with ID PDFNET-49733 has been created to further investigate and resolve the issue. This thread has been linked with the issue so that you may be notified once the issue will be fixed.