PDF.js Express Plusplay_arrow

Professional PDF.js Viewing & Annotations - Try for free

side menu

Get Started

play_arrow

Learn more

play_arrow

Common use cases

play_arrow

Open a document

play_arrow

Save a document

play_arrow

Viewer

play_arrow

UI Customization

play_arrow

Annotations

play_arrow

Collaboration

play_arrow

Forms

play_arrow

Signature

play_arrow

Searching

play_arrow

Measurement

play_arrow

Compare

play_arrow

Advanced Capabilities

play_arrow

PDF.js Express REST API

play_arrow

Migration Guides

play_arrow

Extract XFDF using the Express REST API

The following features are available in:

check

PDF.js Express Viewer

help_outline

PDF.js Express Viewer is a free viewer with limited capabilities compared to PDF.js Express Plus

check

PDF.js Express Plus

help_outline

PDF.js Express Plus is a commercial PDF SDK for viewing, annotating, signing, form filling and more

This endpoint extract annotations from a document and return them in XFDF format.

Each successful call to this endpoint counts as one action.

NOTE: It is strongly recommended to use the Rest API Utility package

Endpoint

POST https://api.pdfjs.express/xfdf/extract

Body params

The request body must be formatted as multipart/form-data

NameTypeDescription
fileFile, Blob, string (url), or BufferThe file to process. Must be a valid PDF file. The max file size for an in memory file is 5.5mb. If your file is larger than that, it must be accessible via URL, and the URL must be passed to this parameter. A File object can be retrieved using the getFileData API.
licensestringYour PDF.js Express API license key. You must pass the correct license key depending if you are making the request from the server or the client. If no license key is provided, the output will be watermarked and usage will be heavily limited.
headersstringified JSONHeaders to forward when the API downloads your file. Only used if file param is a URL. See this guide for more details.

Response body (success)

A success response will come back in json format and will contain the following:

PropertyTypeDescription
xfdfstringThe XFDF representing the annotations on the document. See the example before for usage.

Response body (error)

See the list of error responses for details.

Example

The following example extracts and loads annotations when a document is loaded.

When using this API, it is recommended to set the disableFlattenedAnnotations option to ensure that you do not render duplicate annotations.

WebViewer({
  disableFlattenedAnnotations: true,
  ...otherOptions
}).then(instance => {

  const { docViewer, annotManager } = instance;

  docViewer.on('documentLoaded', async () => {
    const fileData = await docViewer.getDocument().getFileData({});
    const blob = new Blob([fileData], {type: 'application/pdf'})

    const data = new FormData();
    data.append('file', blob);
    data.append('license', my_license_key);

    // Process the file
    const response = await fetch('https://api.pdfjs.express/xfdf/extract', {
      method: 'post',
      body: data
    }).then(resp => resp.json());

    const { xfdf } = response;

    const importedAnnotations = await annotManager.importAnnotations(xfdf);
  })

})
WebViewer({
  disableFlattenedAnnotations: true,
  ...otherOptions
}).then(instance => {

  const { documentViewer, annotationManager } = instance.Core;

  documentViewer.addEventListener('documentLoaded', async () => {
    const fileData = await documentViewer.getDocument().getFileData({});
    const blob = new Blob([fileData], {type: 'application/pdf'})

    const data = new FormData();
    data.append('file', blob);
    data.append('license', my_license_key);

    // Process the file
    const response = await fetch('https://api.pdfjs.express/xfdf/extract', {
      method: 'post',
      body: data
    }).then(resp => resp.json());

    const { xfdf } = response;

    const importedAnnotations = await annotationManager.importAnnotations(xfdf);
  })

})