Extract PDF watermark details in C++

This example inspects page 1 only. It prints properties of matching watermark artifacts rather than exporting watermark images or creating a separate PDF.

The input PDF must contain at least one page. Configure the Aspose.PDF for C++ SDK and use a writable output path for examples that save a PDF.

Read watermark text and bounds

Print text and bounds for matching first-page pagination artifacts. The filter selects only the Watermark subtype.

  1. Open the input PDF with Document.
  2. Iterate through Page::get_Artifacts() on the first page.
  3. Filter using Artifact::get_Type() and get_Subtype().
  4. Print Artifact::get_Text() and get_Rectangle().
#include <Aspose.PDF.Cpp/Document.h>
#include <Aspose.PDF.Cpp/Page.h>
#include <Aspose.PDF.Cpp/PageCollection.h>
#include <Aspose.PDF.Cpp/Artifacts/Artifact.h>
#include <Aspose.PDF.Cpp/Artifacts/ArtifactCollection.h>

using namespace System;
using namespace Aspose::Pdf;

#include <iostream>
#include <Aspose.PDF.Cpp/Rectangle.h>

void ExtractWatermarkFromPdf(System::String inputFile)
{
    auto document = MakeObject<Document>(inputFile);
    for (auto& artifact : document->get_Pages()->idx_get(1)->get_Artifacts()) {
        if (artifact->get_Type() == Artifact::ArtifactType::Pagination &&
            artifact->get_Subtype() == Artifact::ArtifactSubtype::Watermark) {
            std::cout << artifact->get_Text() << " " << artifact->get_Rectangle()->ToString() << std::endl;
        }
    }
}