I want display a watermark in back- and foreground oft the document. I used PdfTilingBrush, because the watermark has some options to be displayed. I can display the watermark for each page differently.
I don't know how to display the watermark in the foreground of the document. Above the text.
In an old version of Spire.PDF I could use PdfPageBase.DefaultLayerIndex. Now this property is obsolete and removed.
- Code: Select all
PdfPageBase pdfPageBase = pdfDocument.Pages[pageIndex];
PdfTilingBrush brush =
new PdfTilingBrush(new SizeF(pdfPageBase.Canvas.ClientSize.Width, pdfPageBase.Canvas.ClientSize.Height));
var fontColor = new PdfRGBColor(watermarkParameter.FontColor);
brush.Graphics.SetTransparency(1.0f - watermarkParameter.TransparencyPercent / 100.0f);
brush.Graphics.Save();
brush.Graphics.TranslateTransform(GetWight(watermarkParameter.Position, brush.Size.Width), GetHeight(watermarkParameter.Position, brush.Size.Height));
brush.Graphics.RotateTransform(watermarkParameter.Rotation);
brush.Graphics.DrawString(watermarkParameter.Text,
pdfFont, new PdfSolidBrush(fontColor), 0, 0,
new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle));
brush.Graphics.Restore();
switch (watermarkParameter.DocumentLevel)
{
case DocumentLevel.Background:
pdfPageBase.Canvas.DrawRectangle(brush, new RectangleF(new PointF(0, 0), pdfPageBase.Canvas.ClientSize));
break;
case DocumentLevel.Foreground:
//... draw PdfTilingBrush in foreground
break;
default:
throw new NotImplementedException($"Document level '{watermarkParameter.DocumentLevel}' is not implemented.");
}
Spire.PDF 9.8.5.1040
C#
Windows
.Net Framework 4.8