API Reference for Processing and Rendering PDFs

PSPDFKit Processor provides the following API endpoints for working with documents:

Processing a Document

To process a document, submit a multipart/form-data request to the POST /process API endpoint.

Available headers for POST /process:

  • Optional — Authorization — This is where you pass in your JSON Web Token (JWT).

  • Optional — pspdfkit-pdf-password — This is where you pass in the password required for the PDF document to be processed. If it’s not set and a password is required, the request will fail.

  • Optional — X-Request-Id — If this is set, log statements associated with the HTTP request are marked with a request_id=<request-id> label. Logs correlated with the same request have the same request ID. This helps you determine which request triggered a specific response and what errors or warnings were emitted during request processing. The request ID needs to be between 20 and 200 characters long.

Available parameters for POST /process:

  • Required — "file", "url", or "generation".

    • "file" — The document that should be processed.

    • "url" — A URL the document that should be processed can be fetched from.

    • "generation" — A JSON object describing how the document should be generated. See the PDF Generation Schema guide for more information.

  • Optional — "operations" — The JSON object describing the operations that should be performed on the supplied document. For all available operations, see the Available Operations guide.

  • Optional — Attachment data for the operations — For example, the XFDF that should be imported when using the applyXfdf document operation.

Request

POST /process
Content-Type: multipart/form-data; boundary=customboundary
Authorization: Token token="JWT Token"
pspdfkit-pdf-password: "PDF Password"

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

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

<Operations JSON>
--customboundary--
curl -H "Authorization: Token token=JWT_TOKEN" \
  -F file=@Example.pdf \
  -F operations="{\"operations\":[{\"type\": \"flattenAnnotations\"}]}" \
  http://localhost:5000/process \
  --output result.pdf

Response

HTTP/1.1 200 OK
Content-Type: application/pdf

<PDF data>

Rendering a Document

To render a document, submit a multipart/form-data request to the POST /render API endpoint. The response depends on whether the source document contains a single page or multiple pages:

  • Responds with application/zip, which contains the rendered pages when rendering multiple pages.

  • Responds with the image data directly when rendering a single page.

Request Headers

Available headers for POST /render:

  • Optional — Authorization — This is where you pass in your JSON Web Token (JWT).

  • Optional — pspdfkit-pdf-password — This is where you pass in the password required for the PDF document to be rendered. If it’s not set and a password is required, the request will fail.

  • Optional — X-Request-Id — If this is set, log statements associated with the HTTP request are marked with a request_id=<request-id> label. Logs correlated with the same request have the same request ID. This helps you determine which request triggered a specific response and what errors or warnings were emitted during request processing. The request ID needs to be between 20 and 200 characters long.

Request Parameters

Available parameters for POST /render:

  • Required — "file", "url", or "generation".

    • "file" — The document that should be rendered.

    • "url" — A URL the document that should be rendered can be fetched from.

    • "generation" — A JSON object describing how the document should be generated. See the PDF Generation Schema guide for more information.

  • Required — "options" — The JSON object describing the options for the render request. See the Available Render Options guide for a description of all available options.

Request

curl -X POST http://localhost:5000/render \
  -F file=@Example.pdf \
  -F options='{
  "options": {
    "pageIndex": 0,
    "width": 1000,
    "renderAnnotations": true,
    "format": "png"
  }
}' \
  -o result.png
POST /render HTTP/1.1
Content-Type: multipart/form-data; boundary=customboundary

--customboundary
Content-Disposition: form-data; name="file"; filename="Example.pdf"


--customboundary
Content-Disposition: form-data; name="options"
Content-Type: application/json

{
  "options": {
    "pageIndex": 0,
    "width": 1000,
    "renderAnnotations": true,
    "format": "png"
  }
}
--customboundary--

Response

HTTP/1.1 200 OK
Content-Type: image/png

<image data>