From 7f9d89331a1ecafffd9cef7293cdbdd3a8b289b6 Mon Sep 17 00:00:00 2001
From: 李金换 <lijinhuan@prec-tech.com>
Date: 星期二, 19 四月 2022 13:45:24 +0800
Subject: [PATCH] HWAG-CAV5WX职位
---
force-app/main/default/pages/QISPDF.page | 212 ++++++++++++++++++++++++++++++++++------------------
1 files changed, 139 insertions(+), 73 deletions(-)
diff --git a/force-app/main/default/pages/QISPDF.page b/force-app/main/default/pages/QISPDF.page
index 073c274..9fa3336 100644
--- a/force-app/main/default/pages/QISPDF.page
+++ b/force-app/main/default/pages/QISPDF.page
@@ -22,8 +22,8 @@
/* 20220221 PI鏀归�� by 寰愪寒 start */
body{margin: 0 auto;
width: 780px;}
- #title1{height: 30px;}
- #title2{height: 110px;}
+ .title1{height: 30px;}
+ .title2{height: 110px;}
/* 20220221 PI鏀归�� by 寰愪寒 end */
@@ -42,7 +42,8 @@
<body style="font-family: MS Gothic;">
<div id="pdf-wrapper">
- <div id="title1"></div>
+ <div class="pdf-page">
+
<table width="100%" border="0">
<tr>
<td width="25%">
@@ -398,9 +399,11 @@
</tr>
</table>
- <div style="page-break-after: always;"></div>
- <div id="title2"></div>
+ </div>
+ <div style="page-break-after: always;"></div>
+ <div class="pdf-page">
+
<table width="100%" border="0">
<tr>
<td width="25%">
@@ -453,34 +456,36 @@
<br/>
<table width="100%" border="1" cellspacing="2" style="font-size: 8pt;">
<tr>
- <td>
- <table width="100%" border="1" cellspacing="0">
- <tr><td style="height:300px; text-align: center;"><apex:image value="{!qr.Photo_1_Text__c}" width="80%" rendered="{!NOT(ISBLANK(qr.Photo_1_Text__c))}" /></td></tr>
+ <td style="width:50%">
+ <table width="100%" border="0" cellspacing="0">
+ <tr><td style="height:300px; text-align: center;"><apex:image id="Photo_1_Text" value="{!Photo_1_Text}" width="80%" rendered="{!NOT(ISBLANK(qr.Photo_1_Text__c))}" /></td></tr>
<tr><td style="height:40px;"></td></tr>
</table>
</td>
<td style="border-left-color: white;">
- <table width="100%" border="1" cellspacing="0">
- <tr><td style="height:300px; text-align: center;"><apex:image value="{!qr.Photo_2_Text__c}" width="80%" rendered="{!NOT(ISBLANK(qr.Photo_2_Text__c))}" /></td></tr>
+ <table width="100%" border="0" cellspacing="0">
+ <tr><td style="height:300px; text-align: center;"><apex:image value="{!Photo_2_Text}" width="80%" rendered="{!NOT(ISBLANK(qr.Photo_2_Text__c))}" /></td></tr>
<tr><td style="height:40px;"></td></tr>
</table>
</td>
</tr>
<tr>
<td style="border-top-color: white;">
- <table width="100%" border="1" cellspacing="0">
- <tr><td style="height:300px; text-align: center;"><apex:image value="{!qr.Photo_3_Text__c}" width="80%" rendered="{!NOT(ISBLANK(qr.Photo_3_Text__c))}" /></td></tr>
+ <table width="100%" border="0" cellspacing="0">
+ <tr><td style="height:300px; text-align: center;"><apex:image value="{!Photo_3_Text}" width="80%" rendered="{!NOT(ISBLANK(qr.Photo_3_Text__c))}" /></td></tr>
<tr><td style="height:40px;"></td></tr>
</table>
</td>
<td style="border-left-color: white; border-top-color: white;">
- <table width="100%" border="1" cellspacing="0">
- <tr><td style="height:300px; text-align: center;"><apex:image value="{!qr.Photo_4_Text__c}" width="80%" rendered="{!NOT(ISBLANK(qr.Photo_4_Text__c))}" /></td></tr>
+ <table width="100%" border="0" cellspacing="0">
+ <tr><td style="height:300px; text-align: center;"><apex:image value="{!Photo_4_Text}" width="80%" rendered="{!NOT(ISBLANK(qr.Photo_4_Text__c))}" /></td></tr>
<tr><td style="height:40px;"></td></tr>
</table>
</td>
</tr>
</table>
+ </div>
+
</div>
</body>
@@ -489,16 +494,16 @@
AWSService.sfSessionId = '{!GETSESSIONID()}';
var staticResources = JSON.parse('{!staticResource}');
var staticResourceFile = JSON.parse('{!staticResourceFile}');
- function Fun(pdf){
+ function Fun(pdf) {
var form = jQuery("<form method='post'></form>");
jQuery(document.body).append(form);
let href = window.location.href
let arr = href.split('/')
- form.attr({"action":staticResourceFile.viewUnifiedContactUrl+"?from="+encodeURIComponent(href)+"&fileName="+encodeURIComponent(arr[arr.length-1].split('?')[0])});
+ form.attr({ "action": staticResourceFile.viewUnifiedContactUrl + "?from=" + encodeURIComponent(href) + "&fileName=" + encodeURIComponent(arr[arr.length - 1].split('?')[0]) });
// form.attr({"action":"http://127.0.0.1:8080/a/d?from="+encodeURIComponent(window.location.href)});
let input = jQuery("<input type='hidden'/>");
- input.attr({"name":"base64Str"});
+ input.attr({ "name": "base64Str" });
input.val(pdf.output('datauristring').substr(28));
form.append(input);
form.submit();
@@ -512,65 +517,126 @@
let id = "pdf-wrapper";
var target = document.getElementById(id);
- function jsPdfDownload(){
- let pdfName = "娴嬭瘯";
- let id = "pdf-wrapper";
- var target = document.getElementById(id);
- target.style.background = "#FFFFFF";
- if(pdfName==''||pdfName==undefined) pdfName= getNowFormatDate();
-
- html2canvas(target, {
- scale: 2,
- onrendered:function(canvas) {
- var contentWidth = canvas.width;
- var contentHeight = canvas.height;
-
- //涓�椤祊df鏄剧ずhtml椤甸潰鐢熸垚鐨刢anvas楂樺害;
- var pageHeight = contentWidth / 592.28 * 841.89;
- //鏈敓鎴恜df鐨刪tml椤甸潰楂樺害
- var leftHeight = contentHeight;
- //椤甸潰鍋忕Щ
- var position = 0;
- //a4绾哥殑灏哄[595.28,841.89]锛宧tml椤甸潰鐢熸垚鐨刢anvas鍦╬df涓浘鐗囩殑瀹介珮
- var imgWidth = 515.28;//595.28//宸﹀彸杈硅窛20
- var imgHeight = 515.28/contentWidth * contentHeight;//宸﹀彸杈硅窛20
-
- var pageData = canvas.toDataURL('image/jpeg', 1.0);
-
- var pdf = new jsPDF('', 'pt', 'a4');
-
- //鏈変袱涓珮搴﹂渶瑕佸尯鍒嗭紝涓�涓槸html椤甸潰鐨勫疄闄呴珮搴︼紝鍜岀敓鎴恜df鐨勯〉闈㈤珮搴�(841.89)
- //褰撳唴瀹规湭瓒呰繃pdf涓�椤垫樉绀虹殑鑼冨洿锛屾棤闇�鍒嗛〉
- if (leftHeight < pageHeight) {
- pdf.addImage(pageData, 'JPEG', 40, 0, imgWidth, imgHeight );//宸﹀彸杈硅窛20
- } else {
- while(leftHeight > 0) {
- pdf.addImage(pageData, 'JPEG', 40, position, imgWidth, imgHeight)//宸﹀彸杈硅窛20
- leftHeight -= pageHeight;
- position -= 841.89;
- //閬垮厤娣诲姞绌虹櫧椤�
- if(leftHeight > 0) {
- pdf.addPage();
- }
- }
- }
- Fun(pdf);
- }
- })
- }
+ // 鎶奿mageDta杞崲鎴恥rl
+ // page_height锛氫竴椤电殑楂樺害
+ function ImageDataToUrl(img_data,page_height){
+ let cvs = document.createElement("CANVAS");
+ cvs.width = img_data.width;
+ cvs.height = page_height;
+ var ctx= cvs.getContext("2d");
+ ctx.fillStyle="white";
+ ctx.fillRect(0,0,cvs.width,cvs.height);// 濉厖canvas鎵�鏈夊尯鍩熶负鐧借壊
+ ctx.putImageData(img_data,0,0);
+ return cvs.toDataURL('image/jpeg', 1.0);
+ }
+ function jsPdfDownload() {
- //blockme();
- document.body.onload = function(){
-
- AWSService.query(staticResources.queryUrl, '{!qr.AWS_Data_Id__c}', function(data){
- //unblockUI();
- document.getElementById("Responsible_Person_HP__c").innerHTML = data.object.responsiblePersonHP;
- document.getElementById("Caller_phone__c").innerHTML = data.object.callerPhone;
+ let jtargets = jQuery("#pdf-wrapper .pdf-page");
+ let j_arr = new Array(jtargets.length + 1).join(0).split('').map(function () { return false });
+ let landscape = false;
+ let pw = 595.28;
+ let ph = 841.89;
+ const marginw = 40;
+ const marginh = 40;
+
+ let orientation = '';
+ if (landscape) {
+ pw += ph; ph = pw - ph; pw = pw - ph;
+ orientation = 'l';
+ }
+ var pdf = new jsPDF(orientation, 'pt', 'a4');// 绗竴涓弬鏁板~瀛楁瘝l锛屾敞鎰忎笉鏄暟瀛�1锛屼负妯悜pdf
+ jtargets.each(function (i, e) {
+ e.style.background = "#FFFFFF";
+ })
+
+ let rei = 0;
+ let recursion = null;
+ recursion = function (i) {
+ if (i >= jtargets.length) {
+ Fun(pdf);
+ return;
+ }
+ e = jtargets[i];
+ html2canvas(e, {
+ scale: 2,
+ onrendered: function (canvas) {
+ /**
+ 鏈柟娉曢渶瑕佸仛鍑犱釜浜嬫儏
+ 1.闇�瑕佹妸canvas鐨勫唴瀹瑰垎椤垫樉绀哄埌pdf鐨勯〉涓�
+ 2.canvas鐨勫楂橀渶瑕佸拰pdf鐨勫楂樿繘琛屾槧灏�
+ 3.鎴彇鍒扮殑鍐呭闇�瑕佹斁杩涗竴椤靛楂樼殑canvas閲岄潰锛屽苟瀵瑰叾浣欏尯鍩熷埛鐧�
+ */
+ var ctx = canvas.getContext("2d");
+ let canvas_max_page_num = 9;
+ let canvas_current_page_num = 0;
+ var contentWidth = canvas.width;
+ var contentHeight = canvas.height;
+
+
+ //鏈敓鎴恜df鐨刪tml椤甸潰楂樺害
+ var leftHeight = contentHeight;
+ //椤甸潰鍋忕Щ
+ var position = 0;
+
+ //a4绾哥殑灏哄[595.28,841.89]锛宧tml椤甸潰鐢熸垚鐨刢anvas鍦╬df涓浘鐗囩殑瀹介珮
+ var outputWidth = pw - 2 * marginw;//595.28//宸﹀彸杈硅窛20
+ let rate = outputWidth / 780;//杈撳嚭瀹藉害鍜屽唴瀹瑰搴︾殑姣斾緥
+ var outputHeight = ph - 2 * marginh;//宸﹀彸杈硅窛20
+ let onePdfPageInCanvasHeight = contentWidth/outputWidth*outputHeight;//涓�椤祊df鍦╟anvas涓殑楂樺害;
+ //var pageData = canvas.toDataURL('image/jpeg', 1.0);
+ var pageData = null;
+ var imgData = null;
+
+ var captureHeight = null;// 鎴彇鐨勫綋鍓峜anvas椤电殑楂樺害
+
+ let j = i;
+ while(position < contentHeight){
+
+ if (j++) {
+ pdf.addPage();
+ }
+
+ if(position+onePdfPageInCanvasHeight>contentHeight){
+ captureHeight = contentHeight-position;
+ }else{
+ captureHeight = onePdfPageInCanvasHeight;
+ }
+
+ imgData = ctx.getImageData(0,position,contentWidth,captureHeight);
+ pageData = ImageDataToUrl(imgData,onePdfPageInCanvasHeight);
+ pdf.addImage(pageData, 'JPEG', marginw, marginh, outputWidth, outputHeight);//宸﹀彸杈硅窛20,琚緭鍑虹殑鍥剧墖浼氳鎷変几涓簅utputWidth锛宱utputHeight鐨勫楂�
+ canvas_current_page_num++;
+ position += onePdfPageInCanvasHeight;
+ if (canvas_max_page_num > 0 && canvas_current_page_num >= canvas_max_page_num) {
+ break;
+ }
+ }
+
+ recursion(i + 1);
+ }
+ })
+ };
+ recursion(rei);
+
+
+
+ }
+
+ //blockme();
+ document.body.onload = function(){
- jsPdfDownload();
- }, staticResources.token);
+ AWSService.query(staticResources.queryUrl, '{!qr.AWS_Data_Id__c}', function(data){
+ //unblockUI();
+ document.getElementById("Responsible_Person_HP__c").innerHTML = data.object.responsiblePersonHP;
+ document.getElementById("Caller_phone__c").innerHTML = data.object.callerPhone;
+ if(confirm("PDF宸插姞杞藉畬姣曪紝鏄惁鏄剧ず锛�")){
+ jsPdfDownload();
+ }
+ }, staticResources.token);
+ }
- }
+
+
</script>
<!-- 20220221 PI鏀归�� by 寰愪寒 end -->
</html>
--
Gitblit v1.9.1