I have edited 16 MB PDF total 20 pages. When click save button merging XFDF using the express REST API return error like below.
HTTP content length exceeded 10485760 bytes.
WebViewer({
disableFlattenedAnnotations: true,
path: '/lib',
licenseKey: '', // optional
initialDoc: pdf_url,
}, document.getElementById('viewer'))
.then(function(instance) {
var docViewer = instance.docViewer;
var annotManager = instance.annotManager;
var Annotations = instance.Annotations;
instance.setHeaderItems(function(header) {
header.push({
type: 'actionButton',
img: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="m0 0h24v24h-24z" fill="none"></path><path d="m21 19v-14c0-1.1-.9-2-2-2h-14c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zm-12.5-5.5 2.5 3.01 3.5-4.51 4.5 6h-14z"></path></svg>',
onClick: function() {
onSavetwo();
async function onSavetwo() {
var stampAnnot = new Annotations.StampAnnotation();
stampAnnot.PageNumber = docViewer.getCurrentPage();
stampAnnot.rotation=180;
stampAnnot.X = 100;
stampAnnot.Y = 250;
stampAnnot.Width = 1050;
stampAnnot.Height = 591;
stampAnnot.ImageData = image_url;
stampAnnot.Author = await annotManager.getCurrentUser();
annotManager.addAnnotation(stampAnnot);
annotManager.redrawAnnotation(stampAnnot);
}
}
});
});
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() {
onSave();
async function onSave() {
var xfdf = await annotManager.exportAnnotations({ links: false, widgets: false });
var fileData = await docViewer.getDocument().getFileData({});
var blob = new Blob([fileData], {type: 'application/pdf'});
var data = new FormData();
data.append('xfdf', xfdf);
data.append('file', blob);
data.append('license','pPNmq7E8QLc5z3EiploT');
// Process the file
var response = await fetch('https://api.pdfjs.express/xfdf/merge', {
method: 'post',
body: data
}).then(resp => resp.json());
var { url, key, id } = response;
// Download the file
var mergedFileBlob = await fetch(url, {
headers: {
Authorization: key
}
}).then(resp => resp.blob())
var data_PDF = new FormData();
data_PDF.append('data' , mergedFileBlob);
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (this.readyState == 4) {
$('#cover-spin').hide(0);
$("#ed-alert").css("display", "block");
setTimeout(function() { $("#ed-alert").css("display", "none"); }, 5000);
} else {
$('#cover-spin').show(0);
}
}
xhr.open('POST', upload_url, true);
xhr.send(data_PDF);
// Do something with blob...
// save(mergedFileBlob)
}
}
});
});
});