Skip to Content
0
Oct 08, 2020 at 09:08 AM

Binary data from ajax call reponse to sap.m.PDFViewer now working

294 Views

hi Team,

Am using below code to fetch the pdf file in the form of blob , currently we are able to download the file, but am unable to set the same to the PDF Viewer , kindly do the needful.

Code for Downloading the PDF File

xhr.onreadystatechange = function() 
{ 
	if (xhr.readyState == 4 && xhr.status == 200)
	{
		var blob 		= this.response;
            const blobURL = window.URL.createObjectURL(new Blob([blob], { type: 'application/pdf' }));
		var downloadLink 	= window.document.createElement('a');
		var contentTypeHeader   = xhr.getResponseHeader("Content-Type");
		downloadLink.href 	= blobURL ;              
		downloadLink.download 	= "file.pdf" ;
		document.body.appendChild(downloadLink);
		downloadLink.click();
              //----------------CODE FOR SETTING TO PDF VIEWER----------------------------------------  
              sap.ui.getCore().byId("pdf_viewer").setSource(blobURL);
            //------------------CODE FOR SETTING TO PDF VIEWER---------------------------------------
	}
}

Regards

Govardan

Attachments

attachment.png (13.3 kB)