I have tried Merging XFDF using the Express REST API but getting below error when submitting save button.
{ message: “Invalid input.”, type: “InvalidPDF”, code: 20 }
This is my code
WebViewer({
path: 'lib', // path to the PDFTron 'lib' folder on your server
licenseKey: 'Insert license key here', // optional
// initialDoc: 'https://pdftron.s3.amazonaws.com/downloads/pl/webviewer-demo.pdf',
initialDoc: 'test.pdf', // You can also use documents on your server
}, document.getElementById('viewer'))
.then(function(instance) {
var docViewer = instance.docViewer;
var annotManager = instance.annotManager;
instance.setHeaderItems(function(header) {
header.push({
type: 'actionButton',
img: '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M0 0h24v24H0z" fill="none"/><path d="M17 3H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2V7l-4-4zm-5 16c-1.66 0-3-1.34-3-3s1.34-3 3-3 3 1.34 3 3-1.34 3-3 3zm3-10H5V5h10v4z"/></svg>',
onClick: function() {
var docViewer = instance.docViewer;
var annotManager = instance.annotManager;
var xfdf = annotManager.exportAnnotations({ links: false, widgets: false });
var fileData = docViewer.getDocument().getFileData({});
var data = new FormData();
data.append('xfdf', xfdf);
data.append('file', fileData);
data.append('license','');
console.log(data);
var response = fetch('https://api.pdfjs.express/xfdf/merge', {
method: 'post',
body: data
}).then(function(resp) {
resp.json()
});
console.log(response);
}
});
});
});
Please help