Pranab V V
Pranab V V

Reputation: 1446

how to add a text at the bottom of jspdf auto table in angular5

I am using jspdf auto table in my angular5 app. I am generating dynamic data for jspdf auto table. My problem is how can I add a text at the bottom of table?

    const columnHead = [];
    const columnRow = [];
    this.tableColumns.filter(x => {
      columnHead.push(this.capFirstLtr(x.title));
    });
    this.tableData.filter((x, y) => {
      x.slaMetFlag = (this.mapData[y].slaMetFlag ? this.capFirstLtr(this.mapData[y].slaMetFlag) : '-');
      columnRow.push([x.date, x.slaMetFlag, x.srType, x.srID, x.srStatus, x.aof, x.ppm, x.deviceID, x.siteID, x.branchID]);
    });
    const doc = new jsPDF();
     doc.text('Showing data from ' + moment(this.requestApi.fromDate).format('MM/DD/YYYY') + ' to ' + moment(this.requestApi.toDate).format('MM/DD/YYYY'), 5, 10);
    doc.autoTable(columnHead, columnRow, {
      styles: { overflow: 'linebreak', halign: 'center', fontSize: 7},
      tableWidth: 200,
      margin: 5,
      theme: 'grid',
      startY: 15,
      addPageContent: function(data) {
        console.log('data', data);
      }
    });
    doc.save('SR View Export');
  }

in the above code how can I add a text after the completion of jspdf auto table?

Upvotes: 0

Views: 2942

Answers (1)

Nambi N Rajan
Nambi N Rajan

Reputation: 509

If you want to know something about the last table that was drawn you can use doc.autoTable.previous. It has a doc.autoTable.previous.finalY property among other things that has the value of the last printed y coordinate on a page. This can be used to draw text, multiple tables or other content after a table.

doc.autoTable.previous.finalY use this property.

doc.autoTable(headers, data);

let finalY = doc.autoTable.previous.finalY;// The y position on the page

doc.text(20, finalY, "Hello!")

Upvotes: 3

Related Questions