Free trial

Pick a framework to get started

close

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

PDF.js Express REST API

play_arrow

Migration Guides

play_arrow

Getting a processed file

In order to get a processed file from the API, the proper authorization header must be set.

This header is returned from any endpoint that creates a new file (set, merge), and is returned as key.

In order to get the file, you must set the Authorization header to be equal to the returned key.

Example:

  const { docViewer, annotManager } = instance;

  // a callback function to some "download" button
  const onSave = async () => {
    const xfdf = await annotManager.exportAnnotations({ links: false, widgets: false });
    const fileData = await docViewer.getDocument().getFileData({});

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

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

    const { url, key, id } = response;

    // Download the file
    const mergedFileBlob = await fetch(url, {
      headers: {
        Authorization: key
      }
    }).then(resp => resp.blob())
  }