In this example, we will explore how to insert Header and Footer in DOCX using C++. Header and Footer are added on top and bottom of Word document pages respectively. They hold key and useful information that has purpose to repeat on every page including Date Time, Author Information, Page number etc. In order to use C++ to add Header and Footer information in Word Document, very simple API interface is used.
Steps to Add Header and Footer in DOCX using C++
- Download Aspose.Words.Cpp using NuGet package Manager
- Include reference to Aspose::Words namespace
- Instantiate Document Class object to load the document for adding Header/Footer
- Use DocumentBuilder Class to manage Header/Footer settings inside DOCX
- Set different Header/Footer properties
- Save the DOCX with Header/Footer information in C++ by using Save method
You can use the following example to load any existing MS Word file or create a new one to add Header and Footer information using C++. It shall take only few API calls in C++ to load the document and enable header and footer settings in DOCX.
Code to Add Header and Footer in DOCX using C++
In previous example, we looked in to How to Create Table in DOCX using C++. Whereas in this example, we have focused on Word document header and footer processing in C++.