• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

913

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
Community Expert ,
Feb 18, 2021 Feb 18, 2021

Copy link to clipboard

Copied

LATEST

What are you using to manipulate the PDF?

Votes

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
Resources