Hi mahesh213,
Already sample provided regarding this.
What you need to do is after generating the pdf get the bytes from ms.ToArray(). Then add watermark image to it.
Refer below code and modify accordingly.
pdfDoc.Close();
byte[] bytes = ms.ToArray();
Bitmap bitmap = new Bitmap(300, 100, PixelFormat.Format64bppArgb);
Graphics graphics = Graphics.FromImage(bitmap);
graphics.Clear(Color.White);
graphics.DrawString("@ASPSnippets.com", new System.Drawing.Font("Arial", 20, FontStyle.Bold), new SolidBrush(Color.Red), new PointF(0.4F, 2.4F));
bitmap.Save(Server.MapPath("~/Image.jpg"), ImageFormat.Jpeg);
bitmap.Dispose();
var img = iTextSharp.text.Image.GetInstance(Server.MapPath("~/Image.jpg"));
img.SetAbsolutePosition(200, 600);
PdfContentByte waterMark;
using (MemoryStream stream = new MemoryStream())
{
PdfReader reader = new PdfReader(bytes);
using (PdfStamper stamper = new PdfStamper(reader, stream))
{
int pages = reader.NumberOfPages;
for (int i = 1; i <= pages; i++)
{
waterMark = stamper.GetUnderContent(i);
waterMark.AddImage(img);
}
}
bytes = stream.ToArray();
}
System.IO.File.Delete(Server.MapPath("~/Image.jpg"));
TempData["Data"] = bytes;