Import and Export Instant JSON Files

You can import and export annotations from documents you’ve uploaded to PSPDFKit Server. One of the supported formats for this is Instant JSON. This guide explains how to import and export annotations in the Instant JSON format.

Exporting Instant JSON

You can export the current annotations of a document as an Instant JSON file via a GET request to /api/documents/:document_id/document.json. To get the current annotations of a layer, send a GET request to /api/documents/:document_id/layers/:layer_name/document.json:

Request

GET /api/documents/:document_id/document.json
Authorization: Token token="<secret token>"
$ curl "http://localhost:5000/api/documents/abc/document.json" \
   -H "Authorization: Token token=<secret token>"

Response

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

<JSON data>

Importing Instant JSON

PSPDFKit Server supports importing annotations from an Instant JSON file when uploading a document via the /api/documents endpoint. Send a multipart/form-data POST request, including the PDF and the Instant JSON file, to import the annotations in the given PDF file. This will replace all existing annotations in the uploaded PDF with the annotations from the uploaded Instant JSON file. If you want to add annotations to already existing ones instead of replacing them, you can set keep_current_annotations to true:

Request

POST /api/documents
Content-Type: multipart/form-data; boundary=customboundary
Authorization: Token token="<secret token>"

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

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

<annotations data>
--customboundary

Importing Instant JSON on Existing Documents

PSPDFKit Server supports importing annotations from an Instant JSON file on an existing document via two different endpoints:

  • POST /pdf_with_instant_json receives an instant.json file and responds with the resulting PDF of the document/layer and the imported instant.json.

  • POST /copy_with_instant_json can optionally receive an instant.json file and will persist the resulting PDF of the document/layer and the imported instant.json file as a new document. The JSON response will include the document_id of the document.