XFDF Support

XFDF is an XML-like standard from Adobe XFDF for encoding annotations and forms (see this XFDF overview). It is compatible with Adobe Acrobat and several other third-party frameworks.

ℹ️ Note: XFDF has various limitations. In most cases, using PSPDFKit Instant or Instant JSON will result in a smaller file and better synchronization.

PSPDFKit Server supports importing XFDF files on document upload and exporting XFDF from an existing PDF. Our POST /documents endpoint for uploading documents now supports the import of an XFDF file, and we also offer a GET /document.xfdf endpoint to export the current state of a document into an XFDF file.

Importing XFDF

PSPDFKit Server supports importing annotations from an XFDF file when uploading a document via the /api/documents endpoint. Send a multipart/form-data POST request including the PDF and the XFDF 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

Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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.xfdf"
Content-Type: application/vnd.adobe.xfdf

<annotations data>
--customboundary
Content-Disposition: form-data; name="keep_current_annotations"

true
--customboundary--

Exporting to XFDF

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

Request

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

Response

1
2
3
4
HTTP/1.1 200 OK
Content-Type: application/vnd.adobe.xfdf

<XFDF data>