var pdfFile = ""; var userID; var idNum; $(function () { var containerHeight = $(document).height() - $("#content").position().top - 120; $("#container").height(containerHeight); userID = getUrlParam("userID"); idNum = getUrlParam("idNum"); $("#loading").show(); $.post(rootPath + "/Home/GetPreview", { userID: userID, idNum: idNum }, function (res) { if (res.IsSuccess) { var url = res.Data; pdfFile = url; pdfjsLib.GlobalWorkerOptions.workerSrc = rootPath + '/Scripts/PlugIns/Pdf.js/pdf.worker.js'; var loadingTask = pdfjsLib.getDocument(url); loadingTask.promise.then(function (pdf) { // // Fetch the first page // pdf.getPage(1).then(function (page) { var canvas = document.getElementById('content'); var viewport = page.getViewport(1); var transform = 120 / 72; //var scale = canvas.width / viewport.width; //viewport = page.getViewport(scale); // // Prepare canvas using PDF page dimensions // var context = canvas.getContext('2d'); canvas.height = viewport.height * transform; canvas.width = viewport.width * transform//$(document).width(); //var context = document.getElementById('content'); // // Render PDF page into canvas context // var renderContext = { transform: [transform, 0, 0, transform, 0, 0], canvasContext: context, viewport: viewport }; page.render(renderContext); }); }); } else { alert("读取报表失败:" + res.Message + "请联系管理员。"); } $("#loading").hide(); resetTime(); }); }); function print() { location.href = rootPath + "/Home/PrintView?userID=" + userID + "&idNum=" + idNum + "&pdfFile=" + pdfFile; // $.post(rootPath + "/Home/Print", { pdfFile: pdfFile }, function (res) { // if (res.IsSuccess) { // $("#loading").hide(); // showError("打印完成,请取走您的成绩单。"); // $.post(emisWeb + "/PrintServices/Count", { userID: userID }, function (res) { // resetTime(); // }, 'json'); // } else { // showError("打印失败:" + res.Message + ",请联系管理员。"); // } // resetTime(); // }); }