Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

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

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

Thu Jun 10, 2021 1:00 pm

Hi,

I have added text watermark to my pdf document .I have attached the sample pdf which i got after adding watermark. The issue is in 1 page there are many text watermarks.How to assign 1 text watermark per page?

Bharathi_Hubfly
 
Posts: 1
Joined: Thu Jun 10, 2021 12:56 pm

Fri Jun 11, 2021 9:49 am

Hello Bharathi,

Thank you for your inquiry.
Please refer to the following code to achieve your requirement. If there is any question, please feel free to write back.
Code: Select all
            //Create a pdf document and load file from disk
            PdfDocument doc = new PdfDocument();
            doc.LoadFromFile("input.pdf");

            foreach (PdfPageBase page in doc.Pages) {             
                PdfTilingBrush brush = new PdfTilingBrush(new SizeF(page.Canvas.ClientSize.Width, page.Canvas.ClientSize.Height));
                brush.Graphics.SetTransparency(0.7f);
                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, 50), PdfBrushes.Violet, 0, 0,
                new PdfStringFormat(PdfTextAlignment.Center));
                brush.Graphics.Restore();
                brush.Graphics.SetTransparency(1);
                page.Canvas.DrawRectangle(brush, new RectangleF(new PointF(0, 0), page.Canvas.ClientSize));
            }
                   
            //Save pdf file
            doc.SaveToFile("output.pdf");
            doc.Close();


Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1643
Joined: Wed Apr 07, 2021 2:50 am

Fri Jul 02, 2021 7:13 am

Hello,

Greetings from e-iceblue.
How is your issue going? Can you give us some feedback at your convenience? Thanks in advance.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1643
Joined: Wed Apr 07, 2021 2:50 am

Return to Spire.PDF