Quellcode durchsuchen

fix:下载不全问题

guotianliang vor 4 Jahren
Ursprung
Commit
4a2900651e
1 geänderte Dateien mit 11 neuen und 4 gelöschten Zeilen
  1. 11 4
      src/utils/htmlToPdf.js

+ 11 - 4
src/utils/htmlToPdf.js

@@ -2,15 +2,19 @@ import html2Canvas from 'html2canvas'
 import JsPDF from 'jspdf'
 import { Loading } from 'element-ui';
 
-
+function footer(doc){
+    doc.text(150,285,'page ' + doc.page); //print number bottom right
+    doc.page ++;
+};
 export default{
     install (Vue, options) {
         Vue.prototype.getPdf = function (id, title,sgin) {
+
             let loadingInstance = Loading.service({target:'page_main'});
             html2Canvas(document.querySelector(`#${id}`), {
                 // allowTaint: true
                 useCORS: true,
-                scale: 2,
+                scale: 1.1,
                 scrollY: 0,
             }).then(function (canvas) {
                 let contentWidth = canvas.width;
@@ -23,7 +27,7 @@ export default{
                 let pageData = canvas.toDataURL('image/jpeg', 1.0);
                 let PDF = new JsPDF('', 'pt', 'a4');
                 let logo =document.querySelector(`#logo`);
-                // let pageNumber=1;
+                let pageNumber=1;
                 if (leftHeight < pageHeight) {
                     PDF.addImage(pageData, 'JPEG', 0, 0, imgWidth, imgHeight);
                     PDF.addImage(logo, 'PNG', 10, 6);
@@ -31,7 +35,10 @@ export default{
                 } else {
                     while (leftHeight > 0) {
                         PDF.addImage(pageData, 'JPEG', 0, position, imgWidth, imgHeight);
-                        PDF.addImage(logo, 'PNG', 10, 6);
+                        if(pageNumber==1){
+                            pageNumber++
+                            PDF.addImage(logo, 'PNG', 10, 6);
+                        }
                         // PDF.setFont('msyh')
                         // PDF.text(500,13,sgin);
                         leftHeight -= pageHeight;