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
- Create a
Document
object and load the PDF. - Create a document
Template
object and add it to theDocument
instance. - Place a
PageNumberingLabel
on the documentTemplate
. - 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
- Create a
Document
object. - Create a document
Template
object and add it to theDocument
instance. - Place a
PageNumberingLabel
on the documentTemplate
. - Begin the
Section
of the Document instance with different numbering styles and add pages to the sections as needed. - 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.
- DynamicPDF Generator
- .NET - DynamicPDF Generator for .NET
- Java - DynamicPDF Generator for Java
- DynamicPDF Merger
- .NET - DynamicPDF Merger for .NET
- Java - DynamicPDF Merger for Java