Add Header to PDF via C++

Add Header to PDF File using C++ Library.

Add Headers to PDF Document Using C++

In order to add Header in PDF, 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 Header to PDF with C++


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

  1. Open a PDF document using Document object.
  2. Create a Stamp and define its properties.
  3. Add the Stamp to Page using AddStamp method.
  4. Save the PDF file.

Add a Header to PDF Document - C++

This sample code shows how to add Header to PDF


    String _dataDir("C:\\Samples\\");
    String inputFileName("AddTextStamp.pdf");
    String outputFileName("AddTextStamp_out.pdf");
    auto document = MakeObject<Document>(_dataDir + inputFileName);

    auto textStamp =MakeObject<TextStamp>(u"Sample Stamp");

    textStamp->set_Background(true);

    textStamp->set_XIndent(100);
    textStamp->set_YIndent(100);

    textStamp->set_Rotate(Rotation::on90);
    textStamp->get_TextState()->set_Font(FontRepository::FindFont(u"Arial"));
    textStamp->get_TextState()->set_FontSize(14.0F);
    textStamp->get_TextState()->set_FontStyle(FontStyles::Bold);
    textStamp->get_TextState()->set_FontStyle(FontStyles::Italic);
    textStamp->get_TextState()->set_ForegroundColor(Color::get_Green());

    document->get_Pages()->idx_get(1)->AddStamp(textStamp);
    document->Save(_dataDir + outputFileName);