Add Page Numbers to PDF Files

Add Page Numbers to PDF Files

Automate the process to add page numbers to PDFs using pdfRest's Add to PDF API Tool for text insertion
Share this page

Adding page numbers to a PDF can make reports, contracts, invoices, and other multi-page documents easier to navigate. With pdfRest, you can determine the document's page count and then insert customized page-number text into the appropriate pages.

Automate PDF Page Numbering

Use the Query PDF API Tool to determine how many pages are in the source document. Your application can then create one text object for each page, assigning the appropriate page number to each object, such as “Page 1 of 8,” “Page 2 of 8,” and so on.

Each page-number object can use the same position and styling while containing different text and targeting a different page. This approach also supports formats such as “1 of 8,” “Page 1,” or “Section A - Page 1 of 8.”

Add Page Numbers with the Add to PDF API Tool

After determining the page count, send the source PDF and a text_objects JSON array to the Add to PDF API Tool. Each object specifies the page, text, position, font, size, color, and other formatting options.

[
  {
    "page": 1,
    "x": 270,
    "y": 36,
    "text": "Page 1 of 8",
    "font": "Arial",
    "text_size": 10,
    "text_color_rgb": "80,80,80"
  },
  {
    "page": 2,
    "x": 270,
    "y": 36,
    "text": "Page 2 of 8",
    "font": "Arial",
    "text_size": 10,
    "text_color_rgb": "80,80,80"
  },
  {
    "page": 3,
    "x": 270,
    "y": 36,
    "text": "Page 3 of 8",
    "font": "Arial",
    "text_size": 10,
    "text_color_rgb": "80,80,80"
  }
]

Your application can generate the complete array dynamically based on the page count returned by Query PDF. This allows the same workflow to handle documents with different numbers of pages without manually preparing each request.

Customize Page-Number Appearance

Page-number text can be positioned and styled to match the rest of the document. You can specify:

  • Position: Place the page number in a footer, header, margin, or another location using PDF coordinates.
  • Text format: Use formats such as “Page 1 of 8,” “1 / 8,” or a custom label.
  • Font and size: Match the typography of the source document.
  • Color and opacity: Use subtle footer text or a more prominent navigational label.
  • Rotation: Rotate the text when page numbers need to appear along a side margin.
  • Wrapping: Set a maximum width when the page-number label may contain additional text.

Add Optional Structure Tags

Add to PDF supports optional structure tags for newly inserted page-number text. When enabled, page numbers can be identified in the PDF structure for downstream processing and accessibility-oriented workflows.

Tagging applies to the page-number text inserted by the request. It does not automatically tag pre-existing untagged content in the source PDF, but tagged page numbers can be added to a PDF that already contains an existing structure tree.

Build a Page-Numbering Workflow

A complete workflow can be organized into three steps:

  1. Send the source PDF to Query PDF and retrieve its page count.
  2. Generate one page-number text object for each page.
  3. Send the source PDF and generated text_objects array to Add to PDF.

You can test the workflow in the pdfRest API Lab and review implementation details in the pdfRest API documentation.





Query PDF



Add to PDF


Generate a self-service API Key now!
Create your FREE API Key to start processing PDFs in seconds, only possible with pdfRest.