This is for hybrid application which runs in android mobile webview container but has mvc code behind. That's why I cannot use window.open to show pdf.
I need to use iframe or embed may be to show it on the mvc view.
I get data as bytes from database.
byte[] RptData;
SqlReportData = reader.GetSqlBytes(0);
RptData = SqlReportData.Value;
return RptData;
then I convert it to Base64String and pass in viewModel.
viewModel.PdfDataString = Convert.ToBase64String(pdfData);
I tried pretty much top suggestions I could find but none of them working for me.
Iframe src set large base64 data
how to display base64 encoded pdf?
Display ASP.NET generated pdf byte[] to web page without saving the file
<div><iframe src="" type="application/pdf"></iframe>
</div>
<div>
<embed src="" width="100%" height="100%" type="application/pdf"/>
</div>
<script>
var pdfData = '@Model.PdfDataString';
$("iframe").attr("src", 'data:application/pdf;base64,{0}'.replace('{0}', pdfData));
$("embed").attr("src", 'data:application/pdf;base64,{0}'.replace('{0}', pdfData));
</script>
I want to show this Base64String data as pdf on mvc view. I am trying with iframe and embed both. iframe shows blank and embed is not displaying.
Chrome debugger shows:
Resource interpreted as Document but transferred with MIME type application/pdf: "data:application/pdf;base64,JVBERi0xLjcKCjQgMCB....(ShowMore 1.6MB)