0
PdfReader reader = new PdfReader(FileUpload1.PostedFile.FileName);
iTextSharp.text.Rectangle size = reader.GetPageSizeWithRotation(1);
Document document = new Document(size);
string name = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName);
FileStream fs = new FileStream(System.IO.Path.GetFullPath(FileUpload1.PostedFile.FileName), FileMode.Open, FileAccess.Write);
PdfWriter writer = PdfWriter.GetInstance(document, fs);
document.Open();                
byte[] data = ReadFully(FileUpload1.PostedFile.InputStream);
PdfContentByte cb = writer.DirectContent;
BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
cb.SetColorFill(BaseColor.DarkGray);
cb.SetFontAndSize(bf, 8);
cb.BeginText();
string hash = string.Empty;
using (SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider())
{
     hash = Convert.ToBase64String(sha1.ComputeHash(data));
}                
cb.ShowTextAligned(1, hash, 400, 150, 0);
cb.EndText();
PdfImportedPage page = writer.GetImportedPage(reader, 1);
cb.AddTemplate(page, 0, 0);
document.Close();
fs.Close();
writer.Close();
reader.Close();

I am trying to write a text on my pdf at specific coordinate. My text is getting in pdf but the old content is also getting lost.

please suggest solution. thanks in advance.

Sandeep Gupta
  • 37
  • 1
  • 7
  • You're doing it all wrong; you're not using `PdfStamper`. Since you seem to be completely new at iText, I suggest that you start working with the latest iText version (which is iText 7.1) instead of using an old iText version. Read [the iText 7 jump-start tutorial](https://developers.itextpdf.com/content/itext-7-jump-start-tutorial-net/chapter-5-manipulating-existing-pdf-document) and you'll discover that iText 7 is much easier to use than iText 5. – Bruno Lowagie Jan 03 '18 at 15:28
  • Possible duplicate of [ITextSharp insert text to an existing pdf](https://stackoverflow.com/questions/3992617/itextsharp-insert-text-to-an-existing-pdf) – Abdur Rahim Jan 04 '18 at 07:47

0 Answers0