Remove PDF watermark artifacts in C++

The example deletes only artifacts with the Pagination type and Watermark subtype on the first page. Visible watermarks stored as regular page text, images, or annotations remain in the PDF. It does not scan or modify artifacts on other pages.

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.

Delete watermark artifacts

Check both Type and Subtype before deleting each matching first-page artifact. Reverse iteration avoids skipping entries after deletion.

  1. Open the input PDF with Document.
  2. Get the first page Artifacts collection.
  3. Iterate backward from ArtifactCollection::get_Count() to index 1.
  4. Check Artifact::get_Type() for Pagination and get_Subtype() for Watermark.
  5. Delete matches with ArtifactCollection::Delete().
  6. Save the result with Document::Save().
#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;


void DeleteWatermarkArtifact(System::String inputFile, System::String outputFile)
{
    auto document = MakeObject<Document>(inputFile);
    auto artifacts = document->get_Pages()->idx_get(1)->get_Artifacts();
    for (int i = artifacts->get_Count(); i >= 1; --i) {
        auto artifact = artifacts->idx_get(i);
        if (artifact->get_Type() == Artifact::ArtifactType::Pagination &&
            artifact->get_Subtype() == Artifact::ArtifactSubtype::Watermark) {
            artifacts->Delete(artifact);
        }
    }
    document->Save(outputFile);
}