Add Page Number to PDF in C++
Contents
[
Hide
]
Use PdfFileStamp for this task. The examples below retain the original C++ code and API Reference steps.
Add page numbers at coordinates
Add Page # numbering at (300, 20).
- Create PdfFileStamp.
- Bind the PDF input with Facade::BindPdf().
- Add page numbering with PdfFileStamp::AddPageNumber().
- Save the resulting PDF with PdfFileStamp::
Save().
#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 AddPageNumbersAtCoordinates(String inputFile, String outputFile)
{
auto pdfStamper = MakeObject<PdfFileStamp>();
pdfStamper->BindPdf(inputFile);
pdfStamper->AddPageNumber(u"Page #", 300, 20);
pdfStamper->Save(outputFile);
}
} // namespace Facades::Examples::PDF_FileStamp
Add page numbers default
Add Page # numbering using default positioning.
- Create PdfFileStamp.
- Bind the PDF input with Facade::BindPdf().
- Add page numbering with PdfFileStamp::AddPageNumber().
- Save the resulting PDF with PdfFileStamp::
Save().
#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 AddPageNumbersDefault(String inputFile, String outputFile)
{
auto pdfStamper = MakeObject<PdfFileStamp>();
pdfStamper->BindPdf(inputFile);
pdfStamper->AddPageNumber(u"Page #");
pdfStamper->Save(outputFile);
}
} // namespace Facades::Examples::PDF_FileStamp
Add page numbers with position and margins
Add Page # numbering at PosBottomRight with all four margins set to 10.
- Create PdfFileStamp.
- Bind the PDF input with Facade::BindPdf().
- Add page numbering with PdfFileStamp::AddPageNumber().
- Save the resulting PDF with PdfFileStamp::
Save().
#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 AddPageNumbersWithPositionAndMargins(String inputFile, String outputFile)
{
auto pdfStamper = MakeObject<PdfFileStamp>();
pdfStamper->BindPdf(inputFile);
pdfStamper->AddPageNumber(u"Page #", PdfFileStamp::PosBottomRight, 10, 10, 10, 10);
pdfStamper->Save(outputFile);
}
} // namespace Facades::Examples::PDF_FileStamp
Add page numbers with roman style
Set uppercase Roman numbering, start at 42, and add the page number at PosUpperRight.
- Create PdfFileStamp.
- Bind the PDF input with Facade::BindPdf().
- Set numbering style through PdfFileStamp using the example values.
- Set starting number through PdfFileStamp using the example values.
- Add page numbering with PdfFileStamp::AddPageNumber().
- Save the resulting PDF with PdfFileStamp::
Save().
#include <Aspose.PDF.Cpp/Facades/PdfFileStamp.h>
#include <Aspose.PDF.Cpp/NumberingStyle.h>
#include <system/string.h>
namespace Facades::Examples::PDF_FileStamp
{
using namespace System;
using namespace Aspose::Pdf;
using namespace Aspose::Pdf::Facades;
void AddPageNumbersWithRomanStyle(String inputFile, String outputFile)
{
auto pdfStamper = MakeObject<PdfFileStamp>();
pdfStamper->BindPdf(inputFile);
pdfStamper->set_NumberingStyle(NumberingStyle::NumeralsRomanUppercase);
pdfStamper->set_StartingNumber(42);
pdfStamper->AddPageNumber(u"Page #", PdfFileStamp::PosUpperRight);
pdfStamper->Save(outputFile);
}
} // namespace Facades::Examples::PDF_FileStamp