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

lookPdf.js 3.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. var qs = parseQueryString(window.location.href),user_id,contract_url;
  2. var request = '';
  3. $().ready(function(){
  4. if(qs.user_id){user_id = qs.user_id}
  5. if(qs.contract_url){
  6. contract_url=qs.contract_url
  7. }
  8. // if(!getCookie('user_id') || getCookie('user_id') != user_id){
  9. // window.location.href="index.html"
  10. // }
  11. showPdf('http://media-sign.oss-cn-beijing.aliyuncs.com/Contract/20200701/dev5efc749a450e7_user_id_8.pdf');
  12. })
  13. function showPdf(url) {
  14. // const CMAP_URL = 'https://unpkg.com/pdfjs-dist@2.0.489/cmaps/';
  15. // pdfjsLib.GlobalWorkerOptions.workerSrc ='./pdf.worker.js';//自己的路径
  16. // var loadingTask = pdfjsLib.getDocument({
  17. // data: url,
  18. // cMapUrl: CMAP_URL,
  19. // cMapPacked: true,
  20. // });
  21. // loadingTask.promise.then(function(pdfDoc_) {
  22. // console.log(pdfDoc_)
  23. // // pdfDoc = pdfDoc_;
  24. // // document.getElementById('page_count').textContent = pdfDoc.numPages;
  25. // // // Initial/first page rendering
  26. // // renderPage(pageNum);
  27. // });
  28. // return;
  29. pdfjsLib.workerSrc = 'js/pdf.worker.js';
  30. pdfjsLib.getDocument(url).then(function getPdfHelloWorld(pdf) {
  31. console.log(pdf)
  32. var $pop = $('#pop');
  33. var shownPageCount = pdf.numPages < 50 ? pdf.numPages : 50;//设置显示的编码
  34. var getPageAndRender = function (pageNumber) {
  35. pdf.getPage(pageNumber).then(function getPageHelloWorld(page) {
  36. var scale = 1.8;
  37. var viewport = page.getViewport(scale);
  38. var $canvas = $('<canvas></canvas>').attr({
  39. 'height': viewport.height,
  40. 'width': viewport.width,
  41. });
  42. $pop.append($canvas);
  43. page.render({
  44. canvasContext: $canvas[0].getContext('2d'),
  45. viewport: viewport
  46. });
  47. });
  48. if (pageNumber < shownPageCount) {
  49. pageNumber++;
  50. getPageAndRender(pageNumber);
  51. }
  52. };
  53. getPageAndRender(1);
  54. });
  55. }
  56. //获取地址栏参数
  57. function parseQueryString(url) {
  58. var urlObj = {};
  59. var reg = /([^?=&]+)=([^?=&]+)/g;
  60. url.replace(reg, function($0, $1, $2) {
  61. urlObj[$1] = decodeURIComponent($2);
  62. })
  63. return urlObj;
  64. }
  65. // 展示错误提示信息
  66. function showMsg(msg) {
  67. var msgBox = document.getElementsByClassName('alert-info')[0];
  68. msgBox.getElementsByTagName("p")[0].innerHTML=msg;
  69. msgBox.style.display="block";
  70. setTimeout(function() {
  71. msgBox.style.display="none";
  72. }, 2000);
  73. }
  74. //取Cookie的值
  75. function getCookie(name) {
  76. var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
  77. if (arr = document.cookie.match(reg)){
  78. return arr[2];
  79. }else{
  80. return false
  81. }
  82. }
  83. //写入到Cookie
  84. //name:cookie名称 value:cookie值
  85. function setCookie(name,value){
  86. var exp = new Date();
  87. exp.setTime(exp.getTime() + 12 * 60 * 60000);//过期时间 12小时
  88. // exp.setTime(exp.getTime() + 60 * 10000);//过期时间 10分钟
  89. document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
  90. }