PDF .NET Library Logo

Numbering pages in PDF documents

The following code sample creates a PDF document with numerous pages and assigns page numbers in varying styles.

C# sample:


PDFCreationOptions options = new PDFCreationOptions();

options.Viewer.PageMode = PageMode.UseThumbs;

PDFDocument MyPDF = new PDFDocument("AutoNumbering.pdf", options);

//Add Page Numbering range for the intro pages  [Roman Number]

PageNumberingRange pnrintro = MyPDF.AddNumberingRange(0, 1); ;

pnrintro.NumberingStyle = NumberingStyle.LowerCaseRoman;

pnrintro.FontFace = "Arial";

pnrintro.FontSize = 12;

//Add intro pages

MyPDF.CurrentPage.Body.SetActiveFont("Helvetica", PDFFontStyles.Regular, 14);

MyPDF.CurrentPage.Body.AddText("Introduction\r\n");

MyPDF.CurrentPage.Body.AddImage(new PDFImage("..\\resources\\images\\merlin.gif"));

MyPDF.CurrentPage.Body.SetActiveFont("Helvetica", PDFFontStyles.Regular, 12, Charset.Unicode, Color.Navy);

MyPDF.CurrentPage.Body.AddText("This sample shows how to add page numbers to pdf documents.\r\n" +

"Page numbering for first 2 page is Roman style.\r\n");

 //read more text from file.

MyPDF.CurrentPage.Body.SetActiveFont("Helvetica", PDFFontStyles.Regular, 12, Charset.Unicode, Color.Black);

MyPDF.CurrentPage.Body.AddText(System.IO.File.ReadAllText("short-lorem.txt"));

if (!MyPDF.Save())

Console.WriteLine(MyPDF.Error);

doc.Save();

Back to PDF Code Library