Some test text!

menu
search
Text searchkeyboard_arrow_down

Search for text in a PDF

To search for text in a PDF using regular expression.

PDFDoc doc = new PDFDoc(filename);
Int32Ref pageNumber = new Int32Ref(0);
StringRef resultString = new StringRef();
StringRef ambientString = new StringRef();
Highlights highlights = new Highlights();
TextSearch textSearch = new TextSearch();

Int32 mode = (Int32)(TextSearchSearchMode.e_whole_word | TextSearchSearchMode.e_page_stop | TextSearchSearchMode.e_highlight);

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

//call Begin() method to initialize the text search.
textSearch.Begin(doc, pattern, mode, -1, -1);
TextSearchResultCode code = textSearch.Run(pageNumber, resultString, ambientString, highlights);

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

close

Free Trial

Get unlimited trial usage of PDFTron SDK to bring accurate, reliable, and fast document processing capabilities to any application or workflow.

Select a platform to get started with your free trial.

Unlimited usage. No email address required.

PDFTron Receives USD$71 Million Growth Investment Led By Silversmith Capital Partners

Learn more
close