Do you need a high-speed solution to find and replace text in a bunch of PDF files using C#? No need to worry because this article provides a powerful mechanism to find and replace text in PDF files within a few simple steps. Let’s find out how it works.

C# find and replace text in PDF

The find and replace option makes it possible to replace a particular piece of text in a document in one go. This way, you do not have to locate and update each occurrence of the text in the whole document manually. So let’s see how to find and replace text in a PDF in C#. You can also use the same guidelines and the provided code samples to replace text in a batch of PDF files.

C# Library to Find and Replace Text in PDF

To find and replace text in PDF files, we will use Aspose.PDF for .NET. It is a C# class library that provides basic as well as advanced PDF manipulation features for .NET applications. The library also lets you find and replace text in PDF files in different ways with high accuracy and speed.

You can either download the library’s DLL or install it using NuGet.

PM> Install-Package Aspose.PDF

Find and Replace Text in PDF using C#

The following are steps to find and replace text in a PDF document.

C# Code to Replace Text in a PDF

The following code sample shows how to find and replace text in PDF using C#.

C# Replace Text in a Particular PDF Page

The following are steps to find and replace text on a particular page in a PDF document.

The following code sample shows how to find and replace text on a particular page of the PDF using C#.

Find and Replace Text in PDF Page Region

You can also find and replace text in a particular region of the page in a PDF document. The following steps show how to define a particular region and then replace text within it.

The following code sample shows how to find and replace text in a particular page region in a PDF using C#.

C# Replace Text in PDF with Regex

You can also use regular expressions to find and replace the text occurrences matching a particular pattern. For this, you only need to provide a regular expression instead of the plain search phrase and use TextSearchOptions. The following are the steps to do so.

The following code sample shows how to find and replace text in a PDF using regular expressions in C#.

Free C# Library to Replace Text in PDF

You can get a free temporary license and replace text in PDF files without any limitations.

Explore C# PDF Library

You can explore more advanced features of the C# PDF library using the documentation.

Conclusion

PDF automation is widely adopted these days to manipulate PDF documents from within the web or desktop applications. This article covered a useful PDF automation feature of finding and replacing text in PDF in C#. The step-by-step guide and code samples have shown how to find and replace text in a whole PDF, a particular page in PDF, or a page region.

See Also