2

I am developing a C# winform application that converts the pdf contents to text. All the required contents are extracted except the content found in highlighted text of the pdf. Please help to get the working sample to extract the highlighted text found in pdf. I am using the iTextSharp.dll in the project

Binod
  • 313
  • 1
  • 2
  • 12
  • 1
    Are you talking about annotations? You need to be more clear. Annotations are elements that aren't part of the content stream of a page. They are always added on top of the page and have their own appearance stream. You can list them in a separate panel in Adobe Reader. Are we talking about that kind of content? – Bruno Lowagie Apr 28 '14 at 13:34

1 Answers1

2

Assuming that you're talking about Comments. Please try this:

for (int i = pageFrom; i <= pageTo; i++)
{
    PdfDictionary page = reader.GetPageN(i);
    PdfArray annots = page.GetAsArray(iTextSharp.text.pdf.PdfName.ANNOTS);
    if (annots != null)
        foreach (PdfObject annot in annots.ArrayList)
        {
            PdfDictionary annotation = (PdfDictionary)PdfReader.GetPdfObject(annot);
            PdfString contents = annotation.GetAsString(PdfName.CONTENTS);
            // now use the String value of contents
        }
}

This is written from memory (I'm a Java developer, not a C# developer).

Gangula
  • 5,193
  • 4
  • 30
  • 59
Bruno Lowagie
  • 75,994
  • 9
  • 109
  • 165
  • you can use `PdfArray quadPoints = annotation.GetAsArray(PdfName.QUADPOINTS);` to get the quad points of the annotation – Gangula Dec 20 '22 at 09:14