jspdf - Insert text after table

11,670

Solution 1

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.

Solution 2

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"
Share:
11,670
Andy Torres
Author by

Andy Torres

Updated on August 05, 2022

Comments

  • Andy Torres
    Andy Torres almost 2 years

    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

  • Andy Torres
    Andy Torres about 7 years
    Thanks, Simon. That did the trick. I didn't found that in the docs, but it seems I didn't look deep enough. Awesome plugin, by the way! Thanks a lot!
  • Simon Bengtsson
    Simon Bengtsson about 7 years
    Somewhat hidden, but it is under the Helper functions section.