PDF's are known to contain graphically transformed text drawing text on top of an existing PDF using page graphics.
Var findsMotorcycle = doc.FindText(new FindTextParams("Motorcycle", true, true), OutputRange.All) 5. Find all 'motorcycle' matching whole words and using case-sensitive word search: The FindTextParams constructor has parameters wholeWord and matchCase thatallow the user to indicate whether the search should match whole words, be case sensitive, or both. When conducting a text search users can specify the find text parameters using GcPDF’s FindTextParams constructor.
Results: Search and highlighting of found terms only happens on pages 3 and 4 of the PDF document. Var findsTextThe = doc.FindText(ftp, pageRange) Find all text using case-insensitive word search within the page range OutputRange pageRange = new OutputRange(3, 4) Define to and from page range properties Var ftp = new FindTextParams("the", true, false) Load an existing document from file stream
FIND WORD IN PDF DOCUMENT CODE
To conduct a text search within a range of pages in a PDF document, use GcPDF’s OutputRange Class to define the range of pages with the FromPage and ToPage properties.įor example, the following code will search pages 3 and 4 of the PDF for the word "the", then highlight it:Ĭ#: GcPdfDocument doc = new GcPdfDocument() Find Text in a Specific Range of PDF Pages See our GcPDF demo Get text from a specific position in a PDF for more information on using the text map of a PDF. This code will only highlight the text found on the second page of the PDF. Perform text search within the text map using FindText Method and highlight text orangeĭoc.(p_.Bounds, Color.FromArgb(100, Color.OrangeRed)) Get the text map of a page by its index, not index starts at 0 so this will search page 2 Var ftp = new FindTextParams("the", false, false) Create a new instance of FindTextParams, search for ‘the’ Perform text search within the text map using FindText MethodĬ#: // Create new instance of PDF document.Get the text map of a page by its index.Create a new instance of FindTextParams class.To do this get the text map of the page by its index and perform a text search only on that page’s text map.įor example, the below code will do the following: In some cases, users may only want to search for text on one page, instead of the entire PDF document. See GcPDF’s demo Find and highlight all occurrences of a string as another resource. (find.Bounds, Color.FromArgb(100, Color.OrangeRed)) Highlight all found text 'drive' using semi-transparent orange redĭoc. Var findsDrive = doc.FindText(new FindTextParams("drive", true, false), OutputRange.All) Use the FindText method to search text for drive, using case-insensitive, whole word match Using (var fs = new FileStream(Path.Combine("PDF Test.pdf"), Highlight each item found by using the System.Drawing Graphics class and the bounds of the found text.įor example, use the following code to find the word "drive" in a PDF and then highlight the found word.Ĭ#: // Create an object of GcPdfDocument class. Use GcPDF’s FindText method to perform a text search in a PDF. Find and Highlight Text in a PDF Document Find Text in a Specific Range of PDF Pagesĭownload Now! 1.Find and Highlight Text in a PDF Document.This blog will cover the steps required to conduct these text searches. GrapeCity’s Documents for PDF (GcPDF) our PDF API library, enables developers to conduct different types of text searches to find, highlight, or redact text within a PDF document.
Using GrapeCity's Documents for PDF you can accomplish all these text search and redact text scenarios from a PDF. You may even want to programmatically search and hide certain confidential data. When working with several PDF's it becomes vital to use a PDF API that can programmatically find the text based on different scenarios, such as searching on a particular page or range of pages or finding text with specified search parameters. When sharing PDFs there could be several documents that need to be searched to find some text. This allows companies to share data with ease and peace of mind. PDFs have become an exceedingly popular way to share and view data since the content within them is more difficult to modify.