Adding watermark to an existing PDF using Spire.PDF

Technical support for Spire.PDF

Moderator: iceblue support

Adding watermark to an existing PDF using Spire.PDF

Postby sony » Sat Oct 01, 2011 3:18 pm

Hello,

I have downloaded the evaluation version of Spire.PDF.

I would like to add a text or image watermark to an existing pdf.

I need to open/load the pdf and go to a particular page and add a watermark.

Alternatively, add watermark to all pages of the existing pdf.

Could you please help with some sample code that will explain how this could be done.

Looking for an early reply as I need to get it working and inform that client

Thanking you

Best Regards,

Sony
sony
 
Posts: 1
Joined: Sat Oct 01, 2011 5:02 am

Re: Adding watermark to an existing PDF using Spire.PDF

Postby Tina.Lin » Mon Oct 10, 2011 1:22 am

Hello,

Sorry for late reply and thank you for your patience with our reply.
If you want to add image or text watermark for the existing Pdf, you can try the following code:
Code: Select all
            PdfDocument doc = new PdfDocument(@"..\..\Sample1.pdf");
            Image img = Image.FromFile(@"..\..\Background.png");
            for (int i = 0; i <doc.Pages.Count; i++)
            {
                //add image to the existing pdf file
                doc.Pages[i].BackgroundImage = img;
               //add Text WaterMark               
                PdfTilingBrush brush
                = new PdfTilingBrush(new SizeF(doc.Pages [i].Canvas.ClientSize.Width /2,doc.Pages  [i].Canvas.ClientSize.Height / 3));
                brush.Graphics.SetTransparency(0.3f);
                brush.Graphics.Save();
                brush.Graphics.TranslateTransform(brush.Size.Width / 2, brush.Size.Height / 2);
                brush.Graphics.RotateTransform(-45);
                brush.Graphics.DrawString("Spire.Pdf Demo",
                    new PdfFont(PdfFontFamily.Helvetica, 24), PdfBrushes.Violet, 0, 0,
                    new PdfStringFormat(PdfTextAlignment.Center));
                doc.Pages[i].Canvas.DrawRectangle(brush, new RectangleF(new PointF(0, 0), doc.Pages[i].Canvas.ClientSize));
 
            }
            doc.SaveToFile(@"WaterMark.pdf");
            System.Diagnostics.Process.Start(@".WaterMark.pdf");

If you still have any questions, please don't hesitate to contact us at any time for any thing.
Have a nice day.

Thanks and Regards.
Tina
Technical Support/Developer,
e-iceblue Support Team
User avatar
Tina.Lin
 
Posts: 152
Joined: Tue Sep 13, 2011 5:37 am


Return to Spire.PDF

Who is online

Users browsing this forum: No registered users and 0 guests