GcPdf allows text search in a PDF document to find all occurences of the specified text and highlights them. It also works across line breaks, so logically connected text that is rendered on different text lines can also be found. The FindText method of GcPdfDocument class can be used for the same. This method accepts object of FindTextParams and OutputRange class as parameters to find all the occurrences of the searched string in the loaded document.
To search text in PDF document:
C# |
Copy Code
|
---|---|
public void CreatePDF(Stream stream) { var doc = new GcPdfDocument(); // The original file stream must be kept open while working with the loaded PDF using (var fs = new FileStream(Path.Combine("Resources","PDFs","BalancedColumns.pdf"), FileMode.Open, FileAccess.Read)) { doc.Load(fs); // Find all 'lorem', using case-insensitive word search: var findsLorem = doc.FindText (new FindTextParams("lorem", true, false), OutputRange.All); // Highlight all 'lorem' using semi-transparent orange red: foreach (var find in findsLorem) doc.Pages[find.PageIndex].Graphics.FillPolygon (find.Bounds[0], Color.FromArgb(100, Color.OrangeRed)); // Done: doc.Save(stream); } |
For more information about implementation of text search using GcPdf, see GcPdf sample browser.