jsPDF-AutoTable-是否有任何函数可以在“didParseCell”挂钩中获取页面计数

jsPDF-AutoTable- Is there any function to get the page count inside the `didParseCell` hook

如果页数更多,我想添加总金额。

我正在使用 didParseCell 添加 table 数据中的总量及其工作,但我无法获得总页数,因此我可以设置任何条件

我也在插件的git添加了评论。(https://github.com/simonbengtsson/jsPDF-AutoTable/issues/550)

我已经在 autoTable 的 didParseCell 中尝试了 doc.internal.getNumberOfPages()data.table.pageNumberdata.table.pageCount

所有人都给出页数 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");

立即调用 didParseCell,这意味着您将始终从 getNumberOfPages 获得 1。做你想做的最简单的方法可能是在 didParseCell 中添加行,然后修改 willDrawCell.

中的内容