新媒体-合同签约,CA签约

pdfceshi.html 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <html>
  2. <head>
  3. <title>pdf.js展示1,上一页,下一页</title>
  4. </head>
  5. <h1>PDF.js Previous/Next example</h1>
  6. <div>
  7. <button id="prev">Previous</button>
  8. <button id="next">Next</button>
  9. &nbsp; &nbsp;
  10. <span>Page: <span id="page_num"></span> / <span id="page_count"></span></span>
  11. </div>
  12. <canvas id="the-canvas"></canvas>
  13. <script src="./pdf.js"></script>
  14. <script src="./pdf.worker.js"></script>
  15. <script>
  16. var url = 'http://new-media-ca.oss-cn-beijing.aliyuncs.com/upload/ca_signs/2020-09-04/kx-5f52369304d06.pdf';
  17. var pdfDoc = null,
  18. pageNum = 1,
  19. pageRendering = false,
  20. pageNumPending = null,
  21. scale = 0.8,
  22. canvas = document.getElementById('the-canvas'),
  23. ctx = canvas.getContext('2d');
  24. /**
  25. * Get page info from document, resize canvas accordingly, and render page.
  26. * @param num Page number.
  27. */
  28. function renderPage(num) {
  29. pageRendering = true;
  30. // Using promise to fetch the page
  31. pdfDoc.getPage(num).then(function(page) {
  32. var viewport = page.getViewport(scale);
  33. canvas.height = viewport.height;
  34. canvas.width = viewport.width;
  35. // Render PDF page into canvas context
  36. var renderContext = {
  37. canvasContext: ctx,
  38. viewport: viewport
  39. };
  40. var renderTask = page.render(renderContext);
  41. // Wait for rendering to finish
  42. renderTask.promise.then(function() {
  43. pageRendering = false;
  44. if (pageNumPending !== null) {
  45. // New page rendering is pending
  46. renderPage(pageNumPending);
  47. pageNumPending = null;
  48. }
  49. });
  50. });
  51. // Update page counters
  52. document.getElementById('page_num').textContent = num;
  53. }
  54. /**
  55. * If another page rendering in progress, waits until the rendering is
  56. * finised. Otherwise, executes rendering immediately.
  57. */
  58. function queueRenderPage(num) {
  59. if (pageRendering) {
  60. pageNumPending = num;
  61. } else {
  62. renderPage(num);
  63. }
  64. }
  65. /**
  66. * Displays previous page.
  67. */
  68. function onPrevPage() {
  69. if (pageNum <= 1) {
  70. return;
  71. }
  72. pageNum--;
  73. queueRenderPage(pageNum);
  74. }
  75. document.getElementById('prev').addEventListener('click', onPrevPage);
  76. /**
  77. * Displays next page.
  78. */
  79. function onNextPage() {
  80. if (pageNum >= pdfDoc.numPages) {
  81. return;
  82. }
  83. pageNum++;
  84. queueRenderPage(pageNum);
  85. }
  86. document.getElementById('next').addEventListener('click', onNextPage);
  87. /**
  88. * Asynchronously downloads PDF.
  89. */
  90. const CMAP_URL = 'https://unpkg.com/pdfjs-dist@2.0.489/cmaps/';
  91. pdfjsLib.GlobalWorkerOptions.workerSrc ='./pdf.worker.js';//自己的路径
  92. var loadingTask = pdfjsLib.getDocument({
  93. data: url,
  94. cMapUrl: CMAP_URL,
  95. cMapPacked: true,
  96. });
  97. loadingTask.promise.then(function(pdfDoc_) {
  98. pdfDoc = pdfDoc_;
  99. document.getElementById('page_count').textContent = pdfDoc.numPages;
  100. // Initial/first page rendering
  101. renderPage(pageNum);
  102. });
  103. // const loadingTask = pdfjsLib.getDocument(/* data here */);
  104. // loadingTask.promise.then(pdfDocument => {
  105. // // The document is loaded here...
  106. // });
  107. </script>
  108. </html>