Add Footer to PDF in C++

Use PdfFileStamp for this task. The examples below retain the original C++ code and API Reference steps.

Add formatted footer text using the overload with three margin values set to 20.

  1. Create the text content and formatting with FormattedText.
  2. Create PdfFileStamp.
  3. Bind the PDF input with Facade::BindPdf().
  4. Add the footer with PdfFileStamp::AddFooter().
  5. Save the resulting PDF with PdfFileStamp::Save().
#include <Aspose.PDF.Cpp/Facades/FormattedText.h>
#include <Aspose.PDF.Cpp/Facades/PdfFileStamp.h>
#include <system/string.h>

namespace Facades::Examples::PDF_FileStamp
{
	using namespace System;
	using namespace Aspose::Pdf;
	using namespace Aspose::Pdf::Facades;

	void AddFooterWithMargins(String inputFile, String outputFile)
	{
		auto pdfStamper = MakeObject<PdfFileStamp>();
		pdfStamper->BindPdf(inputFile);
		auto text = MakeObject<FormattedText>(u"This footer has margins on all sides.");
		pdfStamper->AddFooter(text, 20, 20, 20);
		pdfStamper->Save(outputFile);
	}
} // namespace Facades::Examples::PDF_FileStamp

Add an image footer from a file stream with a margin value of 20.

  1. Create PdfFileStamp.
  2. Bind the PDF input with Facade::BindPdf().
  3. Add the footer with PdfFileStamp::AddFooter().
  4. Save the resulting PDF with PdfFileStamp::Save().
#include <Aspose.PDF.Cpp/Facades/PdfFileStamp.h>
#include <system/io/file.h>
#include <system/io/file_stream.h>
#include <system/string.h>

namespace Facades::Examples::PDF_FileStamp
{
using namespace System;
using namespace Aspose::Pdf;
using namespace Aspose::Pdf::Facades;

void AddImageFooter(String inputFile, String imageFile, String outputFile)
{
    auto pdfStamper = MakeObject<PdfFileStamp>();
    auto imageStream = System::IO::File::OpenRead(imageFile);

    pdfStamper->BindPdf(inputFile);
    pdfStamper->AddFooter(imageStream, 20);
    pdfStamper->Save(outputFile);
}
} // namespace Facades::Examples::PDF_FileStamp

Add Sample Footer as formatted text with a margin value of 20.

  1. Create the text content and formatting with FormattedText.
  2. Create PdfFileStamp.
  3. Bind the PDF input with Facade::BindPdf().
  4. Add the footer with PdfFileStamp::AddFooter().
  5. Save the resulting PDF with PdfFileStamp::Save().
#include <Aspose.PDF.Cpp/Facades/FormattedText.h>
#include <Aspose.PDF.Cpp/Facades/PdfFileStamp.h>
#include <system/string.h>

namespace Facades::Examples::PDF_FileStamp
{
using namespace System;
using namespace Aspose::Pdf;
using namespace Aspose::Pdf::Facades;

void AddTextFooter(String inputFile, String outputFile)
{
    auto pdfStamper = MakeObject<PdfFileStamp>();
    pdfStamper->BindPdf(inputFile);
    auto text = MakeObject<FormattedText>(u"Sample Footer");
    pdfStamper->AddFooter(text, 20);
    pdfStamper->Save(outputFile);
}
} // namespace Facades::Examples::PDF_FileStamp