All endpoints accept a URL as a file, and sometimes headers will be required in order to fetch these files. For example, if you are using a protected endpoint, it might require an Authorization
header to be set.
All endpoints accept a headers
field, which should come in the form as stringified JSON. These headers will be forwarded when we make a GET request to download your file.
For example:
const data = new FormData();
data.append('file', 'http://my-protected-endpoint.com/file.pdf');
data.append('license', my_license_key);
data.append('headers', JSON.stringify({
Authorization: 'my_auth_code'
}))
// Process the file
const response = await fetch('https://api.pdfjs.express/xfdf/extract', {
method: 'post',
body: data
}).then(resp => resp.json());
The API will now pass the Authorization
header when it tries to fetch http://my-protected-endpoint.com/file.pdf
.
Chaining APIs
This feature also allows you to chain API calls easily. Since getting a file from our API requires an Authorization
header to be set, forwarding this header is necessary.
For example, to merge XFDF and then watermark you could do something like this:
const data = new FormData();
data.append('file', 'http://my-protected-endpoint.com/file.pdf');
data.append('license', my_license_key);
data.append('xfdf', my_xfdf);
// Process the file
const response = await fetch('https://api.pdfjs.express/xfdf/merge', {
method: 'post',
body: data
}).then(resp => resp.json());
const {url, key} = response;
const watermarkData = new FormData();
watermarkData.append('file', 'url');
watermarkData.append('headers', JSON.stringify({
Authorization: key
}))
watermarkData.append('text', 'my watermark')
const watermarkResponse = await fetch('https://api.pdfjs.express/watermark', {
method: 'post',
body: data
}).then(resp => resp.json());