Examples

Add Page Numbers to PDF in COM/ActiveX

Page numbers can be added to an existing PDF document or to a PDF document created from scratch merging and generating functionality of DynamicPDF Core Suite. The steps and sample codes to add page numbers to PDF are given below.

How to Add Page Numbers to Existing PDF

The following steps and sample code illustrate adding page numbering labels to an existing PDF document. The PageNumberingLabel page element automatically adds page numbers to a PDF.

Steps for Adding Page Numbers to an Existing PDF Document

  1. Create a Document object and load the PDF.
  2. Create a document Template object and add it to the Document instance.
  3. Place a PageNumberingLabel on the document Template.
  4. Output the Document instance to the browser.

Sample Code - ASP

Dim MyDocument
Set MyDocument = Server.CreateObject("DynamicPDF.Document")
MyDocument.LoadPdf Server.MapPath("doc-a.pdf")

Dim DocTemplate
Set DocTemplate = MyDocument.SetTemplate()
DocTemplate.AddPageNumberingLabel "Page %%CP(A)%% OF %%TP(A)%%", 50, 40, 220, 40

MyDocument.DrawToWeb

How to Create PDF with Page Numbers

The following steps and sample code illustrate adding page numbers to a PDF document. The PageNumberingLabel page element automatically adds page numbers to a PDF.

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 document Template.
  4. Begin the Section of the Document instance with different numbering styles and add pages to the sections as needed.
  5. Output the Document instance to the browser.

Sample Code - ASP

Dim MyDocument 
Set MyDocument = Server.CreateObject( "DynamicPDF.Document" ) 
Dim DocTemplate
Set DocTemplate = MyDocument.SetTemplate()
    
DocTemplate.AddPageNumberingLabel "Page %%CP(A)%% OF %%TP(A)%%", 50, 40, 220, 40
Dim MyPage
Set MyPage = MyDocument.AddPage()
	
MyPage.AddPageNumberingLabel "Page %%CP(i)%% OF %%TP(i)%%", 300, 40, 220, 40

MyDocument.AddPage()
MyDocument.AddPage()
MyDocument.AddPage()
MyDocument.AddPage()
MyDocument.AddPage()
MyDocument.AddPage()
MyDocument.AddPage()
MyDocument.AddPage()
MyDocument.AddPage()
MyDocument.AddPage()
MyDocument.AddPage()
MyDocument.AddPage()
MyDocument.AddPage()
MyDocument.AddPage()
MyDocument.AddPage()
MyDocument.AddPage()
MyDocument.AddPage()
MyDocument.AddPage()
MyDocument.AddPage()
MyDocument.AddPage()
MyDocument.AddPage()
MyDocument.AddPage()
MyDocument.AddPage()
MyDocument.AddPage()
MyDocument.AddPage()
MyDocument.AddPage()
MyDocument.AddPage()

MyDocument.DrawToWeb  

Getting Started

DynamicPDF Core Suite Information

More information can be found at the following web pages.

Available on Other Platforms

The DynamicPDF Core Suite is also available for .NET and Java 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 18 Years)
  • Free Evaluation
  • .NET Core Support (Most Products)
  • Flexible Licensing

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