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())
}
const { documentViewer, annotationManager } = instance.Core;
// a callback function to some "download" button
const onSave = async () => {
const xfdf = await annotationManager.exportAnnotations({ links: false, widgets: false });
const fileData = await documentViewer.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())
}