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.