Some test text!

Text searchkeyboard_arrow_down

Search for text in a PDF in Ruby

To search for text in a PDF using regular expression.

doc =
txt_search =
mode = TextSearch::E_whole_word | TextSearch::E_page_stop
pattern = ""

# use regular expression to find credit card number
mode |= TextSearch::E_reg_expression | TextSearch::E_highlight
pattern = "\\d{4}-\\d{4}-\\d{4}-\\d{4}"  #or "(\\d{4}-){3}\\d{4}"

# call Begin method to initialize the text search.
txt_search.Begin(doc, pattern, mode)
searchResult = txt_search.Run

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


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.

Join our live demo to learn about use cases & capabilities for WebViewer

Learn more