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.
Contents
Step 1: Open PDF.co Account
- Let’s begin. First, let’s start by opening your PDF.co account and the Request Tester menu.
![Request Tester](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2F2niroq9z%2Fproduction%2F1da31f368621a4201c90e89b1dba488323b75c04-2494x1414.png&w=3840&q=75)
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](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2F2niroq9z%2Fproduction%2F441280f342183992f8a14a2d56ea6ce0f27cddce-999x453.png&w=2048&q=75)
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](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2F2niroq9z%2Fproduction%2F51f2822853660ae92b7520ddcfe47cef8d70720d-839x371.png&w=1920&q=75)
{
"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](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2F2niroq9z%2Fproduction%2Fc88dc9bf3f770112d923b0336faef4d685e857bc-999x95.png&w=2048&q=75)
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.