XFDF Support

XFDF is an XML-like standard from Adobe XFDF (ISO 19444-1:2016) 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 will result in a smaller file and better synchronization.

Importing XFDF

Standalone Importing

To import XFDF when using standalone deployment, you can use the Configuration#XFDF option.

In addition to the Configuration#XFDF option, you can also set the Configuration#XFDFKeepCurrentAnnotations flag. This flag will make sure annotations that are already in the source PDF are kept and not replaced with those defined in the XFDF:

Copy
1
2
3
4
5
PSPDFKit.load({
  pdf: "https://your-server.com/some/document.pdf",
  XFDF:
    '<?xml version="1.0" encoding="UTF-8"?><xfdf xml:space="preserve" xmlns="http://ns.adobe.com/xfdf/"> ..'
});
Copy
1
2
3
4
5
PSPDFKit.load({
  pdf: "https://your-server.com/some/document.pdf",
  XFDF:
    '<?xml version="1.0" encoding="UTF-8"?><xfdf xml:space="preserve" xmlns="http://ns.adobe.com/xfdf/"> ..'
});

Server Importing

When you upload a new document to PSPDFKit Server, you can include an XFDF document as a second file in the upload. Follow the Server guides for an in-depth example.

Exporting to XFDF

Copy
1
2
3
instance.exportXFDF().then(xfdf => {
  console.log(xfdf); // => <?xml version="1.0" encoding="UTF-8"?><xfdf xml:space="preserve" xmlns="http://ns.adobe.com/xfdf/"> ...
});
Copy
1
2
3
instance.exportXFDF().then(function(xfdf) {
  console.log(xfdf); // => <?xml version="1.0" encoding="UTF-8"?><xfdf xml:space="preserve" xmlns="http://ns.adobe.com/xfdf/"> ...
});

XFDF works seamlessly with the annotation API. If you want to persist annotations whenever changes are made, we recommend you use the annotations.didSave event. This event will be triggered automatically and can be configured via Configuration#autoSaveMode.

Note for standalone users: Instead of saving annotations to the backend, a save operation will persist the annotations in memory until they are either exported via Instance#exportXFDF or written to the PDF document when you export it using Instance#exportPDF. Unsaved annotations will not be exported, in order to reflect the server behavior:

Copy
1
2
3
4
5
6
7
8
9
10
instance.addEventListener("annotations.didSave", async () => {
  const xfdf = await instance.exportXFDF();
  await fetch("https://your-server.com/xfdf", {
    method: "post",
    headers: {
      "Content-Type": "application/vnd.adobe.xfdf"
    },
    body: xfdf
  });
});
Copy
1
2
3
4
5
6
7
8
9
10
instance.addEventListener('annotations.didSave', function () {
  instance.exportXFDF().then(function (xfdf) {
      var req = new XMLHttpRequest();
      req.open("GET", "https://your-server.com/xfdf");
      req.setRequestHeader("Content-Type", "application/vnd.adobe.xfdf");
      req.send(xfdf);
      req.send();
    });
  });
});

Exporting Annotations to XFDF via Adobe Acrobat

Adobe Acrobat can export annotations into XFDF. The export menu is part of the Comments tool and is accessed by opening the tool in the sidebar.

You can access the export function by clicking on the three dots and then choosing Export All To Data File.

  1. At the bottom of the page, choose Acrobat XFDF Files.
  2. Select the directory you wish to save the XFDF file to and name the file.
  3. Click save.

A successful export will result in a file with an .xfdf extension.

Importing Annotations to XFDF via Adobe Acrobat

The export function is part of the Comments tool and is accessed by clicking on its icon.

Click on the three dots to open the import menu, and then click on Import Data File.

Highlight the .xfdf file you wish to import and click Select.

The import function completes with the annotations being placed on the document.

Adobe Acrobat Error Conditions

Error Description Screenshot
Damaged/missing document body
Damaged/missing description tag
Missing document flag