Skip to main content
Known Participant
July 31, 2020
Question

Embed API using base64 string of PDF

  • July 31, 2020
  • 4 replies
  • 10656 views

 

adobeDCView.previewFile({
      content: base64str,
      metaData:{fileName: "check.pdf"}
    },

 

I have not been successful in using the EmbedAPI when the PDF is a base64hex string. Does the content object of the Preview method support it. If so how? I tried some of the options but it gives content error

Thanks,

This topic has been closed for replies.

4 replies

Participant
July 28, 2021

I tried replicating this, but it does not load the viewer at all. Neither an I getting any errors or console logs. 
Am I doing something wrong?
The viewer was working perfectly for the URL
@Shubhanshu Dixit 
@Joel Geraci  - your codepen is not showing the viewer

 

var resp : {"content": "JVBERi0xLjMKJcTl8uXrp/Og0MTGCjQgMCBvYmoKPDwgL0xlbmd0aCA1IDAgUiAvRmlsdGVyIC9GbGF0ZURlY29kZSA+PgpzdHJlYW0KeAGtnOtv5MaRwL/PX8HLl5OANc3345AEcBwfcsZdgtgCcsBtPmhHs9bauzOyHnaMQ/....."
};

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

 var previewFilePromise = adobeDCView.previewFile(
       {
        content: { promise: Promise.resolve(base64ToArrayBuffer(resp.content)) },
          metaData: {fileName: "Bodea Brochure.pdf", id: "12345ghb"}
       }, {
         enableSearchAPIs:true,
       });

 

Joel Geraci
Community Expert
Community Expert
July 28, 2021

@vedika0101  - I'm seeing the viewer just fine in Chrome. What browser are you using? 

Joel Geraci
Community Expert
Community Expert
July 31, 2020

I've posted a working CodePen here.

R.M.RAuthor
Known Participant
July 31, 2020

Thanks Joel. That looks helpful. It's rather late this part of the world. I will give this a try in my web component tomorrow. 

Community Manager
July 31, 2020

No, PDF Embed APIs don't support base64 encoded PDF. Please find more information on Embed APIs here - https://www.adobe.io/apis/documentcloud/dcsdk/docs.html. You can however, open file in your application, convert from base 64 and pass converted blob to Embed APIs. Help documentation also describes how to pass file blob. 

R.M.RAuthor
Known Participant
July 31, 2020

Hello Brajesh:

 

Thanks for this. In fact, I am doing something similar but I seem stuck at understanding the content promise.

 

Here is what I am doing. I am reading the file (from a secure drive with auth) as a blob. I tried serving it as:

 

adobeDCView.previewFile({
 content: blob,
 metaData: { fileName: "test.pdf" }
 },
 {
   embedMode: "SIZED_CONTAINER"
 });

 

It gives a content error

R.M.RAuthor
Known Participant
July 31, 2020

I even tried

 

var filePromise = blob.arrayBuffer();
..
adobeDCView.previewFile({
  content: {promise: filePromise},
  metaData: { fileName: "test.pdf" }
}

This too brought up the adobe viewer with a content error

 

Participant
July 31, 2020
Can you please send me more information about this