ByteScout Premium 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 Premium Suite – C# – Regular expression search In PDF And Highlight On Rendered Page

  • Home
  • /
  • Articles
  • /
  • ByteScout Premium 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# and ByteScout Premium Suite

Learn to code in C# to regular expression search in PDF and highlight on rendered page with this step-by-step tutorial

We made thousands of pre-made source code pieces for easy implementation in your own programming projects. ByteScout Premium Suite can regular expression search in PDF and highlight on rendered page. It can be applied from C#. ByteScout Premium Suite is the bundle that includes twelve SDK products from ByteScout including tools and components for PDF, barcodes, spreadsheets, screen video recording.

Want to save time? You will save a lot of time on writing and testing code as you may just take the C# code from ByteScout Premium Suite for regular expression search in PDF and highlight on rendered page below and use it in your application. Simply copy and paste in your C# project or application you and then run your app! Want to see how it works with your data then code testing will allow the function to be tested and work properly.

If you want to try other source code samples then the free trial version of ByteScout Premium Suite is available for download from our website. Just try other source code samples for C#.

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 Premium Suite Home Page

Explore ByteScout Premium Suite Documentation

Explore Samples

Sign Up for ByteScout Premium 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 Premium Suite Home Page

Explore ByteScout Premium Suite Documentation

Explore Samples

Sign Up for ByteScout Premium Suite Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

Tutorials:

prev
next