Add Page Stamp to PDF via C++

Create page stamp programmaticaly using Aspose.PDF for C++ Library

How to add Page Stamps to PDF Using C++ Library

In order to work with page stamps in PDF file, we’ll use Aspose.PDF for C++ API which is a feature-rich, powerful and easy to use document manipulation API for cpp platform. Open NuGet package manager, search for Aspose.PDF and install. You may also use the following command from the Package Manager Console.

Package Manager Console

PM > Install-Package Aspose.PDF.Cpp

Add Page Stamp to PDF Document C++


You need Aspose.PDF for C++ to try the code in your environment.

  1. Load the PDF with an instance of Document.
  2. Open a PDF document using Document object.
  3. Create a Page Stamp and define its properties.
  4. Add the Stamp to Page using AddStamp method

Add Page Stamp to PDF - C++


    auto document = MakeObject<Document>(_dataDir + inputFileName);

    auto bluePageStamp = MakeObject<PdfPageStamp>(_dataDir + pageStampFileName, 1);
    bluePageStamp->set_Height(800);
    bluePageStamp->set_Background(true);

    auto plumPageStamp = MakeObject<PdfPageStamp>(_dataDir + pageStampFileName, 2);
    plumPageStamp->set_Height(800);
    plumPageStamp->set_Background(true);

    for (int i = 1; i < 5; i++)
    {
        if (i % 2 == 0)
            document->get_Pages()->idx_get(i)->AddStamp(bluePageStamp);
        else
            document->get_Pages()->idx_get(i)->AddStamp(plumPageStamp);
    }

    document->Save(_dataDir + outputFileName);