Check if the pdf file has a watermark

Hello,

I am trying to check if a pdf has a watermark or not. I have tried several suggestions from Chatgpt without success. Can you help me? Attached is a sample document.

watermarked.pdf (33.2 KB)

Regards

@profiler

To check if a PDF file has a watermark, you can utilize the Aspose.PDF library to iterate through the artifacts on each page of the document. Watermarks are typically classified as artifacts of a specific subtype. Below is a sample code snippet that demonstrates how to count the number of watermarks in a PDF document:

using System;
using Aspose.Pdf;

namespace Aspose.Pdf.Examples
{
    public class CheckWatermark
    {
        public static void Run()
        {
            // Load the PDF document
            Document pdfDocument = new Document("path/to/your/watermarked.pdf");
            int watermarkCount = 0;

            // Iterate through the artifacts on the first page
            foreach (Artifact artifact in pdfDocument.Pages[1].Artifacts)
            {
                // Check if the artifact is a watermark
                if (artifact.Subtype == Artifact.ArtifactSubtype.Watermark)
                {
                    watermarkCount++;
                }
            }

            Console.WriteLine("The document contains " + watermarkCount + " watermark(s).");
        }
    }
}

In this code:

  • Replace "path/to/your/watermarked.pdf" with the actual path to your PDF file.
  • The code checks the first page of the document for artifacts and counts how many of them are classified as watermarks.

This approach will help you determine if your PDF contains any watermarks. If you need further assistance, feel free to ask!

Sources:
[1]: CountingArtifacts.cs
[2]: GetWatermark.cs

I’ve already tried this with a few files. It doesn’t work.

@profiler
aboutWatermark.png (194.3 KB)

By watermark do you mean what is outlined in the frame on the attached screenshot?
There are no special objects of the watermark type in the PDF specification. As you can see on the attached screenshot, Acrobat considers it an image.
That is, in general, the task of searching for watermarks is not entirely correct.
You can try to search for images knowing some of their parameters.