The SetPageNumbering method enables the developer to automatically number all pages of a document. Page numbers are automatically adjusted when pages are added, removed or moved within the document.
Sub SetPageNumbering(Position As acPageNumbersPostions, Font As String, ExtraMarginHorz As Long, ExtraMarginVert As Long, Color As Long, StartWithPage As Long, Format As String)
void SetPageNumbering(acPageNumbersPositions Position, string Font, int ExtraMarginHorz, int ExtraMarginVert, int Color, int StartWithPage, string Format)
HRESULT SetPageNumbering(acPageNumbersPositions Position, BSTR Font, long ExtraMarginHorz, long ExtraMarginVert, long Color, long StartWithPage, BSTR Format)
Position
This parameter takes one of seven values that describe where to position the page numbers. Possible values are:
Name |
Value |
---|---|
acNoPageNumbers |
0 |
acTopLeft |
1 |
acTopCenter |
2 |
acTopRight |
3 |
acBottomLeft |
4 |
acBottomCenter |
5 |
acBottomRight |
6 |
Font
String in the format "FontName, Size, Bold, Italic, Underline". This is the font used to draw the page numbers.
ExtraMarginHorz
Horizontal left or right margin in Twips.
ExtraMarginVert
Vertical top or bottom margin in Twips.
Color
RGB color used to draw the page numbers.
StartWithPage
Page number where to start adding page numbers. If this value is positive, page numbers will start with 1. If this value is negative, page numbers will start with the actual page number.
Format
This specifies the formatting for the page numbers. Two formatting keywords are currently supported: #page and #pages. All other keywords are output as is.
Return Value
This method returns 0 upon success. It returns an exception with one of the following exception codes upon failure:
Exception |
Description |
---|---|
E_NOTIMPL |
The license key that is provided is a read-only license key that does not allow modifying the document. |
E_ACCESSDENIED |
The document security settings do not allow the user to modify the document. |
E_OUTOFMEMORY |
Unable to allocate memory needed to execute this method. |
Once the document is saved in View Only mode, page numbers become static text part of the main document and cannot be modified anymore using this method. To be able to modify the page numbers after saving and loading a document, the document needs to be saved in "Design" or "View and Design" mode.
Sub Sample()
' Constants for Activation codes
Const strLicenseTo As String = "Amyuni PDF Creator Evaluation"
Const strActivationCode As String = "07EFCDAB010001004282943F2AF19A88F332D9E781E40460727DF8A42847A1BDE06DB61C71E94E2D90424BF8762385335F9D6884E9FC"
' Initializing PDFCreativeX Object
Dim pdf As ACPDFCREACTIVEX.PDFCreactiveX = New ACPDFCREACTIVEX.PDFCreactiveX()
' Set license key
pdf.SetLicenseKey(strLicenseTo, strActivationCode)
' Open an existent PDF filw
Dim fileName As String = "c:\temp\PDFdocument.pdf"
Dim password As String = ""
pdf.Open(fileName, password)
' Set Page numbering with Page 1 of 20 format
Dim position As ACPDFCREACTIVEX.acPageNumbersPositions = ACPDFCREACTIVEX.acPageNumbersPositions.acPageNumbersPositionBottomCenter
Dim font As String = "Verdana,11,700,0,0"
Dim extraMarginHorz As Integer = 0
Dim extraMarginVert As Integer = 0
Dim color As Integer = &H0
Dim startWithPage As Integer = 1
Dim format As String = "- Page #page of #pages -"
pdf.SetPageNumbering(position, font, extraMarginHorz, extraMarginVert, color, startWithPage, format)
' Save PDF
pdf.Save("c:\temp\CreatePDFDocument_resulting.pdf", ACPDFCREACTIVEX.FileSaveOptionConstants.acFileSaveView)
End Sub
static void Sample()
{
// Constants for Activation codes
const string strLicenseTo = "Amyuni PDF Creator Evaluation";
const string strActivationCode = "07EFCDAB010001004282943F2AF19A88F332D9E781E40460727DF8A42847A1BDE06DB61C71E94E2D90424BF8762385335F9D6884E9FC";
// Initializing PDFCreativeX Object
ACPDFCREACTIVEX.PDFCreactiveX pdf = new ACPDFCREACTIVEX.PDFCreactiveX();
// Set license key
pdf.SetLicenseKey(strLicenseTo, strActivationCode);
// Open an existent PDF file
string fileName = @"c:\temp\PDFdocument.pdf";
string password = "";
pdf.Open(fileName, password);
// Set Page numbering with Page 1 of 20 format
ACPDFCREACTIVEX.acPageNumbersPositions position = ACPDFCREACTIVEX.acPageNumbersPositions.acPageNumbersPositionBottomCenter;
string font = "Verdana,11,700,0,0";
int extraMarginHorz = 0;
int extraMarginVert = 0;
int color = 0x0;
int startWithPage = 1;
string format = "- Page #page of #pages -";
pdf.SetPageNumbering(position, font, extraMarginHorz, extraMarginVert, color, startWithPage, format);
// Save PDF
pdf.Save(@"c:\temp\CreatePDFDocument_resulting.pdf", ACPDFCREACTIVEX.FileSaveOptionConstants.acFileSaveView);
}
#include <iostream>
#import "c:\users\amyuni\pdfcreactivex.dll" no_namespace
using namespace std;
int main()
{
// Constants for Activation codes
bstr_t strLicenseTo = "Amyuni PDF Creator Evaluation";
bstr_t strActivationCode = "07EFCDAB010001004282943F2AF19A88F332D9E781E40460727DF8A42847A1BDE06DB61C71E94E2D90424BF8762385335F9D6884E9FC";
// Initialize the COM subsystem
CoInitialize(0);
// IPDFCreactiveXPtr is a smart pointer type defined in pdfcreactivex.tlh,
// the type library header file generated by the #import instruction above
IPDFCreactiveXPtr pdf;
// Create the PDFCreactiveX instance
pdf.CreateInstance(__uuidof(PDFCreactiveX));
// set license key
pdf->SetLicenseKey(_bstr_t(strLicenseTo), _bstr_t(strActivationCode));
// Open an existent PDF file
bstr_t fileName = "c:\\temp\\PDFdocument.pdf";
bstr_t password = "";
pdf->Open(fileName, password);
// Set Page numbering with Page 1 of 20 format
acPageNumbersPositions position = acPageNumbersPositionBottomCenter;
bstr_t font = "Verdana,11,700,0,0";
long extraMarginHorz = 0;
long extraMarginVert = 0;
long color = 0x0;
long startWithPage = 1;
bstr_t format = "- Page #page of #pages -";
pdf->SetPageNumbering(position, font, extraMarginHorz, extraMarginVert, color, startWithPage, format);
// Save PDF
pdf->Save("c:\\temp\\CreatePDFDocument_resulting.pdf", acFileSaveView);
return 0;
}