Skip to main content
Participant
February 18, 2021
Question

Download PDF as $.ajax() showing blank pages.

  • February 18, 2021
  • 1 reply
  • 1341 views

I am using Embed API. I download pdf using $.ajax() and then load pdf as

function loadPdf(pdfPath) {
        window.adobeDCView = new AdobeDC.View({clientId: adobeApiKeyStaging, divId: "adobe-dc-view"});
        adobeDCView.previewFile({
            content: { promise: Promise.resolve(stringToArrayBuffer(pdfPath)) },
            metaData:{fileName: "Test1.pdf"}
        }, viewerConfig);
    }

I convert string to Array Buffer and feel its not coverting correctly or Promise.resolve() require something else ?

function stringToArrayBuffer2(bin) {
        var len = bin.length;
        var uInt8Array = new Uint8Array(len);
        for (var i = 0; i < len; i++) {
            uInt8Array[i] = bin.charCodeAt(i);
        }
        return uInt8Array.buffer;
}

If I send base64 from server then its working fine, but when I read raw pdf data then its showing blank pages. Following example is also working fine.

function fetchPDF(urlToPDF) {
        return new Promise((resolve) => {
            fetch(urlToPDF)
            .then((resolve) => resolve.blob())
            .then((blob) => {
                resolve(blob.arrayBuffer())
            })
        })
}

but problem with above method is that I need some manuplation with pdf data before send it to show pdf function. 

    This topic has been closed for replies.

    1 reply

    Joel Geraci
    Community Expert
    Community Expert
    February 18, 2021

    What are you using to manipulate the PDF?