pdf.html 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="apple-mobile-web-app-capable" content="yes">
  6. <meta name="apple-mobile-web-app-status-bar-style" content="black">
  7. <meta name="format-detection" content="telephone=no" />
  8. <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
  9. <meta http-equiv="pragma" content="no-cache">
  10. <meta http-equiv="cache-control" content="no-cache">
  11. <meta http-equiv="expires" content="0">
  12. <title>PDF</title>
  13. <link rel="stylesheet" href="html/pdf/style.css" />
  14. <link rel="stylesheet" href="html/pdf/pdfh5.css" />
  15. <style>
  16. html,body {
  17. width: 100%;
  18. height: 100%;
  19. }
  20. </style>
  21. </head>
  22. <body>
  23. <div id="pdf-view"></div>
  24. <script src="./pdf/pdf.js"></script>
  25. <script src="./pdf/pdf.worker.js"></script>
  26. <script src="./pdf/jquery-1.11.3.min.js" type="text/javascript" charset="utf-8"></script>
  27. <script src="./pdf/pdfh5.js" type="text/javascript" charset="utf-8"></script>
  28. <script type="text/javascript">
  29. var pdfh5;
  30. $(function() {
  31. $("#pdf-view").show()
  32. var url = getQuery('url');
  33. pdfh5 = new Pdfh5('#pdf-view', {
  34. pdfurl: url,
  35. // background:{
  36. // image:"url('pdfh5.png')",
  37. // repeat:"no-repeat",
  38. // position:"left top",
  39. // size:"40px 40px"
  40. // },
  41. URIenable:true //开启浏览器地址栏file参数获取
  42. });
  43. //pdf准备开始渲染,此时可以拿到pdf总页数
  44. pdfh5.on("ready", function() {
  45. console.log("pdf准备开始渲染,总页数:" + this.totalNum)
  46. })
  47. //监听pdf渲染成功
  48. pdfh5.on("success", function(time) {
  49. time = time / 1000
  50. console.log("pdf渲染完成,总耗时" + time + "秒");
  51. })
  52. })
  53. function getQuery(name) {
  54. // 正则:[找寻'&' + 'url参数名字' = '值' + '&']('&'可以不存在)
  55. let reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
  56. let r = window.location.search.substr(1).match(reg);
  57. if(r != null) {
  58. // 对参数值进行解码
  59. return decodeURIComponent(r[2]);
  60. }
  61. return null;
  62. }
  63. </script>
  64. </body>
  65. </html>