Find and Highlight Text with Custom Color in PDF in C#, VB.NET

Find function is essential to any PDF reader, which makes it easy for user to locate the specified content in a PDF document. In this post, I’ll show you how to find and highlight searched text with custom color programmatically using .NET PDF library with C# and VB.NET. By using this component, you can also create the find and highlight feature in your own .NET application.

Step 1: Download Spire.PDF and add following namespace to your own project.


using Spire.Pdf;

using Spire.Pdf.General.Find;

using System.Drawing;


Imports Spire.Pdf

Imports Spire.Pdf.General.Find

Imports System.Drawing

Step 2: Use following code snippet to find and highlight text in the PDF document.


PdfDocument pdf = new PdfDocument(@”sample.pdf”);

PdfTextFind[] result = null;

foreach (PdfPageBase page in pdf.Pages)


    result = page.FindText(“SQL”).Finds;

    foreach (PdfTextFind find in result)








Dim pdf As New PdfDocument(“sample.pdf”)

Dim result As PdfTextFind() = Nothing

For Each page As PdfPageBase In pdf.Pages

    result = page.FindText(“SQL”).Finds

    For Each find As PdfTextFind In result









Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s