This sample shows how to remove XObjects (often used for watermarks and backgrounds) from PDF document pages.

Use PdfPage.XObjects.Remove or PdfPage.XObjects.RemoveAt method to remove specified XObject from a page or PdfPage.XObjects.Clear method to remove all such objects.

Please note that XObjects are not always watermarks or backgrounds. Sometimes such objects are used for logos and other repeatable items.

C#
using System.Diagnostics;

namespace BitMiracle.Docotic.Pdf.Samples
{
    public static class RemoveXObjectsWatermarks
    {
        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.

            string pathToFile = "RemoveXObjectsWatermarks.pdf";

            using (PdfDocument pdf = new PdfDocument(@"Sample Data\DocumentWithWatermark.pdf"))
            {
                foreach (PdfPage page in pdf.Pages)
                {
                    // remove first XObject (in this case it's a watermark)
                    page.XObjects.RemoveAt(0);
                }

                pdf.Save(pathToFile);
            }

            Process.Start(pathToFile);
        }
    }
}
VB
Imports System.Diagnostics
Imports System.Drawing
Imports System.IO

Imports BitMiracle.Docotic.Pdf

Namespace BitMiracle.Docotic.Pdf.Samples
    Public NotInheritable Class RemoveXObjectsWatermarks
        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 pathToFile As String = "RemoveXObjectsWatermarks.pdf"

            Using pdf As New PdfDocument("Sample Data\DocumentWithWatermark.pdf")
                For Each page As PdfPage In pdf.Pages
                    ' remove first XObject (in this case it's a watermark)
                    page.XObjects.RemoveAt(0)
                Next

                pdf.Save(pathToFile)
            End Using

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