How to Add Page Numbers to a PDF File using PDF.co Web API

PDF.co offers a variety of functionalities to help you with your PDF. These functionalities include PDF merging/splitting, search/replace text, PDF data extraction, PDF filler, document parsing, barcode reader, barcode generator, etc.

In this tutorial, we will show you how to add page numbers to a PDF file using PDF.co Web API.

Step 1: Open PDF.co Account

Request Tester

Step 2: Request Tester Page

  • For Choose PDF.co API endpoint field, search and select v1/pdf/edit/add. This endpoint can add multiple pages in a single PDF.
  • For the Input Parameters field, override the URL param with a link or input with a file.
Request Tester Page

Step 3: Enter JSON Code

Let’s add the JSON Code and set up the parameters

  • For the Async param, will set it to false.
  • For Encrypt param, set it to true.
  • For the Inline param, set it to true.
  • In the Name param, type in your desired output file name.

Let’s set up the Annotations param

  • In the Text param, enter the macros {{$$PageNumber}} to automatically add page numbers in the PDF file.
  • For X and Y params, add the coordinates where you want to add the page number. You can get the coordinates of your PDF file with our PDF/Edit/Add Helper.
  • In the Size param, add the size of your page number.
  • For the Pages param, enter 0- so we can add numbers to all pages in a PDF file.
Enter JSON Code
{
"async": false,
"encrypt": true,
"inline": true,
"name": "Output_File",
"annotations": [
{
"text": "{{$$PageNumber}} ",
"x": 290,
"y": 7,
"size": 20,
"pages": "0-"
}
]
}

After setting up the code, click on the Run Request button to send a request.

Step 4: Result

  • Great! We successfully run the request, kindly click on the URL to view the output, or directly download the output file.
Run Request Result

In this tutorial, you learned how to add page numbers to a PDF file using PDF.co Web API. You also learned how to use the v1/pdf/edit/add endpoint and add multiple page numbers in a single PDF.