Browse Source

不分页 pdf

lxf 1 week ago
parent
commit
bbac46925e
3 changed files with 28 additions and 5 deletions
  1. 2 0
      src/main.js
  2. 23 0
      src/utils/util.js
  3. 3 5
      src/views/finance/fundManage/accountStatement/index.vue

+ 2 - 0
src/main.js

@@ -53,6 +53,7 @@ import {
   getDict,
   getDictOne,
   getPdf,
+  getPdfNoPage,
   getPdfTransverseA4,
   translateIntoEnglish,
   random,
@@ -104,6 +105,7 @@ app.config.globalProperties.calculationWeek = calculationWeek
 app.config.globalProperties.getDict = getDict
 app.config.globalProperties.getDictOne = getDictOne
 app.config.globalProperties.getPdf = getPdf
+app.config.globalProperties.getPdfNoPage = getPdfNoPage
 app.config.globalProperties.getPdfTransverseA4 = getPdfTransverseA4
 app.config.globalProperties.translateIntoEnglish = translateIntoEnglish
 app.config.globalProperties.random = random

+ 23 - 0
src/utils/util.js

@@ -128,6 +128,29 @@ export function calculationWeek(val, format) {
   return week;
 }
 
+export function getPdfNoPage(name, title) {
+  // Vue.prototype.htmlToPdf = function (name, title) {
+  html2Canvas(document.querySelector("#" + name), {
+    // allowTaint: true,
+    useCORS: true,
+    scale: 2, // 提升画面质量,但是会增加文件大小
+    dpi: window.devicePixelRatio * 1,
+  }).then((canvas) => {
+    const contentWidth = canvas.width;
+    const contentHeight = canvas.height;
+    /* 导出不分页处理 */
+    const pageData = canvas.toDataURL("image/jpeg", 1.0);
+    const pdfWidth = ((contentWidth + 10) / 2) * 0.75;
+    const pdfHeight = ((contentHeight + 200) / 2) * 0.75; // 500为底部留白
+    const imgWidth = pdfWidth;
+    const imgHeight = (contentHeight / 2) * 0.75; // 内容图片这里不需要留白的距离
+    const PDF = new JsPDF("", "pt", [pdfWidth + 50, pdfHeight + 100]);
+    PDF.addImage(pageData, "jpeg", 33, 33, imgWidth, imgHeight);
+    PDF.save(title + ".pdf");
+  });
+  // };
+}
+
 export function getPdf(title, num, domId = "pdfDom") {
   const element = document.getElementById(domId);
   // var doc = new JsPDF("", "pt", "a4");

+ 3 - 5
src/views/finance/fundManage/accountStatement/index.vue

@@ -269,8 +269,8 @@
 
     <el-dialog title="打印" v-if="openMorePrint" v-model="openMorePrint" width="860">
       <div id="printMe">
-        <div style="padding: 16px; font-size: 12px !important; font-family: 'msyh'">
-          <div v-for="(item, index) in checkList.filter((item, index) => checkList.indexOf(item) === index)" :key="index" :id="'pdfDom' + index">
+        <div style="padding: 16px; font-size: 12px !important; font-family: 'msyh'" id="pdfDom">
+          <div v-for="(item, index) in checkList.filter((item, index) => checkList.indexOf(item) === index)" :key="index">
             <ContractPDF :rowData="{ code: item }"></ContractPDF>
           </div>
         </div>
@@ -1570,9 +1570,7 @@ const clickDownload = () => {
   proxy.getPdf("外销合同PDF文件");
 };
 const clickMoreDownload = () => {
-  for (let i = 0; i < checkList.value.length; i++) {
-    proxy.getPdf(checkList.value[i], "", "pdfDom" + i);
-  }
+  proxy.getPdfNoPage("pdfDom", "外销合同PDF文件");
 };
 
 const loanRules = ref({