Adding Image watermark to Pdf while Creating it using iTextSharp

Deeptechtons picture Deeptechtons · May 18, 2011 · Viewed 18.7k times · Source

Wonder if this possible. Saw many posts on adding watermark after the pdf is created and saved in disk. But during creation of document how do i add a image watermark. I know how to add a image to document. But how do i position it such that it comes at the end of page.

Answer

user1146956 picture user1146956 · Feb 3, 2012

For C#, use this code...

//new Document

Document DOC = new Document();


// open Document

DOC.Open();


//create New FileStream with image "WM.JPG"

FileStream fs1 = new FileStream("WM.JPG", FileMode.Open);


iTextSharp.text.Image JPG = iTextSharp.text.Image.GetInstance(System.Drawing.Image.FromStream(fs1), ImageFormat.Jpeg);


//Scale image

JPG.ScalePercent(35f);


//Set position

JPG.SetAbsolutePosition(130f,240f);

//Close Stream

fs1.Close();


DOC.Add(JPG);