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
Asked
Active
Viewed 1.7k times
2 Answers
22
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.

Simon Bengtsson
- 7,573
- 3
- 58
- 87
-
1Thanks, 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! – Andy Torres Apr 12 '17 at 21:30
-
1Somewhat hidden, but it is under the `Helper functions` section. – Simon Bengtsson Apr 13 '17 at 08:00
-
Suppose I am using foreach loop, and in each item of loop there is a autotable and I want to print some text after the table. Suppose we have 3 items in array, By using this ```doc.lastAutoTable.finalY``` we get the coordinates of last autotable only. So text is displaying only in the end loop item. Is there any way to print just after the autotable in for loop? – Aug 17 '22 at 16:16
1
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"

Terrence LP
- 11
- 2