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 by using the Merger and Generator products respectively. The steps and sample codes to add page numbers to PDF is given below for both the products.

How to Add Page Numbers to an Existing PDF

Below are steps and sample code on how to add page numbering labels to an existing PDF document. The PageNumberingLabel page element can be used to automatically add 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.
  3. Place a PageNumberingLabel on the document Template.
  4. Output the Document 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

Below are steps and sample code on how to add page numbers to a PDF document you are creating from scratch. The PageNumberingLabel page element can be used to automatically add 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.
  3. Place a PageNumberingLabel on the document Template.
  4. Begin the Section of the Document with different numbering styles and add pages to the sections as needed.
  5. Output the Document 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 Generator and Merger Information

More information can be found here:

Available in Other Platforms

Generator and Merger PDF Libraries are 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!