I am having a source file of pdf.I want to replace specified texts with the code in my c#.I am here using ItextSharp libary and below is my code:
//using iTextSharp.text.pdf;
string OrigFile = "Original.pdf";
string ResultFile = "MyPDF.pdf";
using (PdfReader reader = new PdfReader(OrigFile))
{
for (int i = 1; i <= reader.NumberOfPages; i++)
{
byte[] contentBytes = reader.GetPageContent(i);
string contentString = PdfEncodings.ConvertToString(contentBytes, "PDF");
contentString = contentString.Replace(OriginalText, ReplacedText);
reader.SetPageContent(i,PdfEncodings.ConvertToBytes(contentString, PdfObject.TEXT_PDFDOCENCODING));
}
new PdfStamper(reader, new FileStream(ResultFile, FileMode.Create, FileAccess.Write)).Close();
}
This code doesn’t work and my Result file is not changed with replaced text.
What is the exact problem with the above??Can anyone suggest me.
I have tried this using ItextSharp.