Skip to Content

I have a base64 encoded pdf content and want to view it using sap.m.PDFViwer. Since PDFViewer only accepts URI as source to display pdf:

So I should first create a blob url or a data url for my pdf content.

var base64EncodedPDF = "JVBERi0xLjcNCiW..."; // the encoded string
var decodedPdfContent = atob(base64EncodedPDF);
var byteArray = new Uint8Array(decodedPdfContent.length)
for(var i=0; i<decodedPdfContent.length; i++){
    byteArray[i] = decodedPdfContent.charCodeAt(i);
var blob = new Blob([byteArray.buffer], { type: 'application/pdf' });
var _pdfurl = URL.createObjectURL(blob);

However when I use this blob url as source of my PDFViewer, my pdf can’t be loaded at all however my blob url is accessible.

At last I find out that UI5 would validate the pdf url after rendering the PDFViewer dialog, only if my blob url is in the whitelist of UI5, my url can be considered as validated.

what I do is as below:

     this._PDFViewer = new sap.m.PDFViewer({
         source:_pdfurl // my blob url
     });"blob"); // register blob url as whitelist
this._PDFViewer.downloadPDF = function(){

The method addUrlWhitelist has four parameters., host, port, path);

After I added my blob url as whitelist then the pdf can be loaded successfully!


What happens in UI5?

line 269: PDFViewer try validate the source url

In, the method validateUrl would be executed:

And I can see from line 504(still in method validateUrl) why my blob url is now validated after doing addUrlWhiteList, the protocal,host,port and path would be checked:


The PDFViewer loads my pdf as below:

To report this post you need to login first.


You must be Logged on to comment or reply to a post.

  1. Alfredo Semeco Blanco

    Hi, @Vicky Chen

    I have a issue  when I try to load a pdf in my pdfviewer fiori app in fiori client Android. The  android system show a message refering a visor problem ( having install yet pdf visor  like adobe reader and others) and never load the pdf file so if you know how to handle this issue or what can i do?. I have tried with, <iframe src= url>, <object data= url>, <embed src= url> and your solution but nothing happen just in Android. In iOS and Web your solution works fine when i test the app. thanks you!


Leave a Reply