Issues with Flattening Annotations Using Aspose.PDF - Missing Underlines, Polygon Fills, and Cloud Shapes

Hi Team,

I’m experiencing issues with flattening annotations in a PDF document using Aspose.PDF. We are importing XFDF annotations and attempting to flatten them, but some annotations do not render correctly in the final output. Specifically, the following issues occur:

  1. Underlines and Squiggly Text: After flattening, the underline and squiggly text annotations are missing.
  2. Polygon and Cloud Shapes: The fill color inside the polygon and cloud shapes is not appearing. Only the outline is visible.
  3. Cloud Shapes: Cloud shapes are turning into regular lines and lose their “bump” structure.

We tried the following approach to flatten annotations but encountered the issues mentioned above. Here’s the code we used:

PdfAnnotationEditor AnnotationEditor = new PdfAnnotationEditor();
AnnotationEditor.BindPdf(inputpath);

// Import annotation from XFDF
using (MemoryStream xfdfStream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(xmlString)))
{
AnnotationEditor.ImportAnnotationsFromXfdf(xfdfStream);
}

// Flatten the annotations
AnnotationEditor.FlatteningAnnotations();

// Save the output PDF
AnnotationEditor.Save(outputpath);

I have attached the input file and the output file after flattening and also the XFDF string file

Original.pdf (2.3 KB)
Expected Output.pdf (24.5 KB)
original_AsposeOutput.pdf (30.0 KB)
XFDF XML string.docx (16.3 KB)

The Asposeoutput shows the issues described above when compared with expected output which is coming before flattening.

Please let me know if there’s anything I can adjust in the code or if there’s a known limitation with Aspose.PDF when flattening these specific annotations. I would appreciate your guidance on resolving this issue.

Thank you in advance for your support!

@Anvesa

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-58963

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.

Is there any work around currently i can use to get the flatten PDF , as i have to do some other operations on the PDF downstream which are getting impacted with this ?

Any work around would be highly helpful.

@Anvesa

You can try using DOM approach instead of Facades Classes and see if that helps. e.g.

var pdfDocument = new Aspose.Pdf.Document(dataDir + "input.pdf");
pdfDocument.Flatten();
pdfDocument.Save(dataDir + "output.pdf");

OR

using (Document document = new Document(dataDir + "Unbenannt.pdf"))
{
    document.Flatten();
    foreach (var page in document.Pages)
    {
        foreach (var annotation in page.Annotations)
        {
            annotation.Flatten();
        }
    }
    if (document.Form.Fields.Count() > 0)
    {
        foreach (var item in document.Form.Fields)
        {
            item.Flatten();
        }
    }
    Aspose.Pdf.Forms.Form.FlattenSettings flattenSettings = new Aspose.Pdf.Forms.Form.FlattenSettings()
    {
        CallEvents = true,
        HideButtons = false,
        UpdateAppearances = true
    };
    document.Flatten(flattenSettings);
    document.Save(dataDir + "3_Fattened_out.pdf");
}

I have tried both the options you provided, and both are giving the same ouput like before
Missing annotations, shape out and missing fill color

@Anvesa

Can you please confirm if you have tried with 24.12 version of the API as well?

We are using Aspose.PDF.Drawing 24.1.0 version

have you tried 24.12 version and it resolved the issue with the above code?

@Anvesa

We tested using 24.12 version and the suggested code snippet from our previous reply and the output remained same.
Fattened_out.pdf (23.0 KB)

The ticket information has been updated accordingly as well. We will 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.