How to add a Watermark below the graphics and text in the existing WF PDF?
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
Note:
Starting with v16.2.0.x, if you reference Syncfusion® assemblies from the trial setup or the NuGet feed, include a license key in your projects. Refer to the link to learn about generating and registering the Syncfusion® license key in your application to use the components without a trial message.
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 Flutter PDF feature tour page to learn about its other groundbreaking features and documentation, and how to quickly get started with configuration specifications. You can also explore our Flutter PDF Flutter PDF examples to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to explore 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 forums or feedback portal. We are always happy to assist you!