PDF.js是一款基於HTML5創建的PDF閱讀器,兼容大部分主流的瀏覽器,使用起來,也相對簡單。步驟以下:html
下載地址:http://mozilla.github.io/pdf....git
建新文件夾,將PDF.js插件文件放入新建的文件夾。github
在HTML文件代碼以下:web
<!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"; window.open("pdfjs/web/viewer.html?file=" + url); } </script> </head> <body> <input type="button" onclick="openFile()" value="打開"> </body> </html>
注意:由於pdf.js須要依賴http,https協議。因此直接瀏覽index打開報錯。搭個服務,或者用idea的瀏覽就能夠了。瀏覽器