Editing in Existing Pdf File in asp.net
<p>I have written this code i want to edit the existing PDF file by removing already text and want to enter new data for edit but this code not work after adding text first text not removed.</p>

<pre><code>string fileName = "PdfFileDocument1.pdf";
string newFile = "File.PDF";
PdfReader reader = new PdfReader(Server.MapPath(fileName));
Rectangle size = reader.GetPageSizeWithRotation(1);
Document document = new Document(size);

// open the writer
FileStream fs = new FileStream(Server.MapPath(newFile), FileMode.Create, FileAccess.Write);
PdfWriter writer = PdfWriter.GetInstance(document, fs);
document.Open();

// the pdf content
PdfContentByte cb = writer.DirectContent;

// select the font properties
BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
cb.SetColorFill(Color.BLUE);
cb.SetFontAndSize(bf, 8);

// write the text in the pdf content
cb.BeginText();
string text = "Some random Words";
// put the alignment and coordinates here
cb.ShowTextAligned(1, text, 100, 0, 0);
cb.EndText();
cb.BeginText();
// put the alignment and coordinates here
cb.ShowTextAligned(2, text, 0, 40, 0);
cb.EndText();

// create the new page and add it to the pdf
PdfImportedPage page = writer.GetImportedPage(reader, 1);
cb.AddTemplate(page, 0, 0);

// close the streams and voilá the file should be changed :)
document.Close();
fs.Close();`enter code here`
writer.Close();
reader.Close();
</code></pre>
