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

Community Beginner ,
Feb 18, 2021 Feb 18, 2021

Copy link to clipboard

Copied

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. 

Views

49

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Feb 18, 2021 Feb 18, 2021

Copy link to clipboard

Copied

LATEST

What are you using to manipulate the PDF?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines