使用PDF.JS在线查看PDF

过程简单粗暴。

第一步:下载源码https://github.com/mozilla/pdf.js

第二步:将源码拷贝进项目中,可以新建一个PDFShow文件夹存放代码

第三步:修改viewer.js

var DEFAULT_URL 'compressed.tracemonkey-pldi-09.pdf'  里面是PDF的路径

修改为:var DEFAULT_URL '';

发布IIS后访问localhost:8080/PDFShow/web/viewer.html?file=09.pdf即可。

打开新窗口的代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
 
<script language="javascript">
    function tanchu(a) {
         
    }
</script>
<body>
    <a href="#" onclick="window.open('web/viewer.html?file=09.pdf','PDF','50%;height:50%;top:100;left:100;');">查看09.pdf</a>
</body>
</html>

 

-------------------------------2017-07-13 13:01的分割线-------------------------------

文章年久失修,使用案例可参阅官方Demo

插件官方的例子:http://mozilla.github.io/pdf.js/examples/

 

这是我在官方上的例子修改了url之后的Demo示例:http://jsfiddle.net/9engc9mw/582/

原文地址:https://www.cnblogs.com/hzcya1995/p/13317515.html