使⽤PDF.JS插件在HTML中预览PDF⽂件的⽅法PDF.js是⼀款基于HTML5建⽴的PDF阅读器,兼容⼤部分主流的浏览器,使⽤起来,也相对简单。步骤如下:
1.下载PDF.js插件
2.⽂件部署
建新⽂件夹,将PDF.js插件⽂件放⼊新建的⽂件夹。
3.新建index.html
在HTML⽂件代码如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="google" content="notranslate">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>《使⽤指南》-柠檬课件</title>
<script>
function openFile () {
var url = "pdf.pdf";
script在html中的用法
window.open("pdfjs/web/viewer.html?file=" + url);
}
</script>
</head>
<body>
<input type="button" onclick="openFile()" value="打开">
</body>
</html>
4.将pdf.pdf⽂件放到pdfjs/web/下
5.点击浏览即可。
注意:因为pdf.js需要依赖http,https协议。所以直接浏览index打开报错。搭个服务,或者⽤idea的浏览就可以了。以上就是本⽂的全部内容,希望对⼤家的学习有所帮助,也希望⼤家多多⽀持。