Remove PDF header and footer artifacts in C++

The example processes page 1 only and removes Pagination artifacts with the Header or Footer subtype. Text, images, or annotations that merely look like a header or footer are not selected by this filter.

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.

Remove both header and footer pagination artifacts from the first page. Other artifact types and subtypes are left in the collection.

  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 Header or Footer.
  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 DeleteHeaderFooterArtifact(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::Header
                || artifact->get_Subtype() == Artifact::ArtifactSubtype::Footer)) {
            artifacts->Delete(artifact);
        }
    }
    document->Save(outputFile);
}