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()