我需要显示一个带有数据的 PDF 文件,这个数据是 data:application/pdf;base64, @Session["Pdf"] 。
所以这个过程在我的机器上工作我打开 PDF 并自动显示 PDF 并在 GOOGLE CHROME 中显示数据。
问题是当我在 web 环境或 IE 中进行此过程时,HTML 页面不显示任何内容。
1 暂定
<body>
<object data="data:application/pdf;base64, @Session["Pdf"]" type="application/pdf" style="width: 100%; height: 100%;" frameborder="0" scrolling="no">
<p>It appears you don't have Adobe Reader or PDF support in this web browser. </p>
<embed src="data:application/pdf;base64, @Session["Pdf"]" type="application/pdf" />
</object>
</body>
2 暂定
<div class="modal-body">
<iframe src="data:application/pdf;base64, @Session["Pdf"]" style="width: 100%; height: 100%;" frameborder="0" scrolling="no">
@*<embed src="@Session["Pdf"]"></embed>*@
</div>
3 st
<script type="text/javascript">
var data= "data:application/pdf;base64,@Session["Pdf"]" ;
if (data == "" || data == undefined) {
alert("Falied to open PDF.");
} else {
//For IE using atob convert base64 encoded data to byte array
if (window.navigator && window.navigator.msSaveOrOpenBlob) {
var byteCharacters = atob(data);
var byteNumbers = new Array(byteCharacters.length);
for (var i = 0; i < byteCharacters.length; i++) {
byteNumbers[i] = byteCharacters.charCodeAt(i);
}
var byteArray = new Uint8Array(byteNumbers);
var blob = new Blob([byteArray], {
type: 'application/pdf'
});
window.navigator.msSaveOrOpenBlob(blob, fileName);
} else {
// Directly use base 64 encoded data for rest browsers (not IE)
var base64EncodedPDF = data;
var dataURI = "data:application/pdf;base64," + base64EncodedPDF1;
window.open(dataURI, '_blank');
}
}
</script>