Skip to main content

Add Page Number to PDF - Pagination API

PDF4me Add Page Number to PDF enables you to add customizable page numbers to PDF documents with control over position, format, and styling. This API service processes PDF files and adds page numbers using format placeholders where # represents the current page number and {1} represents the total number of pages. The API receives PDF content through REST API calls, utilizing Base64 encoding for secure transmission. This solution is ideal for document organization, legal documentation, academic papers, and enterprise PDF workflows.

Authenticating Your API Request

To access the PDF4me REST API, every request must include proper authentication credentials. Authentication ensures secure communication and validates your identity as an authorized user of the REST API.

Key Features

  • Flexible Formatting: Choose from multiple page number formats using # for current page and {1} for total pages (e.g., "# of 1", "Page #")
  • Precise Positioning: Control horizontal and vertical alignment with pixel-perfect accuracy
  • Custom Styling: Adjust font size, bold, italic, and other text formatting options
  • Margin Control: Set precise margins in millimeters for optimal placement
  • Skip First Page: Option to exclude page numbers from the first page
  • Professional Results: Create consistent, professional page numbering across documents

REST API Endpoint

The PDF4me REST API uses standard HTTP methods to interact with resources. All page number addition operations are performed through a single endpoint:

  • Method: POST
  • Endpoint: /api/v2/AddPageNumber

REST API Parameters

Complete list of parameters for the Add Page Number to PDF REST API. Parameters are organized by category for better understanding and implementation.

Important: Parameters marked with an asterisk (*) are required and must be provided for the API to function correctly.

Required Parameters

ParameterTypeDescriptionExample
docName*StringOutput PDF file name with .pdf extensionoutput.pdf
docContent*Base64PDF file content encoded in Base64JVBERi...
pageNumberFormat*StringPage number format. Use # for current page number, {1} for total pages. Examples: "# of 1", "Page #", "# / 1"# of {1}
alignX*StringHorizontal alignment: left, center, or rightright
alignY*StringVertical alignment: top, middle, or bottombottom

Optional Parameters

ParameterTypeDescriptionExample
marginXinMMIntegerHorizontal margin from edge in millimeters (0-100)2
marginYinMMIntegerVertical margin from edge in millimeters (0-100)2
fontSizeIntegerFont size for page numbers (8-72)12
isBoldBooleanMake page numbers bold (true) or regular (false)true
isItalicBooleanMake page numbers italic (true) or normal (false)false
skipFirstPageBooleanSkip numbering on first page (true) or include it (false)false
asyncBooleanEnable asynchronous processing. When true, the API returns a 202 status and provides a polling URL in the Location headertrue

Page Number Format Placeholders

The pageNumberFormat parameter uses the following placeholders:

  • # - Replaced with the current page number (1, 2, 3, etc.)
  • {1} - Replaced with the total number of pages

Format Examples:

  • "# of {1}" → Displays "1 of 10", "2 of 10", "3 of 10", etc.
  • "Page #" → Displays "Page 1", "Page 2", "Page 3", etc.
  • "# / {1}" → Displays "1 / 10", "2 / 10", "3 / 10", etc.
  • "- # -" → Displays "- 1 -", "- 2 -", "- 3 -", etc.
  • "[#/{1}]" → Displays "[1/10]", "[2/10]", "[3/10]", etc.
  • "(#)" → Displays "(1)", "(2)", "(3)", etc.
  • "#" → Displays just the page number: "1", "2", "3", etc.

Output

The PDF4me Add Page Number to PDF REST API returns different responses based on the processing mode. The API returns the PDF as a Base64-encoded string in JSON format, not as binary data.

Synchronous Processing (Default)

When async is not set or set to false, the API processes the request immediately:

Status Code: 200 OK

Content-Type: application/json

Response Body:

{
"docName": "output.pdf",
"docContent": "JVBERi0xLjQKJeLjz9MKMSAwIG9iago8PAovVHlwZSAvQ2F0YWxvZwovUGFnZXMgMiAwIFIKPj4KZW5kb2JqCjIgMCBvYmoKPDwKL1R5cGUgL1BhZ2VzCi9LaWRzIFszIDAgUl0KL0NvdW50IDEKPD4KZW5kb2JqCjMgMCBvYmoKPDwKL1R5cGUgL1BhZ2UKL1BhcmVudCAyIDAgUgovTWVkaWFCb3ggWzAgMCA2MTIgNzkyXQovUmVzb3VyY2VzIDw8Ci9Gb250IDw8Ci9GMSA0IDAgUgo+Pgo+PgovQ29udGVudHMgNSAwIFIKPj4KZW5kb2JqCjQgMCBvYmoKPDwKL1R5cGUgL0ZvbnQKL1N1YnR5cGUgL1R5cGUxCi9CYXNlRm9udCAvSGVsdmV0aWNhCj4+CmVuZG9iago1IDAgb2JqCjw8Ci9MZW5ndGggNDQKPj4Kc3RyZWFtCkJUCi9GMSAxMiBUZgoxMDAgNzAwIFRkCihIZWxsbyBXb3JsZCkgVGoKRVQKZW5kc3RyZWFtCmVuZG9iagp4cmVmCjAgNgowMDAwMDAwMDAwIDY1NTM1IGYgCjAwMDAwMDAwMDkgMDAwMDAgbiAKMDAwMDAwMDA1NCAwMDAwMCBuIAowMDAwMDAwMTAxIDAwMDAwIG4gCjAwMDAwMDAxNzAgMDAwMDAgbiAKMDAwMDAwMDI0NCAwMDAwMCBuIAp0cmFpbGVyCjw8Ci9TaXplIDYKL1Jvb3QgMSAwIFIKPj4Kc3RhcnR4cmVmCjM0MQolJUVPRg=="
}

Response Fields:

  • docName (string): The output PDF file name
  • docContent (string): The PDF file with page numbers added, encoded as Base64 string

How to Use:

  1. Extract the docContent field from the JSON response
  2. Decode the Base64 string to get the binary PDF data
  3. Save or process the PDF file as needed

Example (JavaScript):

const response = await fetch(url, options);
const data = await response.json();
const pdfBytes = atob(data.docContent); // Decode Base64
// Save or process pdfBytes

Request Example

Content-Type: application/json
Authorization: Basic YOUR_BASE64_ENCODED_API_KEY

Note:

  • Get your API key from the PDF4me Dashboard
  • The API key must be Base64 encoded and prefixed with "Basic " in the Authorization header
  • Example: If your API key is abc123, encode it to Base64 and use Authorization: Basic YWJjMTIz

Payload

Basic Example (Required Fields Only):

{
"docName": "output.pdf",
"docContent": "JVBERi0xLjQKJeLjz9MKMSAwIG9iago8PAovVHlwZSAvQ2F0YWxvZwovUGFnZXMgMiAwIFIKPj4KZW5kb2JqCjIgMCBvYmoKPDwKL1R5cGUgL1BhZ2VzCi9LaWRzIFszIDAgUl0KL0NvdW50IDEKPD4KZW5kb2JqCjMgMCBvYmoKPDwKL1R5cGUgL1BhZ2UKL1BhcmVudCAyIDAgUgovTWVkaWFCb3ggWzAgMCA2MTIgNzkyXQovUmVzb3VyY2VzIDw8Ci9Gb250IDw8Ci9GMSA0IDAgUgo+Pgo+PgovQ29udGVudHMgNSAwIFIKPj4KZW5kb2JqCjQgMCBvYmoKPDwKL1R5cGUgL0ZvbnQKL1N1YnR5cGUgL1R5cGUxCi9CYXNlRm9udCAvSGVsdmV0aWNhCj4+CmVuZ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wMDAwMDAwMDkgMDAwMDAgbiAKMDAwMDAwMDA1NCAwMDAwMCBuIAowMDAwMDAwMTAxIDAwMDAwIG4gCjAwMDAwMDAxNzAgMDAwMDAgbiAKMDAwMDAwMDI0NCAwMDAwMCBuIAp0cmFpbGVyCjw8Ci9TaXplIDYKL1Jvb3QgMSAwIFIKPj4Kc3RhcnR4cmVmCjM0MQolJUVPRg==",
"pageNumberFormat": "# of {1}",
"alignX": "right",
"alignY": "bottom",
"marginXinMM": 2,
"marginYinMM": 2,
"fontSize": 12,
"isBold": true,
"isItalic": false,
"skipFirstPage": false,
"async": true
}

Code Samples

The PDF4me Add Page Number to PDF REST API provides code samples in multiple programming languages. Choose the language that best fits your development environment:

C# (CSharp) Sample

Complete C# implementation for adding page numbers to PDF:

Page Number Features

Formatting Options

  • Multiple Formats: Support for various numbering styles and patterns
  • Flexible Positioning: Precise control over page number placement
  • Custom Styling: Full control over font appearance and formatting
  • First Page Control: Option to exclude cover pages from numbering

Document Enhancement

  • Professional Layout: Create consistent, professional page numbering across documents
  • Print Optimization: Optimize page numbers for different printing requirements
  • Digital Distribution: Maintain formatting across different viewing devices
  • Brand Consistency: Apply uniform page numbering standards across organizations

Advanced Features

  • Batch Processing: Process multiple documents with consistent page numbering
  • Quality Assurance: Ensure page number integrity and proper PDF compatibility
  • Layout Preservation: Maintain document structure while adding page numbers
  • Custom Margins: Precise control over page number positioning

Industry Use Cases & Applications

Legal & Professional Services Use Cases

  • Legal Documentation: Number pages in contracts, agreements, and legal briefs
  • Court Documents: Add page numbers to court filings and legal documents
  • Compliance Documentation: Number pages in compliance and regulatory documents
  • Client Documentation: Organize client documents with page numbering

Get Help