ByteScout PDF Suite - C# - Regular expression search In PDF And Highlight On Rendered Page - ByteScout
Announcement
Our ByteScout SDK products are sunsetting as we focus on expanding new solutions.
Learn More Open modal
Close modal
Announcement Important Update
ByteScout SDK Sunsetting Notice
Our ByteScout SDK products are sunsetting as we focus on our new & improved solutions. Thank you for being part of our journey, and we look forward to supporting you in this next chapter!

ByteScout PDF Suite – C# – Regular expression search In PDF And Highlight On Rendered Page

  • Home
  • /
  • Articles
  • /
  • ByteScout PDF Suite – C# – Regular expression search In PDF And Highlight On Rendered Page

How to regular expression search in PDF and highlight on rendered page in C# with ByteScout PDF Suite

This code in C# shows how to regular expression search in PDF and highlight on rendered page with this how to tutorial

Every ByteScout tool includes simple example C# source codes that you can get here or in the folder with installed ByteScout product. ByteScout PDF Suite is the set that includes 6 SDK products to work with PDF from generating rich PDF reports to extracting data from PDF documents and converting them to HTML. This bundle includes PDF (Generator) SDK, PDF Renderer SDK, PDF Extractor SDK, PDF to HTML SDK, PDF Viewer SDK and PDF Generator SDK for Javascript and you can use it to regular expression search in PDF and highlight on rendered page with C#.

Want to quickly learn? This fast application programming interfaces of ByteScout PDF Suite for C# plus the guidelines and the code below will help you quickly learn how to regular expression search in PDF and highlight on rendered page. Follow the instructions from scratch to work and copy the C# code. Use of ByteScout PDF Suite in C# is also described in the documentation included along with the product.

ByteScout PDF Suite free trial version is available on our website. C# and other programming languages are supported.

On-demand (REST Web API) version:
 Web API (on-demand version)

On-premise offline SDK for Windows:
 60 Day Free Trial (on-premise)

Program.cs
      
using System.Diagnostics; using System.Drawing; using Bytescout.PDFExtractor; using Bytescout.PDFRenderer; namespace SearchAndHighlightExample { class Program { static void Main(string[] args) { const string inputFile = @"sample.pdf"; const int pageIndex = 0; const float renderingResolution = 300f; const string searchPattern = "\\d+\\.\\d+"; // Prepare TextExtractor using (TextExtractor textExtractor = new TextExtractor("demo", "demo")) { textExtractor.RegexSearch = true; textExtractor.LoadDocumentFromFile(inputFile); // Preapre RasterRenderer using (RasterRenderer rasterRenderer = new RasterRenderer("demo", "demo")) { rasterRenderer.LoadDocumentFromFile(inputFile); // Render document page to image Image image = rasterRenderer.GetImage(pageIndex, renderingResolution); // Prepare highlight brush Brush highlightBrush = new SolidBrush(Color.FromArgb(128, Color.Yellow)); using (Graphics graphics = Graphics.FromImage(image)) { // Search for pattern and paint found piecese if (textExtractor.Find(pageIndex, searchPattern, caseSensitive: false)) { do { foreach (var foundPiece in textExtractor.FoundText.Elements) { // Convert from document Points to pixels Rectangle pixelRect = new Rectangle( (int) (foundPiece.Bounds.Left / 72f * renderingResolution), (int) (foundPiece.Bounds.Top / 72f * renderingResolution), (int) (foundPiece.Bounds.Width / 72f * renderingResolution), (int) (foundPiece.Bounds.Height / 72f * renderingResolution) ); // Paint rectangle graphics.FillRectangle(highlightBrush, pixelRect); } } while (textExtractor.FindNext()); } } image.Save("result.png"); Process.Start("result.png"); } } } } }

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit ByteScout PDF Suite Home Page

Explore ByteScout PDF Suite Documentation

Explore Samples

Sign Up for ByteScout PDF Suite Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

VIDEO

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit ByteScout PDF Suite Home Page

Explore ByteScout PDF Suite Documentation

Explore Samples

Sign Up for ByteScout PDF Suite Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

Tutorials:

prev
next