Internal server error

I have implemented merge api ,It working fine 1 page pdf and small size pdf bleow 1MB. Unfortunately above 1 mb or more page pdf getting error.

WebViewer({
    disableFlattenedAnnotations: true,
    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: 'test2.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() {

                    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', fileData);
                        data.append('file', blob);
                        data.append('license', '');

                        // 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 fd = new FormData();
                        fd.append('fname', 'test.pdf');
                        fd.append('data', mergedFileBlob);
                        var data = new FormData();
                        data.append('mydoc.pdf', mergedFileBlob, 'mydoc.pdf');


                        var req = new XMLHttpRequest();
                        req.open("POST", '/pdf_editor/test/upload.php', true);
                        req.onload = function (oEvent) {
                            // Uploaded.
                        };

                        req.send(data);


                        // Do something with blob...
                        // save(mergedFileBlob)
                    }

                }
            });
        });
    });

I have tried1.75 mb pdf file and edit some content and requested to merge api.But i got error .“Internal server error” .Also when i try above 3mb pdf file igot another error HTTP content length exceeded 10485760 bytes.

Hi there,

Thanks for the info. We will look into the internal server error issue and get back to you when its resolved.

Thanks,
Logan

Hi!

You are appending the ‘file’ data twice to your request which will combine fileData and blob together which is creating invalid (and large) data.

data.append('file', fileData); // you can remove this line
data.append('file', blob);

Thanks!
Logan

1 Like