newPdf.html 933 B

1234567891011121314151617181920212223242526272829303132333435
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <script src="pdf.js"></script>
  5. </head>
  6. <body>
  7. <div id="pdfViewer"></div>
  8. <script>
  9. var pdfViewer = document.getElementById('pdfViewer');
  10. var pdfUrl = "E:\\pdf\\DM8_DIsql使用手册.pdf";
  11. PDFJS.getDocument(pdfUrl).then(function (pdfDoc) {
  12. var totalPages = pdfDoc.numPages;
  13. for (var i = 1; i <= totalPages; i++) {
  14. pdfDoc.getPage(i).then(function (page) {
  15. var canvas = document.createElement('canvas');
  16. pdfViewer.appendChild(canvas);
  17. var context = canvas.getContext('2d');
  18. var viewport = page.getViewport(canvas.width / page.getViewport(1.0).width);
  19. canvas.height = viewport.height;
  20. page.render({
  21. canvasContext: context,
  22. viewport: viewport
  23. });
  24. });
  25. }
  26. });
  27. </script>
  28. </body>
  29. </html>