Flattening of 50+ pages document

The document.flatten() doesn’t flatten all annotations for 51+ page documents.
PDF document:
document.pdf (277.7 KB)

Code to repro the issue:
static void Main(string[] args)
{
Document document = new Document(“document.pdf”);

        // Uncomment the following line to see that the document will be flattened successfully if it's 10 pages only.
        //while (document.Pages.Count > 10) document.Pages.Delete(document.Pages.Count);

        document.Flatten();

        foreach (var page in document.Pages)
        {
            int annotationsCount = page.Annotations?.Count ?? 0;
            if (annotationsCount != 0)
            {
                throw new Exception(String.Format("Document still has {0} annotation(s) on page {1}", annotationsCount, page.Number));
            }
        }
        document.Save("document_out.pdf");
    }

@mmrusin

Could you please try using the following code snippet with Aspose.PDF for .NET 21.1 and let us know if you still face any issue. We tested this in our environment and noticed that all annotations were flattened:

Document doc = new Document(dataDir + "document.pdf");
foreach (Page page in doc.Pages)
{
 foreach(Annotation annot in page.Annotations)
 { 
  annot.Flatten();
 }
}
foreach (var page in doc.Pages)
{
 int annotationsCount = page.Annotations?.Count ?? 0;
 if (annotationsCount != 0)
 {
  Console.WriteLine(String.Format("Document still has {0} annotation(s) on page {1}", annotationsCount, page.Number));
 }
}
doc.Save(dataDir + "Flatten.pdf");

Hello Asad,

First of all, I would like to thank you for the quick turn on this - it’s really appreciated!

Just retested on the newly published Aspose.PDF 21.1.0 - the issue still persists.

Please comment the validation block and open the resulting PDF in Adobe Acrobat:
image.png (65.1 KB)
You will see that notes were not flattened by document.flatten()
The processing works fine if we will delete a few pages before flattening - document.flatten works fine with documents up to 49 pages.

Possible workarounds: to flatten all annotations on all pages (as you mentioned above) or to flatten all pages (it also works fine).
The issue is: we can’t rely on document.flatten() and have to add some additional code to validate and flatten skipped pieces.

@mmrusin

Thanks for sharing your feedback.

We have logged an issue as PDFNET-49269 in our issue tracking system for this case. We will surely look into its details and keep you posted with the status of its correction. Please be patient and spare us some time.

We are sorry for the inconvenience.

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