Andy Torres
Andy Torres

Reputation: 165

jspdf - Insert text after table

I am using jsPDF and jsPDF-AutoTable to create and print a report. But I want to insert a text right below the table. But, as it is a dynamic table, I can't tell doc.text() the y coordinate from where to write the text. Has anyone done that before? Thanks in advance

Upvotes: 11

Views: 20607

Answers (2)

Terrence LP
Terrence LP

Reputation: 11

Great answer above, the key is how you will be using it in the page set up.

    if(doc.lastAutoTable.finalY) {
    doc.autoTable({startY: doc.lastAutoTable.finalY + 150})

The + 150 forces a new page, using the following

    orientation: "landscape",
    unit: "mm",
    format: "a4"

Upvotes: 1

Simon Bengtsson
Simon Bengtsson

Reputation: 8151

You can use the doc.autoTable.previous.finalY property like this:

doc.autoTable({html: '#table'});
let finalY = doc.lastAutoTable.finalY; // The y position on the page
doc.text(20, finalY, "Hello!")

See the with content example for sample code.

Upvotes: 23

Related Questions