This article will explain how we can replace specific text from PDF using C# and Aspose.Pdf
Aspose.Pdf support to find specific word from PDF and replace it with the another text in all the pages of PDF document. This article is going to show you how to replace text from PDF. I have create Console Application for This demo.
Before you begin
Before you start with Aspose.Pdf, you have to purchase license version.
Install nuget
Install the nuget in Your application Aspose.Pdf
Put the Below Code in your Application
In this Demo I’m replacing “Your Name” word from Resume.pdf with the My Name “Chand Dakhara” and saved this as a new pdf with the name ReplaceResume.pdf
Console.WriteLine("Replcing process Start"); //Document Path string DocPath = "D:/Resume.pdf"; //Orginal Pdf Aspose.Pdf.License PdfLicense = new Aspose.Pdf.License(); PdfLicense.SetLicense("Aspose.Pdf.lic"); // OPEN DOCUMENTS Aspose.Pdf.Document doc = new Aspose.Pdf.Document(DocPath); // CREATE PDF CONTENT EDITOR OBJECT TO EDIT TEXT PdfContentEditor editor = new PdfContentEditor(); editor.BindPdf(doc); int PageCount = doc.Pages.Count; for (int i = 1; i <= PageCount; i++) { // CHANGE TEXT editor.ReplaceText("Your Name", i, "Chand Dakhara"); } // DOWNLOAD string newBaseDocPath = "D:/ReplaceResume.pdf"; //New Generate Pdf doc.Save(newBaseDocPath); Console.WriteLine("Replacing Process complete, now check new Generated PDF");