Skip to main content
Participant
January 20, 2021
Question

Is there any way to save edited pdf in server in pdf embed API

  • January 20, 2021
  • 2 replies
  • 4197 views

I am currently working on a Learning Management System and I have to attach this Embed API to my application based on PHP Core, but instead of downloading the pdf I want it to be saved on my server and not on the client's computer, is there any way to do it?

    This topic has been closed for replies.

    2 replies

    Joel Geraci
    Community Expert
    Community Expert
    February 8, 2021

    I've posted a functioning example on CodePen.

    The functional part of the code is below. The content parameter is the PDF as a ByteArray. Convert the ByteArray into a Blob then add it to the FormData as you would any other file, then simply POST it to your server. The PHP side looks just like you uploaded a file.

    To run the demo, go to the CodePen, add a comment, then Save the file. The file will get sent to my server and then zipped; this is just to make it clear that the normal save function was replaced. You'll see the UI change to a message that will let you download the zipped file. Open the zip and you should see your commented PDF.

    adobeDCView.registerCallback(
        AdobeDC.View.Enum.CallbackType.SAVE_API,
        function (metaData, content, options) {
            var uint8Array = new Uint8Array(content);
            var blob = new Blob([uint8Array], { type: 'application/pdf' });
            formData = new FormData();
            var pdfFilename = urlToPDF.split("/").slice(-1)[0];
            pdfFilename = pdfFilename.split(".")[0] + "-" + uuidv4() + ".pdf";
            formData.append('pdfFile', blob, pdfFilename);
    
            var zipFileName = pdfFilename.replace(".pdf", ".zip");
    
            fetch("https://practicalpdf.com/code-pens/reflect/", {
                method: 'POST',
                body: formData,
            })
                .then(
                    function (response) {
                        if (response.status == 200) {
                            updateSaveUI(zipFileName);
                        }
                    }
                )
    
            return new Promise((resolve, reject) => {
                resolve({
                    code: AdobeDC.View.Enum.ApiResponseCode.SUCCESS,
                    data: {
                        metaData: { fileName: urlToPDF.split("/").slice(-1)[0] }
                    }
                });
            });
        },
        saveOptions
    );

      

    Participant
    August 17, 2021

    @Joel Geraci Excellent example, you almost solved my problem. I am a teacher and I want to use this method to collect student work back to my server. However I need a little more help. This code did not work when I used my server URL and figured out I may need a PHP code or something like that. I have no idea about PHP and whatever I tried did not work...Can you please guide or point me in the right direction...Sorry, I might have uploaded some student worksheets to your server while trying 🙂

    Community Manager
    January 20, 2021

    Yes, that should be possible. Please refer to the public facing Embed APIs documentation for Save API here.