Ben
Ben

Reputation: 680

Adobe PDF Embed API Save PDF to Firestore

Using Adobe PDF Embed API and want to save annotated PDFs in a browser window to Firestore. The file is uploaded to Firebase but corrupt and only about 9 bytes in size. Please see the below code. Is there something I need to do with "content" in the callback? Attached also a picture of the console.log.enter image description here

    const previewConfig = {
        embedMode: "FULL_WINDOW",
        showAnnotationTools: true,
        showDownloadPDF: true,
        showPrintPDF: true,
        showPageControls: true
    }

    document.addEventListener("adobe_dc_view_sdk.ready", function () {
        var adobeDCView = new AdobeDC.View({
            clientId: "2eab88022c63447f8796b580d5058e71",
            divId: "adobe-dc-view"
        });
        adobeDCView.previewFile({
            content: { location: { url: decoded } },
            metaData: { fileName: decodedTitle }
        }, previewConfig);

        /* Register save callback */
        adobeDCView.registerCallback(
            AdobeDC.View.Enum.CallbackType.SAVE_API,
            async function (metaData, content, options) {
                console.log(metaData);
                console.log(content);
                var meta = {
                    contentType: 'application/pdf'
                };
                var pdfRef = storageRef.child(decodedTitle);
                var upload = await pdfRef.put(content, meta);
                console.log('Uploaded a file!');
                return new Promise(function (resolve, reject) {
                    /* Dummy implementation of Save API, replace with your business logic */
                    setTimeout(function () {
                        var response = {
                            code: AdobeDC.View.Enum.ApiResponseCode.SUCCESS,
                            data: {
                                metaData: Object.assign(metaData, { updatedAt: new Date().getTime() })
                            },
                        };
                        resolve(response);
                    }, 2000);
                });
            }
        );

    });

Upvotes: 0

Views: 454

Answers (1)

Ben
Ben

Reputation: 680

I was able to use putString() in Firebase Storage to upload the PDF to storage in the end. Before I was only using put() which ended up having a corrupt file.

Upvotes: 0

Related Questions