Text Find and Replace

You can find and replace text within a PDF using IronPDF's Replace.

using IronPdf; class PdfTextReplacer { static void Main() { // Load the PDF document from a file var pdfDocument = PdfDocument.FromFile("example.pdf"); // Replace text on a specific page // Parameters: page number, text to find, replacement text pdfDocument.ReplaceTextOnPage(1, "old text", "new text"); // Save the updated PDF to a new file pdfDocument.SaveAs("updated_example.pdf"); // Notify the user Console.WriteLine("Text replacement complete. The updated PDF has been saved as 'updated_example.pdf'."); } }
using IronPdf; class PdfTextReplacer { static void Main() { // Load the PDF document from a file var pdfDocument = PdfDocument.FromFile("example.pdf"); // Replace text on a specific page // Parameters: page number, text to find, replacement text pdfDocument.ReplaceTextOnPage(1, "old text", "new text"); // Save the updated PDF to a new file pdfDocument.SaveAs("updated_example.pdf"); // Notify the user Console.WriteLine("Text replacement complete. The updated PDF has been saved as 'updated_example.pdf'."); } }
Imports IronPdf Friend Class PdfTextReplacer	Shared Sub Main()	' Load the PDF document from a file	Dim pdfDocument = PdfDocument.FromFile("example.pdf")	' Replace text on a specific page	' Parameters: page number, text to find, replacement text	pdfDocument.ReplaceTextOnPage(1, "old text", "new text")	' Save the updated PDF to a new file	pdfDocument.SaveAs("updated_example.pdf")	' Notify the user	Console.WriteLine("Text replacement complete. The updated PDF has been saved as 'updated_example.pdf'.")	End Sub End Class
$vbLabelText   $csharpLabel

This code demonstrates how to replace text in a PDF file using the IronPDF library in C#. First, ensure you have the IronPDF library installed via NuGet. The code loads an existing PDF through the FromFile method, replaces text on the specified page using ReplaceTextOnPage, and saves the result as a new PDF file. The page number, text to replace, and new text need to be specified. Finally, the changes are saved with SaveAs, and a message is printed to confirm the operation is complete.