Some test text!

Search for text in a PDF

To search for text in a PDF using regular expression.

PDFDoc doc = new PDFDoc(input_path + "credit card numbers.pdf");
Int32 page_num = 0;
String result_str = "", ambient_string = "";
Highlights hlts = new Highlights();

// use regular expression to find credit card number
TextSearch txt_search = new TextSearch();
Int32 mode = (Int32)(TextSearch.SearchMode.e_reg_expression | TextSearch.SearchMode.e_highlight);
txt_search.SetMode(mode);
pattern = "\\d{4}-\\d{4}-\\d{4}-\\d{4}"; //or "(\\d{4}-){3}\\d{4}"
txt_search.SetPattern(pattern);

//call Begin() method to initialize the text search.
txt_search.Begin( doc, pattern, mode, -1, -1 );

//call Run() method
TextSearch.ResultCode code = txt_search.Run(ref page_num, ref result_str, ref ambient_string, hlts );
Console.WriteLine("  " + result_str);

Search PDF files for text
Full code sample which shows how to use TextSearch to search text on PDF pages using regular expressions.

Get the answers you need: Support