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.
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.
- Open a PDF document using Document object.
- Create a Stamp and define its properties.
- Add the Stamp to Page using AddStamp method.
- Save the PDF file.
Add a Header to PDF Document - C++
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);