Do you want to replace the text from..:
1. The pdf which is being uploaded and you want to get the uploaded pdf with replaced value.
OR
2. The pdf which is not yet generated but created and you want some changes in it.
In second case you can make changes in your data before adding it to your PDF doc.
For example:
In below example I am reading text file content and adding it to PDF doc.
At first time I am adding the content as it is but second time, first I am replacing values then adding it to Pdf.
HTML
<asp:FileUpload ID="fuUpload" runat="server" />
<asp:Button ID="btnGenerate" runat="server" Text="Generate" OnClick="OnGenerate" />
Code
protected void OnGenerate(object sender, EventArgs e)
{
//Save the Uploaded Text file.
string filePath = Server.MapPath("~/Uploads/") + Path.GetFileName(fuUpload.PostedFile.FileName);
fuUpload.SaveAs(filePath);
//Initialize the PDF document object.
using (Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 10f))
{
PdfWriter writer = PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
//Read Text file content
string content = File.ReadAllText(filePath);
//Add the Text file content to the PDF document object.
pdfDoc.Add(new Paragraph(content));
//Add the Text file content to the PDF document object after replacing values.
content = content.Replace("Mango", "Banana");
pdfDoc.Add(new Paragraph(content));
pdfDoc.Close();
//Download the PDF file.
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=Sample.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Write(pdfDoc);
Response.End();
}
}
The above is the solution for second case.
--------------------------------------------------------
For first case you will need to:
● First extract the text with its coordinates.
● Replace the text.
● Putting it to same coordinates where they were.
Refer the below link
https://stackoverflow.com/questions/23722427/adding-text-to-existing-multipage-pdf-document-in-memorystream-using-itextsharp/23738927