This endpoint will merge any new annotations with the existing annotations in the document.
Each successful call to this endpoint counts as one action.
Endpoint
POST https://api.pdfjs.express/xfdf/merge
Body params
The request body must be formatted as multipart/form-data
Name | Type | Description |
---|---|---|
file | File, Blob, string (url), or Buffer | The file to process. Must be a valid PDF file. The max file size for an in memory file is 5.5mb. If your file is larger than that, it must be accessible via URL, and the URL must be passed to this parameter. A File object can be retrieved using the getFileData API. |
xfdf | string | The XFDF to merge. Can be retrieved using the exportAnnotations API. |
license | string | Your PDF.js Express API license key. You must pass the correct license key depending if you are making the request from the server or the client. If no license key is provided, the output will be watermarked and usage will be heavily limited. |
headers | stringified JSON | Headers to forward when the API downloads your file. Only used if file param is a URL. See this guide for more details. |
Response body (success)
A success response will come back in json
format and will contain the following:
Property | Type | Description |
---|---|---|
url | string | The URL where the processed file can be downloaded from (using proper authentication) |
id | string | The unique id of the file. Used to delete the file |
key | string | An authentication required used to GET the file. See details here |
Response body (error)
See the list of error responses for details.
Example
The following example merges XFDF into the current document when a download button is clicked.
WebViewer({...}).then(instance => {
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 blob = new Blob([fileData], {type: 'application/pdf'});
const data = new FormData();
data.append('xfdf', xfdf);
data.append('file', blob);
data.append('license', my_license_key);
// Process the file
const response = await fetch('https://api.pdfjs.express/xfdf/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())
// Do something with blob...
// save(mergedFileBlob)
}
})
WebViewer({...}).then(instance => {
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 blob = new Blob([fileData], {type: 'application/pdf'});
const data = new FormData();
data.append('xfdf', xfdf);
data.append('file', blob);
data.append('license', my_license_key);
// Process the file
const response = await fetch('https://api.pdfjs.express/xfdf/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())
// Do something with blob...
// save(mergedFileBlob)
}
})