index.html 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover">
  6. <title>PDF预览</title>
  7. <style>
  8. * {
  9. margin: 0;
  10. padding: 0;
  11. box-sizing: border-box;
  12. }
  13. body {
  14. height: 100vh;
  15. overflow: hidden;
  16. background-color: #FFFFFF;
  17. }
  18. #pdf-container {
  19. width: 100%;
  20. height: 100%;
  21. }
  22. .loading {
  23. position: fixed;
  24. top: 50%;
  25. left: 50%;
  26. transform: translate(-50%, -50%);
  27. font-size: 14px;
  28. color: #666;
  29. }
  30. </style>
  31. </head>
  32. <body>
  33. <div id="pdf-container"></div>
  34. <div class="loading" id="loading">加载中...</div>
  35. <script src="js/pdfh5.js"></script>
  36. <script>
  37. document.addEventListener('DOMContentLoaded', function() {
  38. var urlParams = new URLSearchParams(window.location.search);
  39. var pdfUrl = urlParams.get('url');
  40. if (!pdfUrl) {
  41. document.getElementById('loading').textContent = '未找到PDF文件';
  42. return;
  43. }
  44. var container = document.getElementById('pdf-container');
  45. var pdfh5 = new Pdfh5(container, {
  46. pdfurl: decodeURIComponent(pdfUrl),
  47. zoomScale: [0.5, 2],
  48. maxZoom: 2,
  49. minZoom: 0.5,
  50. showZoom: false,
  51. showFullScreen: false,
  52. showRotate: false,
  53. showProgress: true,
  54. progressBar: true,
  55. progressBarColor: '#2E64FA',
  56. renderType: 'canvas',
  57. curNumMode: 'number',
  58. lazy: true,
  59. withCredentials: true
  60. });
  61. pdfh5.on('complete', function(status, msg, time) {
  62. document.getElementById('loading').style.display = 'none';
  63. if (status === 'error') {
  64. console.error('PDF加载失败:', msg);
  65. }
  66. });
  67. pdfh5.on('error', function(error) {
  68. document.getElementById('loading').style.display = 'none';
  69. console.error('PDF加载错误:', error);
  70. });
  71. });
  72. </script>
  73. </body>
  74. </html>