Insert Pages

PSPDFKit Processor lets you add new pages to a document using the addPage operation. You can specify the new page size, background color, and rotation.

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

Adding a Page to a File on Disk

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

curl -X POST http://localhost:5000/process \
  -F file=@/path/to/example.pdf \
  -F operations='{
  "operations": [
    {
      "type": "addPage",
      "afterPageIndex": "last",
      "backgroundColor": "#FFFFFF",
      "pageWidth": 595,
      "pageHeight": 842,
      "rotateBy": 0
    }
  ]
}' \
  -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": "addPage",
      "afterPageIndex": "last",
      "backgroundColor": "#FFFFFF",
      "pageWidth": 595,
      "pageHeight": 842,
      "rotateBy": 0
    }
  ]
}
--customboundary--

This will add a white A4-size page after the last page of the document.

Adding a Page to a File from a URL

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

curl -X POST http://localhost:5000/process \
  -F url=https://pspdfkit.com/downloads/examples/paper.pdf \
  -F operations='{
  "operations": [
    {
      "type": "addPage",
      "afterPageIndex": "last",
      "backgroundColor": "#FFFFFF",
      "pageWidth": 595,
      "pageHeight": 842,
      "rotateBy": 0
    }
  ]
}' \
  -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": "addPage",
      "afterPageIndex": "last",
      "backgroundColor": "#FFFFFF",
      "pageWidth": 595,
      "pageHeight": 842,
      "rotateBy": 0
    }
  ]
}
--customboundary--

This will add a white A4-size page after the last page of the document.