How to Ignore Annotations When Extracting PDFs

How to Ignore Annotations When Extracting PDFs?
Is there a way to extract only the text of the PDF content without extracting the text from the PDF annotation?

@xuziqi

You can flatten the annotations and use TextAbsorber class to extract text from the PDF. However, if you are facing some issues, please share your sample PDF with us so that we can also test the scenario in our environment and address it accordingly.

I want to implement the following functions.
If a PDF document has comments, the comments are not extracted.
If a PDF document has no annotations, the annotations are not extracted, but the body text is extracted.
Is there a suitable method and sample code?

@xuziqi

We tested using below code snippet and it worked fine in our environment.

Document doc = new Document();
var page = doc.Pages.Add();
page.Paragraphs.Add(new TextFragment("A quick brown jumps over a lazy dog"));
TextAnnotation annot = new TextAnnotation(page, new Rectangle(200, 200, 300, 300));
annot.Contents = "Hello World!!";
page.Annotations.Add(annot);
doc.Save(dataDir + "samplePDF.pdf");

Document pdfDocument = new Document(dataDir + "samplePDF.pdf");
TextAbsorber textAbsorber = new TextAbsorber();
pdfDocument.Pages.Accept(textAbsorber);
var t = textAbsorber.Text;