Move or Rearrange PDF Pages in Linux

PSPDFKit Processor lets you move the existing pages of a document using the movePages operation.

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

Reordering Pages of a 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": "movePages",
      "pageIndexes": [
        "first"
      ],
      "afterPageIndex": "last"
    }
  ]
}' \
  -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": "movePages",
      "pageIndexes": [
        "first"
      ],
      "afterPageIndex": "last"
    }
  ]
}
--customboundary--

This will move the first page of the document and place it after the last page.

Reordering Pages of a 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": "movePages",
      "pageIndexes": [
        "first"
      ],
      "afterPageIndex": "last"
    }
  ]
}' \
  -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": "movePages",
      "pageIndexes": [
        "first"
      ],
      "afterPageIndex": "last"
    }
  ]
}
--customboundary--

This will move the first page of the document and place it after the last page.