Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding Image watermark to Pdf while Creating it using iTextSharp

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.

like image 629
Deeptechtons Avatar asked May 18 '11 08:05

Deeptechtons


People also ask

How do I put a watermark on PDF?

Choose Document > Watermark > Add. Specify the watermark: To reuse a watermark and watermark options that you saved in an earlier session, select it from the Saved Settings menu. To create a text watermark, select Text, and type the text in the box.

What is the use of ITextSharp DLL?

What is ITextSharp? iTextSharp is a free and open source assembly that helps to convert page output or HTML content in a PDF file. Now add that DLL in the application. Getting Started: Start Visual Studio and create a new website in ASP.Net and add these 2 DLLs to the solution.


1 Answers

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);
like image 200
user1146956 Avatar answered Oct 03 '22 23:10

user1146956