jsPDF-AutoTable-是否有任何函数可以获取`didParseCell`挂钩中的页数

问题描述 投票:1回答:1

如果页面数多于一个,我想增加总数。

我正在使用didParseCell将总数添加到表数据及其工作中,但是我无法获得“总页数”,因此我可以放入任何条件

我还在插件的git上添加了注释。(https://github.com/simonbengtsson/jsPDF-AutoTable/issues/550

我已经在autoTable的doc.internal.getNumberOfPages()中尝试过data.table.pageNumberdata.table.pageCountdidParseCell

所有人都给页数1

代码

let doc     = new jsPDF({
      orientation: 'landscape',
      unit: 'pt'
    });

    let totalAmountRow = {column1:'Total Amount',column2:'INR',column2:'40'}

    doc.autoTable(headers, data, {
      startY:yPoint += 20,
      margin: {top: 100},
      theme: "grid",      
      didParseCell: function (data) {           
            console.log("Data getNumberOfPages",doc.internal.getNumberOfPages()) // Wrong page count here           
            console.log("Data Table PageCount",data.table.pageCount)
            console.log("data Table PageNumber",data.table.pageNumber)
            if(totalAmountRow != ''){
                data.table.settings.body.push(totalAmountRow);              
                totalAmountRow = '';
            }
      },
        didDrawCell: function (data) {
        doc.setFillColor(255, 255, 255);
      },
      columnStyles: {
        amount: {cellWidth: 60},
        "Demo Text": {cellWidth: 50}
      },
      didDrawPage: function (data) {
        let footerStr;
        let pageCount = doc.internal.getNumberOfPages(); // Here I am getting correct page count 
        if (typeof doc.putTotalPages === 'function') {
          footerStr = pageCount + " / " + totalPagesExp;
        }
        if(pageCount != 0) {
          doc.addImage('imgURL', 'JPEG', 35, 30);
          doc.setFontSize(14);
          doc.text('Title', 35, 80);
          yPoint = 300;
        }
        doc.setFontSize(10);
        doc.text(footerStr, 400, 590);        
      }
    });

    if (typeof doc.putTotalPages === 'function') {
      doc.putTotalPages(totalPagesExp);
    }
    doc.save("pdfName.pdf");
angular jspdf jspdf-autotable
1个回答
0
投票

didParseCell立即被调用,这意味着您将始终从getNumberOfPages获得1。执行所需操作的最简单方法可能是在didParseCell中添加行,然后在willDrawCell中修改内容。

© www.soinside.com 2019 - 2024. All rights reserved.