Importing PDF Annotations in Linux

Information

PSPDFKit Processor has been deprecated and replaced by PSPDFKit Document Engine. All PSPDFKit Processor licenses will work as before and be supported until 15 May 2024 (we will contact you about license migration). To start using Document Engine, refer to the migration guide. With Document Engine, you’ll have access to robust new capabilities (read the blog for more information).

You can import annotations into an input file by sending a multipart request to the /build endpoint and including an Instant JSON or XFDF file that contains annotations.

Instant JSON files are imported via the applyInstantJson action, whereas you can use the applyXfdf action to import XFDF files.

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

You can download these sample files to use as you work through the examples in this guide:

Importing Instant JSON into a File on Disk

Send a request to the /build endpoint, attaching an input file and the Instant JSON attachment:

curl -X POST http://localhost:5000/build \
  -F document=@/path/to/example-document.pdf \
  -F 'instant_json=@/path/to/instant.json;type=application/json' \
  -F instructions='{
  "parts": [
    {
      "file": "document"
    }
  ],
  "actions": [
    {
      "type": "applyInstantJson",
      "file": "instant_json"
    }
  ]
}' \
  -o result.pdf
POST /process HTTP/1.1
Content-Type: multipart/form-data; boundary=customboundary

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

<PDF data>
--customboundary
Content-Disposition: form-data; name="instant_json"; filename="instant.json"
Content-Type: application/json

<Instant JSON data>
--customboundary
Content-Disposition: form-data; name="instructions"
Content-Type: application/json

{
  "parts": [
    {
      "file": "document"
    }
  ],
  "actions": [
    {
      "type": "applyInstantJson",
      "file": "instant_json"
    }
  ]
}
--customboundary--

Note that the applyInstantJson action’s file references the request attachment with the same name: instant_json.

Importing a Local Instant JSON File into a PDF File That Was Downloaded from a URL

Attach an Instant JSON file like you did in the previous example, but instead of a file on disk, include a URL pointing to the input file:

curl -X POST http://localhost:5000/build \
  -F 'instant_json=@/path/to/instant.json;type=application/json' \
  -F instructions='{
  "parts": [
    {
      "file": {
        "url": "https://pspdfkit.com/downloads/examples/paper.pdf"
      }
    }
  ],
  "actions": [
    {
      "type": "applyInstantJson",
      "file": "instant_json"
    }
  ]
}' \
  -o result.pdf
POST /process HTTP/1.1
Content-Type: multipart/form-data; boundary=customboundary

--customboundary
Content-Disposition: form-data; name="instant_json"; filename="instant.json"
Content-Type: application/json

<Instant JSON data>
--customboundary
Content-Disposition: form-data; name="instructions"
Content-Type: application/json

{
  "parts": [
    {
      "file": {
        "url": "https://pspdfkit.com/downloads/examples/paper.pdf"
      }
    }
  ],
  "actions": [
    {
      "type": "applyInstantJson",
      "file": "instant_json"
    }
  ]
}
--customboundary--

Importing an XFDF File

Similar to how you import Instant JSON files, you can import XFDF files via the applyXfdf action. Make sure that the XFDF attachment to the multipart request has its content type set to application/vnd.adobe.xfdf.