Hi, this is my first time to use your .NET PDF SDK. I am also quite new to c# programming. I have tried to find a solution on your website, but it didn't found any useful article till now. So, hope you can help me out soon.
This is what i am doing. I have installed XsPDF library and I am trying to insert a watermark into the document. Actually, the watermark is just a signature image. My problem is that I cannot simply add watermark images to a specific page of exiting PDF. I do not need to add images to a newly created PDF page. Just loading an existing PDF and add it is what all i need.
I can add text watermark to PDF exiting page now, but it cannot work with image watermark. I can only get the output PDF without the watermark. Certainly, i do something wrong. Hope you get what i say and please help.
This article on XsPDF.com is what are you looking for, check out: Add watermark on PDF in C#.
Answers
Thank you for contacting us. We appreciate your evaluation of our SDK. From what you explain, we can get the following requirements.
- You want to add image watermark at a specific position of PDF page
- You want to add watermark to an existing PDF and do not want to add it to a new page
If yes, there is nothing to worry about. Adding watermarks to an existing PDF file is quite simple. You can easily achieve this by copying the following c# sample code to your project. Simply load a PDF file and the image watermark, customize the position, and save it.
//Load PDF document PdfDocument document = new PdfDocument("sample.pdf"); //Load watermark image from local file string watermarkFile = "watermark.png"; var watermarkImg = XImage.FromFile(watermarkFile); //Add watermark to first page var page = document.Pages[0]; //The new content will be rendered above the existing graphic. var gfx = XGraphics.FromPdfPage(page, XGraphicsPdfPageOptions.Append); //Customize image location var location = new XPoint(100, 100); //Watermark the PDF page with image gfx.DrawImage(watermarkImg, location); //Customize image size //gfx.DrawImage(watermarkImg, location.X, location.Y, 50, 50); document.Save("image-watermark.pdf");
If you have additional questions about this, please directly reply.