Documents can be exported from PDF.js Express by using the Document.getFileData
API.
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);
})
});
Webviewer({
...options
}, document.getElementById('viewer')).then(instance => {
const { documentViewer } = instance.Core;
// must wait for the document to be loaded before you can save the file
documentViewer.addEventListener('documentLoaded', async () => {
const documentStream = await documentViewer.getDocument().getFileData({});
const documentBlob = new Blob([documentStream], { type: 'application/pdf' });
// Example function that saves a blob to the server
saveBlobToServer(documentBlob);
})
});