Changing PDF Page Numbers or Labels in Linux

You can set page labels of a document using the setPageLabel operation. This can be useful when, for example, you want PDF readers to show Roman numerals for page labels instead of Arabic numerals.

Before you get started, make sure that Processor is up and running.

Setting the Page Label of the File on Disk

Send a request to the /process endpoint, attaching an input file and the operations JSON:

curl -X POST http://localhost:5000/process \
  -F file=@/path/to/example.pdf \
  -F operations='{
  "operations": [
    {
      "type": "setPageLabel",
      "pageIndexes": [
        0
      ],
      "pageLabel": "i"
    }
  ]
}' \
  -o result.pdf
POST /process HTTP/1.1
Content-Type: multipart/form-data; boundary=customboundary

--customboundary
Content-Disposition: form-data; name="file"; filename="example.pdf"
Content-Type: application/pdf

<PDF data>
--customboundary
Content-Disposition: form-data; name="operations"
Content-Type: application/json

{
  "operations": [
    {
      "type": "setPageLabel",
      "pageIndexes": [
        0
      ],
      "pageLabel": "i"
    }
  ]
}
--customboundary--

This will set the page label of the first page to “i.” You can see this by opening the resulting PDF in a PDF viewer application:

Single-page PDF thumbnail view with a page label set to a Roman numeral “i.”

Setting the Page Label of the File from a URL

Send a request to the /process endpoint, attaching a URL pointing to an input file and the operations JSON:

curl -X POST http://localhost:5000/process \
  -F url=https://pspdfkit.com/downloads/examples/paper.pdf \
  -F operations='{
  "operations": [
    {
      "type": "setPageLabel",
      "pageIndexes": [
        0
      ],
      "pageLabel": "i"
    }
  ]
}' \
  -o result.pdf
POST /process HTTP/1.1
Content-Type: multipart/form-data; boundary=customboundary

--customboundary
Content-Disposition: form-data; name="url"

https://pspdfkit.com/downloads/examples/paper.pdf
--customboundary
Content-Disposition: form-data; name="operations"
Content-Type: application/json

{
  "operations": [
    {
      "type": "setPageLabel",
      "pageIndexes": [
        0
      ],
      "pageLabel": "i"
    }
  ]
}
--customboundary--

This will set the page label of the first page to “i.”