Watermarks

Docotic.Pdf Library Help > Samples > Graphics > Watermarks

This sample shows how to create and use watermarks in Docotic.Pdf library.

Please use PdfDocument.AddWatermark() method to add a watermark to your document. After watermark is added to your document you can access watermark canvas using PdfWatermark.Canvas property.

You can apply a watermark to a page using PdfPage.Watermark property. A watermark can be applied to any number of pages.

CopyC#
using System.Diagnostics;

namespace BitMiracle.Docotic.Pdf.Samples
{
    public static class Watermarks
    {
        public static void Main()
        {
            // NOTE: 
            // When used in trial mode, the library imposes some restrictions.
            // Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx
            // for more information.

            PdfDocument pdf = new PdfDocument();
            pdf.AddPage();

            PdfWatermark watermark = pdf.AddWatermark();
            PdfCanvas watermarkCanvas = watermark.Canvas;
            watermarkCanvas.TextAngle = -45;
            watermarkCanvas.FontSize = 36;
            watermarkCanvas.DrawString(100, 100, "This text is a part of the watermark");

            for (int i = 0; i < pdf.PageCount; ++i)
                pdf.Pages[i].Watermark = watermark;

            string pathToFile = "Watermarks.pdf";
            pdf.Save(pathToFile);
            pdf.Dispose();

            Process.Start(pathToFile);
        }
    }
}
CopyVB.NET
Imports System.Diagnostics

Imports BitMiracle.Docotic.Pdf

Namespace BitMiracle.Docotic.Pdf.Samples
    Public NotInheritable Class Watermarks
        Private Sub New()
        End Sub
        Public Shared Sub Main()
            ' NOTE: 
            ' When used in trial mode, the library imposes some restrictions.
            ' Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx
            ' for more information.


            Dim pdf As New PdfDocument()
            pdf.AddPage()

            Dim watermark As PdfWatermark = pdf.AddWatermark()
            Dim watermarkCanvas As PdfCanvas = watermark.Canvas
            watermarkCanvas.TextAngle = -45
            watermarkCanvas.FontSize = 36
            watermarkCanvas.DrawString(100, 100, "This text is a part of the watermark")

            For i As Integer = 0 To pdf.PageCount - 1
                pdf.Pages(i).Watermark = watermark
            Next

            Dim pathToFile As String = "Watermarks.pdf"
            pdf.Save(pathToFile)
            pdf.Dispose()

            Process.Start(pathToFile)
        End Sub
    End Class
End Namespace