0

I found this article to be helpful but I need to expand on it a little to get what I need - Search Particular Word in PDF using Itextsharp

I have some text in my PDF that is like this:

Full Name:  Bob Smith

The text "Full Name" will always be in the PDF but I don't know what the value of "Full Name" is and I need to be able to find that.

Is there a way to search a PDF for a certain text and get the value of the field instead of just looking for the field name? I need to be able to get "Bob Smith" or whatever is in that field. The name "Bob Smith" is going to be in the same place on each PDF and starts at the same number of spaces after the "Full Name" field, I am just not sure how to capture "Bob Smith"

Community
  • 1
  • 1
Baub
  • 723
  • 4
  • 21
  • 36
  • You keep saying "field" which makes it sound like your searching text fields within a form. Is this the case? Or are you just searching for text with a document. If your question is "does iTextSharp have a search a specific word function" I can tell you that no, it does not. You can extract text but its up to you to perform your search within the extracted text. – Chris Haas May 21 '14 at 18:41
  • 1
    Also, I'd recommend looking into the LocationTextExtractionStrategy shown here http://stackoverflow.com/a/4866110/231316 – Chris Haas May 21 '14 at 18:43

1 Answers1

2

I am using ABCPDf but the logic might be same

get the whole document into a string by using some thing like GETTEXT for (int i = 0; i <= doc.PageCount; i++) { doc.PageNumber = i; theDocString += doc.GetText(Page.TextType.Text); }

then search for certain string using Indexof int index = theDocString.IndexOf(str, 0, StringComparison.CurrentCultureIgnoreCase); bool isFound = index != -1;

MustangManiac
  • 317
  • 2
  • 13