IacDocument.SetPageNumbering Method

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.

 

Syntax

Visual Basic .NET:

Public Function SetPageNumbering(Position As Amyuni.PDFCreator.IacPageNumbersPosition, font As String, extraMarginHorz As Integer, extraMarginVert As Integer, color As Integer, startWithPage As Integer, format As String) As Boolean

C#:

public bool SetPageNumbering(Amyuni.PDFCreator.IacPageNumbersPosition Position , string font , int extraMarginHorz , int extraMarginVert , int color , int startWithPage , string format)

 

Parameters

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

It is the formatting for the page numbers. Two formatting keywords are currently supported: #page and #pages. All other keywords are output as is.

 

Return Value

Returns Value True if the call succeeded and False otherwise.

 

Remarks

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.

 

Member of Amyuni.PDFCreator.IacDocument.

Example

Sub Sample()

    ' Constants for Activation codes

    Const strLicenseTo As String = "Amyuni PDF Creator .NET Evaluation"

    Const strActivationCode As String = "07EFCDAB0100010025C3B7B351579FF94C49112EAF7368612744C7237C2F6A215A53E83A9ECCFFE54C52063CB05338BDE555773D7B1B"

 

    ' Initialize library

    ' This should be done once

    acPDFCreatorLib.Initialize()

 

    ' set license key This is needed only with licensed version

    acPDFCreatorLib.SetLicenseKey(strLicenseTo, strActivationCode)

 

    ' Create new stream object

    Dim fileRead As System.IO.Stream = System.IO.File.OpenRead("C:\temp\PDFDocument.pdf")

 

    ' Create a new PDF document

    Dim doc As New Amyuni.PDFCreator.IacDocument()

 

    ' Open stream

    Dim Password As String = ""

    doc.Open(fileRead, Password)

 

    Dim position As Amyuni.PDFCreator.IacPageNumbersPosition = Amyuni.PDFCreator.IacPageNumbersPosition.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 -"

    doc.SetPageNumbering(position, font, extraMarginHorz, extraMarginVert, color, startWithPage, format)

 

    ' Create new stream object

    Dim fileWrite As System.IO.Stream = System.IO.File.OpenWrite("C:\temp\CreatePDFDocument_resulting.pdf.pdf")

 

    ' Save stream

    doc.Save(fileWrite, Amyuni.PDFCreator.IacFileSaveOption.acFileSaveView)

 

    ' Close the streams

    fileRead.Close()

    fileWrite.Close()

 

    ' terminate library to free resources

    acPDFCreatorLib.Terminate()

 

    ' destroy objects

    doc.Dispose()

End Sub

static void Sample()

{

    // Constants for Activation codes

    const string strLicenseTo = "Amyuni PDF Creator .NET Evaluation";

    const string strActivationCode = "07EFCDAB0100010025C3B7B351579FF94C49112EAF7368612744C7237C2F6A215A53E83A9ECCFFE54C52063CB05338BDE555773D7B1B";

 

    // Initialize library

    // This should be done once

    acPDFCreatorLib.Initialize();

 

    // set license key This is needed only with licensed version

    acPDFCreatorLib.SetLicenseKey(strLicenseTo, strActivationCode);

 

    // Create new stream object

    System.IO.FileStream fileRead = new System.IO.FileStream(@"C:\temp\PDFDocument.pdf",

            System.IO.FileMode.Open,

            System.IO.FileAccess.Read,

            System.IO.FileShare.Read);

 

    // Create a new PDF document

    Amyuni.PDFCreator.IacDocument doc = new Amyuni.PDFCreator.IacDocument();

 

    // Open stream

    String password = "";

    doc.Open(fileRead, password);

 

    // Set Page numbering with Page 1 of 20 format

    Amyuni.PDFCreator.IacPageNumbersPosition position = Amyuni.PDFCreator.IacPageNumbersPosition.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 -";

    doc.SetPageNumbering(position, font, extraMarginHorz, extraMarginVert, color, startWithPage, format);

 

    // Create new stream object

    System.IO.FileStream fileWrite = new System.IO.FileStream(@"C:\temp\CreatePDFDocument_resulting.pdf",

            System.IO.FileMode.Create,

            System.IO.FileAccess.Write,

            System.IO.FileShare.Read);

 

    // Save stream

    doc.Save(fileWrite, Amyuni.PDFCreator.IacFileSaveOption.acFileSaveView);

 

    // Close the streams

    fileRead.Close();

    fileWrite.Close();

 

    // terminate library to free resources

    acPDFCreatorLib.Terminate();

 

    // destroy objects

    doc.Dispose();

}