Is it possible to remove annotation in pdf?

Skip Navigation LinksHome  /  Support  /  Forums  /  DynamicPDF CoreSuite for .NET (v10)  /  Is it possible to remove annotation in pdf?

DynamicPDF CoreSuite for .NET (v10) Forum

Is there a way to remove an annotation by loading an already created pdf?
Posted by a ceTe Software moderator
Hello,

You can remove all the annotations in a PDF by setting the PageAnnotations merge option to false. Here is a code sample:

     MergeOptions options = new MergeOptions();
     options.PageAnnotations = false;
     MergeDocument document = new MergeDocument(@"Input PDF file path", options);
     document.Draw(@"Output PDF file path");

Thanks,
ceTe Software Support Team
I want to remove only certain annotation.
If it is possible, please let me know what to do.
It is not working.

public void AddRectangle()
{
                       MergeDocument doc = new MergeDocument("D:\\TestData\\test.pdf");
                        
                        Rectangle rectangle = new Rectangle(100, 100, 50, 50);
                        rectangle.BorderStyle = LineStyle.Solid;
                        rectangle.CornerRadius = 5;
                        rectangle.FillColor = RgbColor.Yellow;
                        rectangle.ID = "Exhibit 1 Rectangle";

                        TextArea textArea = new TextArea("Exhibits 1", 100, 100, 50, 50);
                        textArea.ID = "Exhibit 1 Rectangle";

                        doc.Pages[0].Elements.Add(rectangle);
                        doc.Pages[0].Elements.Add(textArea);
                        doc.Draw("D:\\TestData\\test2.pdf");
}

public void RemoveRectangle()
{
                       MergeOptions options = new MergeOptions();
                        options.PageAnnotations = false;
                        MergeDocument document = new MergeDocument("D:\\TestData\\test2.pdf", options);

                        document.Draw("D:\\TestData\\test3.pdf");
}

The rectangle and letters remain.
See what I want below code.

public void RemoveRectangle()
{
                        MergeDocument document = new MergeDocument("D:\\TestData\\test2.pdf");

                       foreach (Page item in document.Pages)
                        {
                                foreach (PageElement element in item.Elements)
                                {
                                    if (element.ID == "Some ID")
                                    {
                                         Remove this item.
                                    }
                                }
                        }

                        document.Draw("D:\\TestData\\test3.pdf");
}
Posted by a ceTe Software moderator
Hello,

Currently we only support removing all annotations, and not a specific one. We're added this as a feature request and may add it as a feature in a future build, but please note that we do not have any exact time line on this.

Thanks,
ceTe Software Support Team

All times are US Eastern Standard time. The time now is 3:31 PM.