Articles in this section
Category / Section

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

1 min read

To add a Watermark below the graphics and text in the existing in .NET 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


Conclusion


I hope you enjoyed learning about how to add a Watermark below the graphics and text in the existing WF PDF.

You can refer to our .NET PDF feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our .NET PDF example to understand how to create and manipulate data in the .NET PDF. 

For current customers, you can check out our Document processing libraries from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied