Get exact line number and page number of the keyword in both pdf and word.
I have made an Api and through which i am passing the keyword which maybe present in the pdf or word document and searching , so i need to know that where exactly it is located in the file , i need the line number and page number of that keyword.
@Aditya5
With page it’s relativly simple, you can just use TextFragmentAbsorber
Aspose.Pdf.Document pdfDocument = new Document(input);
//regex for specific keyword
var textFragmentAbsorber = new TextFragmentAbsorber("keyword_you_searching");
textFragmentAbsorber.TextSearchOptions = new TextSearchOptions(true);
//rectangle if you need to search in specific page area
//textFragmentAbsorber.TextSearchOptions.Rectangle = new Rectangle(0,700,600,1000);
pdfDocument.Pages.Accept(textFragmentAbsorber);
List<Page> pages = new List<Page>();
foreach (var fragment in textFragmentAbsorber.TextFragments)
{
pages.Add(fragment.Page);//this is page of found fragment
}
It’s a different case with line number, it doesn’t seem to contain such information
Could you describe for what reasons do you need line number?