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

pdfceshi copy.html 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <html>
  2. <head>
  3. <script src="./pdf.js"></script>
  4. <script src="./common/jquery-2.1.0.js"></script>
  5. </head>
  6. <body>
  7. <input type="file" id="file">
  8. <div id="pop"></div>
  9. </body>
  10. <script>
  11. pdfjsLib.GlobalWorkerOptions.workerSrc = './pdf.worker.js';
  12. document.getElementById('file').onchange = function(event) {
  13. var file = event.target.files[0];
  14. var fileReader = new FileReader();
  15. fileReader.onload = function() {
  16. var typedarray = new Uint8Array(this.result);
  17. console.log(typedarray);
  18. const CMAP_URL = 'https://unpkg.com/pdfjs-dist@2.0.489/cmaps/';
  19. // pdfjsLib.GlobalWorkerOptions.workerSrc ='./pdf.worker.js';//自己的路径
  20. var loadingTask = pdfjsLib.getDocument({
  21. data: typedarray,
  22. cMapUrl: CMAP_URL,
  23. cMapPacked: true,
  24. });
  25. loadingTask.promise.then(function(pdf) {
  26. console.log(pdf)
  27. var $pop = $('#pop');
  28. var shownPageCount = pdf.numPages < 50 ? pdf.numPages : 50;//设置显示的编码
  29. var getPageAndRender = function (pageNumber) {
  30. pdf.getPage(pageNumber).then(function getPageHelloWorld(page) {
  31. var scale = 1.8;
  32. var viewport = page.getViewport(scale);
  33. var $canvas = $('<canvas></canvas>').attr({
  34. 'height': viewport.height,
  35. 'width': viewport.width,
  36. });
  37. $pop.append($canvas);
  38. page.render({
  39. canvasContext: $canvas[0].getContext('2d'),
  40. viewport: viewport
  41. });
  42. });
  43. if (pageNumber < shownPageCount) {
  44. pageNumber++;
  45. getPageAndRender(pageNumber);
  46. }
  47. };
  48. getPageAndRender(1);
  49. });
  50. };
  51. fileReader.readAsArrayBuffer(file);
  52. }
  53. </script>
  54. </html>