1

大家好,我正在使用最新版本的 jspdf 和 jspdf-autotable,当数据占用单个页面时,我尝试嵌套表工作正常,但是当它们占用更多嵌套表时,它们会转到最后一页

在此处输入图像描述

此代码打印表格

public printTableData() {
    let __self__ = this;
    let extra    = 0, lastDifference = 0, infoPositions = [];
    this.pdfBuilder.autoTable(this.config.columnsTable, this.config.concepts, {
        addPageContent: this.printFooterEachPage.bind(this),
        pageBreak: 'auto',
        drawRow: function (row, data) {
            if(data.cursor.y > 200) {
                // Adding page for the next products
                data.addPage();
                lastDifference = 0;
                data.cursor.y = row.height + data.table.headerRow.height - 1.5;
                row.y = row.height + data.table.headerRow.height - 1.5;
            }
            // This code helps me to separate the rows with the information by product
            let difference = row.height;
            if (row.index > 0 && lastDifference > 0) {
                data.cursor.y = lastDifference;
                lastDifference += difference;
            } else {
                lastDifference = row.y + row.height
            }
            __self__.pdfBuilder.setDrawColor(170, 170, 170);
            __self__.pdfBuilder.setFontStyle('bold');
            __self__.pdfBuilder.setFontSize(10);
            __self__.pdfBuilder.rect(data.settings.margin.left, lastDifference, data.table.width, 28, 'S');
            __self__.pdfBuilder.autoTableText("Product data", data.settings.margin.left + data.table.width / 2, lastDifference + 5, {
                halign: 'center',
                valign: 'middle'
            });

            // Here is the data to position the information by product
            infoPositions.push({
                y: lastDifference,
                index: row.index,
                pageCount: data.pageCount
            });

            lastDifference += 28;
            extra = difference + 28;
        },
        margin: {
            left:  5,
            right: 5,
        },
        startY: 79,
    });

    this.printTaxesInfo(infoPositions);
}

此代码打印每个产品的税收信息

private printTaxesInfo(infoPositions) {
    infoPositions.forEach((infoData) => {
        this.pdfBuilder.autoTable([
            {title: "BASE",         dataKey: "base"},
            {title: "TAX",          dataKey: "tax"},
            {title: "FACTOR",       dataKey: "factor"},
            {title: "RATE OR FEE",  dataKey: "fee"},
            {title: "AMOUNT",       dataKey: "amount"},
        ], this.config.concepts[infoData.index].taxes, {
            margin: {
                left:  130,
            },
            tableWidth: 80,
            startY: infoData.y + 5
        });
    });
}

我怎样才能没有这些问题的嵌套表?谢谢你。

4

0 回答 0