Examples

Adding Page Numbers to a PDF

Add page numbers to a new or existing PDF using DynamicPDF Core Suite for .NET. The following C# examples show you how.

Watch the Video

How to Create PDF with Page Numbers

The following steps and C# sample code illustrate how to add page numbers to a PDF document created from scratch.


Steps for Adding Page Numbers to a PDF document


  1. Create a Document object.
  2. Create a document Template object and add it to the Document instance.
  3. Place a PageNumberingLabel on the Template instance.
  4. Begin a Section for the Document instance.
  5. Add nine pages, note the different numbering styles for the first section and then the appendix (pages 8 and 9).
  6. Add the Draw method to output the PDF document.

Sample Code - C#


Document document = new Document();    
Template documentTemplate = new Template();
document.Template = documentTemplate;
    
documentTemplate.Elements.Add(new PageNumberingLabel("%%PR%%%%SP%% of %%ST%%", 0, 680, 512, 12, Font.Helvetica, 12, TextAlign.Center));
    
document.Sections.Begin(NumberingStyle.RomanLowerCase);
document.Pages.Add(new Page()); //Page 1
document.Pages.Add(new Page()); //Page 2
document.Pages.Add(new Page()); //Page 3
    
document.Sections.Begin( NumberingStyle.Numeric );
document.Pages.Add(new Page()); //Page 4
document.Pages.Add(new Page()); //page 5
document.Pages.Add(new Page()); //page 6
document.Pages.Add(new Page()); //page 7
    
document.Sections.Begin( NumberingStyle.RomanLowerCase, "Appendix A - " );
document.Pages.Add(new Page()); //page 8
document.Pages.Add(new Page()); //page 9
    
document.Draw("output.pdf");

A PDF with page numbering.

How to Add Page Numbers to Existing PDF

The following steps and C# sample code illustrate how to add page numbering labels to an existing PDF document using the PageNumberingLabel page element to automatically add page numbers to a PDF.


Steps for Adding Page Numbers to an Existing PDF Document


  1. Create a MergeDocument object with the source PDF.
  2. Create a document Template object and add it to the Document instance.
  3. Place a PageNumberingLabel on the document Template instance.
  4. Add the Draw method to save the merged PDF.

Sample Code - C#


MergeDocument document = new MergeDocument("doc-a.pdf");
Template template = new Template();
PageNumberingLabel pageLabels = new PageNumberingLabel("%%CP%% of %%TP%%", 0, 0, 200, 20);
template.Elements.Add(pageLabels);
document.Template = template;
document.Draw("output.pdf");

GitHub Project

An example project is available on GitHub (examples.dynamicpdf-core-suite-dotnet-core). Examples are provided in C# and VB.NET. Clone or view the example project at GitHub. This specific example discussed on this page are all contained in following classes on GitHub


Clone or View Example Project on GitHub

Getting Started

Get started easily by installing DynamicPDF Core Suite for .NET through NuGet or manually. Then, refer to the documentation for more information on using and purchasing the product.


NuGet Package


The easiest way to install DynamicPDF Core Suite is by obtaining the NuGet package using Visual Studio's Package Manager. You can also obtain the NuGet package by downloading it directly. Refer to the installation documentation for more information.

NuGet Package ID: ceTe.DynamicPDF.CoreSuite.NET

DynamicPDF Core Suite Information


DynamicPDF Core Suite for .NET combines creating, merging, and visual report creation into one powerful product for creating PDF documents. It is ideal for anyone who needs to generate PDF documents or reports or work with existing PDFs in their applications. With a free Evaluation Edition to try and with flexible and royalty-free licensing options, why not start using DynamicPDF Core Suite for .NET today!



More Information on Page Numbers

Available on Other Platforms

DynamicPDF Core Suite is also available for the Java and COM/ActiveX platforms. Refer to the respective product pages for more details.


Why Choose DynamicPDF?

  • Transparent Pricing
  • Lots of Features
  • Easy to Use
  • Great Support
  • Efficient Performance
  • Product Maturity (Over 22 Years)
  • Free Evaluation
  • .NET Core Support (Most Products)
  • Flexible Licensing

We’re Not The Only Ones That Think We’re Great!