Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Mon Feb 11, 2019 5:54 pm

Experiencing the following issues attempting to place text and background image watermarks with Spire.Pdf 5.1.4.2046:
1. Text and background image watermarks do not appear on some pages in pdf document (usually pages with drawings).
2. When attempting to add background image watermarks to some pages (with drawings), the background image is not visible and the original page content is not rendered properly (only half the page is rendered).

Implementation:

Image image = Image.FromFile(@"Logo.PNG");

foreach (PdfPageBase page in document.Pages)
{
// add image
page.BackgroundImage = image;
page.BackgroudOpacity = 0.1f;

// add text
PdfTilingBrush brush = new PdfTilingBrush(new SizeF(page.Canvas.ClientSize.Width / 2, page.Canvas.ClientSize.Height / 3));
brush.Graphics.SetTransparency(0.1f);
brush.Graphics.Save();
brush.Graphics.TranslateTransform(brush.Size.Width / 2, brush.Size.Height / 2);
brush.Graphics.RotateTransform(-45);
brush.Graphics.DrawString("CONTROLLED COPY", new PdfFont(PdfFontFamily.Helvetica, 24), PdfBrushes.Red, 0, 0, new PdfStringFormat(PdfTextAlignment.Center));
brush.Graphics.Restore();
brush.Graphics.SetTransparency(0.1f);
page.Canvas.DrawRectangle(brush, new RectangleF(new PointF(0, 0), page.Canvas.ClientSize.ToSize()));
}

mscotto511
 
Posts: 13
Joined: Fri Sep 21, 2018 3:45 pm

Mon Feb 11, 2019 8:22 pm

Drawing the text on a PdfPageLayer (deprecated) renders the watermark text under the original page image however only half the original page is rendered. Without the PfPageLayer, watermark text is not rendered.

mscotto511
 
Posts: 13
Joined: Fri Sep 21, 2018 3:45 pm

Tue Feb 12, 2019 7:09 am

Hello,

Thank you for contacting us.
I simulated a PDF file and tested your case, but I didn't reproduce your issue. Please provide your input PDF file as well as your output PDF file to help us further investigate it. You could send them to us via email ([email protected]). Thanks in advance.
Besides, as for the PdfPageLayer method, it has been adjusted to the following way in our newer version.
Code: Select all
 ......
PdfLayer layer = document.Layers.AddLayer("test", PdfVisibility.On);
PdfCanvas canvas = layer.CreateGraphics(page.Canvas);
canvas.DrawString("CONTROLLED COPY", new PdfFont(PdfFontFamily.Helvetica, 24), PdfBrushes.Red, new RectangleF(new PointF(0, 0), page.Canvas.ClientSize.ToSize()), new PdfStringFormat(PdfTextAlignment.Center));
......

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1536
Joined: Wed Apr 25, 2018 3:20 am

Return to Spire.PDF