We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to add a Watermark below the graphics and text in the existing PDF?

Platform: WinForms |
Control: PDF
Tags: pdf, watermark

To add a Watermark below the graphics and text in the existing PDF, you need to create page template from the existing document and draw the template into the new document on the Watermark. You can refer to the following code example.

C#

//Loads the pdf document
PdfLoadedDocument ldoc = new PdfLoadedDocument("Bullets and Lists.pdf");
//Creats new pdf document
PdfDocument doc = new PdfDocument();
//itereate through the pages of loaded document
foreach (PdfLoadedPage lpage in ldoc.Pages)
{
//Adds new Page
PdfPage page = doc.Pages.Add();
//Create template from the loaded page
PdfTemplate template = lpage.CreateTemplate();
//Method for drawing Watermark from newly created pdf document page
DrawWatermark(page);
//Draws template of loaded page from pdf document page.
page.Graphics.DrawPdfTemplate(template, PointF.Empty);
}
//Save the document and dispose it
doc.Save("Loaded.pdf", Response, HttpReadType.Save);
doc.Close();
}
private void DrawWatermark(PdfPage page)
{
// Sets font
PdfFont bigFont = new PdfStandardFont(PdfFontFamily.Helvetica, 80f);
string s = "WaterMark";
//Saves the graphics state
PdfGraphicsState state = page.Graphics.Save();
//Measures the size of the string
 SizeF textSize = bigFont.MeasureString(s);
//The Translate transform changes the origin of the coordinate system by prepending the specified translation to the transformation matrix of this Graphics.
page.Graphics.TranslateTransform((page.Size.Width/2)-200,page.Size.Height/2+100);
//Applying rotation for watermark
page.Graphics.RotateTransform(-45);
//Sets transparency
page.Graphics.SetTransparency(0.4f);
//Draw string
page.Graphics.DrawString(s, bigFont, PdfPens.Gray, PdfBrushes.LightGray, new PointF(0, 0));
//Restores the graphics state
page.Graphics.Restore(state);
 }

Sample Link:

https://www.syncfusion.com/downloads/support/directtrac/general/EditingPdf-1995725521.zip

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile