Aspose.PDF Annotation Flatten Deletes Square Annotations created by Aspose

Currently using Aspose.PDF .NET 24.4.0

Aspose.PDF flatten does not retain annotation visual styles for annotations created using Aspose.PDF, and in the case of Square Annotation, deletes it entirely.

Here is a file with several annotations. The four at the bottom of the page were created using mostly boilerplate code from the documentation examples. I added border properties, but that’s it. After creating the markups with Aspose, I opened the file in Bluebeam Revu, and manually made copies of the markups, so same properties, just copied by Bluebeam. Bluebeam versions are at the top of the page.
all annotations added.pdf (6.6 KB)

Then I used the Aspose.PDF flatten function. I tried the document flatten, the page flatten, and the annotation flatten, all with the same result. The annotations created or copied in Bluebeam Revu flattened properly using the Aspose function. The annotations created using Aspose are incorrect. They either look visually completely different or are deleted. This file is the flatten result:
all annotations added_flattened_by_aspose.pdf (31.0 KB)

Here is the annotation creation code:

private void HighlightPages(Document document)
{
    var circleAnnotation = new CircleAnnotation(document.Pages[1], new Rectangle(270, 160, 483, 383))
    {
        Title = "Annotation Created with Aspose",
        Subject = "Circle Annotation Created with Aspose",
        Color = Aspose.Pdf.Color.Red,
        InteriorColor = Aspose.Pdf.Color.MistyRose,
        Opacity = 0.25,
        Popup = new PopupAnnotation(document.Pages[1], new Rectangle(842, 316, 1021, 459))                
    };
    var circleBorder = new Border(circleAnnotation)
    {
        Width = 0,
        Effect = BorderEffect.None,
        Style = BorderStyle.Solid,
    };
    circleAnnotation.Border = circleBorder;


    var squareAnnotation = new SquareAnnotation(document.Pages[1], new Rectangle(67, 317, 261, 459))
    {
        Title = "Annotation Created with Aspose",
        Subject = "Square Annotation Created with Aspose",
        Color = Aspose.Pdf.Color.Blue,
        InteriorColor = Aspose.Pdf.Color.BlueViolet,
        Opacity = 0.25,
        Popup = new PopupAnnotation(document.Pages[1], new Rectangle(842, 196, 1021, 338))
    };
    var squareBorder = new Border(squareAnnotation)
    {
        Width = 0,
        Effect = BorderEffect.None,
        Style = BorderStyle.Solid,
    };
    squareAnnotation.Border = squareBorder;

    var polygonAnnotation = new PolygonAnnotation(document.Pages[1],
        new Rectangle(270, 193, 571, 383),
        new Point[] {
            new Point(274, 381),
            new Point(555, 381),
            new Point(555, 304),
            new Point(570, 304),
            new Point(570, 195),
            new Point(274, 195)})
    {
        Title = "Polygon Annotation Created with Aspose",
        Color = Color.Blue,
        InteriorColor = Color.BlueViolet,
        Opacity = 0.25,
        Popup = new PopupAnnotation(document.Pages[1], new Rectangle(842, 196, 1021, 338))
    };
    var polygonBorder = new Border(polygonAnnotation)
    {
        Width = 0,
        Effect = BorderEffect.None,
        Style = BorderStyle.Solid,
    };
    polygonAnnotation.Border = polygonBorder;

    // Create PoliLine Annotation
    var polylineAnnotation = new PolylineAnnotation(document.Pages[1],
        new Rectangle(270, 193, 571, 383),
        new Point[]
        {
            new Point(545,150),
            new Point(545,190),
            new Point(667,190),
            new Point(667,110),
            new Point(626,111)
        })
    {
        Title = "Polyline Annotation Created with Aspose",
        Color = Color.Red,
        Popup = new PopupAnnotation(document.Pages[1], new Rectangle(842, 196, 1021, 338)),                
    };

    // Add annotation to the page
    document.Pages[1].Annotations.Add(circleAnnotation);
    document.Pages[1].Annotations.Add(squareAnnotation);
    document.Pages[1].Annotations.Add(polygonAnnotation);
    document.Pages[1].Annotations.Add(polylineAnnotation);
}

Here is the flatten code:
public void Flatten()
{
    try
    {
        InitializeLicense();
        // Open the document
        using (Document pdfDocument = new Document(_filePath))
        {
            // Flatten the document
            //pdfDocument.Flatten();

            foreach (Page page in pdfDocument.Pages)
            {
                // Flatten the page
                //page.Flatten();
                
                foreach (Annotation annotation in page.Annotations)
                {


                    // Flatten the annotation
                    annotation.Flatten();
                }
            }


            // Save the updated document
            //pdfDocument.Save(_filePath);
            exportCopy(_filePath, pdfDocument, "flattened","flattened_by_aspose");
        }
    }
    catch (Exception ex)
    {
        // Handle any errors that occur during processing
        _logger.Log($"An error occurred while processing the PDF: {ex.Message}", SeverityType.Critical);
    }
}

@mtevebaugh

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): PDFNET-57058

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

Thank you. Is this an issue with the method of generating annotations? Is there a workaround to create the annotation in a way that it can be flattened?

@mtevebaugh

We are afraid that we cannot comment much about the issue or offer any workaround because the ticket is not yet analyzed. As soon as we make some progress towards ticket resolution, we will be sharing updates with you in this forum thread. Please be patient and spare us some time.