var qs = parseQueryString(window.location.href),user_id,contract_url; var request = ''; $().ready(function(){ if(qs.user_id){user_id = qs.user_id} if(qs.contract_url){ contract_url=qs.contract_url } // if(!getCookie('user_id') || getCookie('user_id') != user_id){ // window.location.href="index.html" // } showPdf('http://media-sign.oss-cn-beijing.aliyuncs.com/Contract/20200701/dev5efc749a450e7_user_id_8.pdf'); }) function showPdf(url) { // const CMAP_URL = 'https://unpkg.com/pdfjs-dist@2.0.489/cmaps/'; // pdfjsLib.GlobalWorkerOptions.workerSrc ='./pdf.worker.js';//自己的路径 // var loadingTask = pdfjsLib.getDocument({ // data: url, // cMapUrl: CMAP_URL, // cMapPacked: true, // }); // loadingTask.promise.then(function(pdfDoc_) { // console.log(pdfDoc_) // // pdfDoc = pdfDoc_; // // document.getElementById('page_count').textContent = pdfDoc.numPages; // // // Initial/first page rendering // // renderPage(pageNum); // }); // return; pdfjsLib.workerSrc = 'js/pdf.worker.js'; pdfjsLib.getDocument(url).then(function getPdfHelloWorld(pdf) { console.log(pdf) var $pop = $('#pop'); var shownPageCount = pdf.numPages < 50 ? pdf.numPages : 50;//设置显示的编码 var getPageAndRender = function (pageNumber) { pdf.getPage(pageNumber).then(function getPageHelloWorld(page) { var scale = 1.8; var viewport = page.getViewport(scale); var $canvas = $('').attr({ 'height': viewport.height, 'width': viewport.width, }); $pop.append($canvas); page.render({ canvasContext: $canvas[0].getContext('2d'), viewport: viewport }); }); if (pageNumber < shownPageCount) { pageNumber++; getPageAndRender(pageNumber); } }; getPageAndRender(1); }); } //获取地址栏参数 function parseQueryString(url) { var urlObj = {}; var reg = /([^?=&]+)=([^?=&]+)/g; url.replace(reg, function($0, $1, $2) { urlObj[$1] = decodeURIComponent($2); }) return urlObj; } // 展示错误提示信息 function showMsg(msg) { var msgBox = document.getElementsByClassName('alert-info')[0]; msgBox.getElementsByTagName("p")[0].innerHTML=msg; msgBox.style.display="block"; setTimeout(function() { msgBox.style.display="none"; }, 2000); } //取Cookie的值 function getCookie(name) { var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)"); if (arr = document.cookie.match(reg)){ return arr[2]; }else{ return false } } //写入到Cookie //name:cookie名称 value:cookie值 function setCookie(name,value){ var exp = new Date(); exp.setTime(exp.getTime() + 12 * 60 * 60000);//过期时间 12小时 // exp.setTime(exp.getTime() + 60 * 10000);//过期时间 10分钟 document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString(); }