方式一:(仅适用于IE且计算机安装有pdf阅读器)
方式二:(仅适用于IE且计算机安装有pdf阅读器)
方式三:(不推荐兼容性太差)
使用PDFObject.js 插件;
方式四:(推荐使用)
使用pdf.js插件
项目中引入pdf.js插件插件后
要显示的jsp页面:
注:static为存放pdf.js插件的文件夹,一般放在webapp下,web-inf上级;
generic为pdf.js的插件文件夹;
viewer.html为pdf.js差价问价下的视图文件,当?file参数为空或不传时会跳到pdf.js的默认页面;
要使pdf高度变为100%,需要去掉
标准中的“Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd”即可。
Insert title herewindow.onload = function (){
var iframe = document.getElementById("showIframe");
//文件url
var fileUrl = '';
//jsp页面提取文件时的路径 转码方式 encodeURIComponent(filepath)或 encodeURI(encodeURI(filepath))
var filepath = "../../../"+fileUrl;
iframe.src = "/static/generic/web/viewer.html?file="+encodeURIComponent(filepath);
};