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

Measurement

play_arrow

PDF.js Express REST API

play_arrow

Saving a document as a blob

Documents can be exported from PDF.js Express by using the Document.getFileData API.

Please note that PDF.js Express does not have the ability to bake annotations into a PDF file on the client, so getFileData will not include annotations. For instructions on baking annotations into the document, please see this guide.

A use case for this may be saving a file a user has uploaded to your own server, allowing them to reuse it later.

The function can be used as follows:

Webviewer({
  ...options
}, document.getElementById('viewer')).then(instance => {

  const { docViewer } = instance;

  // must wait for the document to be loaded before you can save the file
  docViewer.on('documentLoaded', async () => {
    const documentStream = await docViewer.getDocument().getFileData({});
    const documentBlob = new Blob([documentStream], { type: 'application/pdf' });

    // Example function that saves a blob to the server
    saveBlobToServer(documentBlob);
  })

});