bs-preview.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. var pdfFile = "";
  2. var userID;
  3. var idNum;
  4. $(function () {
  5. var containerHeight = $(document).height() - $("#content").position().top - 120;
  6. $("#container").height(containerHeight);
  7. userID = getUrlParam("userID");
  8. idNum = getUrlParam("idNum");
  9. $("#loading").show();
  10. $.post(rootPath + "/Home/GetPreview", { userID: userID, idNum: idNum }, function (res) {
  11. if (res.IsSuccess) {
  12. var url = res.Data;
  13. pdfFile = url;
  14. pdfjsLib.GlobalWorkerOptions.workerSrc = rootPath + '/Scripts/PlugIns/Pdf.js/pdf.worker.js';
  15. var loadingTask = pdfjsLib.getDocument(url);
  16. loadingTask.promise.then(function (pdf) {
  17. //
  18. // Fetch the first page
  19. //
  20. pdf.getPage(1).then(function (page) {
  21. var canvas = document.getElementById('content');
  22. var viewport = page.getViewport(1);
  23. var transform = 120 / 72;
  24. //var scale = canvas.width / viewport.width;
  25. //viewport = page.getViewport(scale);
  26. //
  27. // Prepare canvas using PDF page dimensions
  28. //
  29. var context = canvas.getContext('2d');
  30. canvas.height = viewport.height * transform;
  31. canvas.width = viewport.width * transform//$(document).width();
  32. //var context = document.getElementById('content');
  33. //
  34. // Render PDF page into canvas context
  35. //
  36. var renderContext = {
  37. transform: [transform, 0, 0, transform, 0, 0],
  38. canvasContext: context,
  39. viewport: viewport
  40. };
  41. page.render(renderContext);
  42. });
  43. });
  44. } else {
  45. alert("读取报表失败:" + res.Message + "请联系管理员。");
  46. }
  47. $("#loading").hide();
  48. resetTime();
  49. });
  50. });
  51. function print() {
  52. location.href = rootPath + "/Home/PrintView?userID=" + userID + "&idNum=" + idNum + "&pdfFile=" + pdfFile;
  53. // $.post(rootPath + "/Home/Print", { pdfFile: pdfFile }, function (res) {
  54. // if (res.IsSuccess) {
  55. // $("#loading").hide();
  56. // showError("打印完成,请取走您的成绩单。");
  57. // $.post(emisWeb + "/PrintServices/Count", { userID: userID }, function (res) {
  58. // resetTime();
  59. // }, 'json');
  60. // } else {
  61. // showError("打印失败:" + res.Message + ",请联系管理员。");
  62. // }
  63. // resetTime();
  64. // });
  65. }