iframe 打开base64文件流文件,文件流太大无法显示(PDF转base64展示问题)

189 阅读1分钟

iframe 打开base64文件流文件,文件流太大无法显示,解决方法

引用 (blog.csdn.net/weixin_4394…)


var fileBlob = base64ToBlob(Data.substring(Data.indexOf(',') + 1),'application/pdf');
var href = window.URL.createObjectURL(fileBlob);
	
strhtml += '<iframe id="img-attach" src="' + href + '#toolbar=0" "frameborder="0" scrolling="no" style="overflow: auto;text-align: center;border:0; top:0px; left:0px; bottom:0px; right:0px; width:100%; height:'+height+'px;"></iframe>';
document.getElementById("attach").innerHTML=strhtml;


function base64ToBlob(DataBase64,fileType){
	var raw = window.atob(DataBase64);
	var rawLength = raw.length;
	var uint8Array = new Uint8Array(rawLength);
	while (rawLength--){
		uint8Array[rawLength] = raw.charCodeAt(rawLength);
	}
	return new Blob([uint8Array],{type: fileType});
}