1.功能介绍
PDF.js是Mozilla公司开发的pdf浏览器展示组件,项目主页位于https://github.com/mozilla/pdf.js
PDF.js支持火狐、谷歌和IE(9及以上)等浏览器。
2.示例
直接使用Mozilla提供的代码,见示例文件夹PDFViewer。文件夹中除1.html外都是Mozilla官方案例提供。
我们采用将Mozilla提供的PDF展示页面viewer.html通过iframe内嵌的方式展示在我们自己的页面中
<iframe id="pdfFrame" src="viewer.html" style="width:800px;height:500px" />
通过设置页面的参数file指定待展示的pdf访问路径
<script>
showPdf = function(file){
document.getElementById("pdfFrame").src="viewer.html?file="+file;
}
</script>
<button onclick="showPdf('file/Oracle12c Development Guide.pdf')">show1</button>
<button onclick="showPdf('file/compressed.tracemonkey-pldi-09.pdf')">show2</button>