I have a problem, not get extract the Highlighted Text from PDF File. The str variable is always empty. Anybody can help me?
My code:
private static string GetPdfHighlighText(string file, int page) {
string nv = "";
PdfReader reader = new PdfReader(file);
for (int x = 1; x < reader.NumberOfPages; x++)
{
PdfDictionary pageDict = reader.GetPageN(x);
PdfArray annots = pageDict.GetAsArray(PdfName.ANNOTS);
if (annots != null)
{
for (int i = 1; i <= annots.Size; ++i)
{
PdfDictionary annotationDic = (PdfDictionary)PdfReader.GetPdfObject(annots[i]);
PdfName subType = (PdfName)annotationDic.Get(PdfName.SUBTYPE);
if (subType.Equals(PdfName.HIGHLIGHT))
{
PdfString str = annots.GetAsString(i);
nv = nv + str;
}
}
}
}
return nv; }
I'm using ITextSharp library. PFLibrary is iTextSharp.text.pdf namespace.
I want sweep all pages from pdf and extract all Highlighted Texts, It is 245 pages but i will put filter per page. I can identify the highlight annotations however not returned a string with the text highlighted