adhik13th
3 months ago

How to add dinamic text under table in jspdf

Posted 3 months ago by adhik13th

i have a pdf with table using jspdf autotable , i want to add some text dinamicly on under table. if the table has reached the bottom, then underneath there will be text as I want it right. the concept is like a footer but this is exactly below the table.

and its my code

 methods:{
downloadPDF(){
 var  addFooters = doc => {
 const pageCount = doc.internal.getNumberOfPages()

 doc.setFont('helvetica', 'italic')
 doc.setFontSize(8)
 for (var i = 1; i <= pageCount; i++) {
   doc.setPage(i)
   doc.text('Page ' + String(i) + ' of ' + String(pageCount), doc.internal.pageSize.width / 2, 587, {
   align: 'center'
    })
  }
 }
   
  var doc = new jsPDF('l', 'pt');

   var header = function (data) {
                doc.setFontSize(18);
                doc.setTextColor(40);
                doc.setFontStyle('normal');

               doc.text(330, 50, 'Pengajuan Pencairan')
              
              
            };
             doc.setFontSize(12)
             doc.text(75, 80, 'Nama Program')      
             doc.text(75, 100, 'Kegiatan')
             doc.text(75, 140, 'Rincian Kegiatan')
             doc.text(75, 160, 'Bulan Tanggal')


             doc.text(600, 80, 'Anggaran')
             doc.text(600, 100, 'Sudah Digunakan')
             doc.text(600, 140, 'Pengajuan')
             doc.text(600, 160, 'Sisa Anggaran')

 
  var res = doc.autoTableHtmlToJson(document.getElementById("basic-table"));     
  doc.autoTable(res.columns, res.data, {margin: {top: 180},  beforePageContent: header }); //table
  
  //here after this table i need add some dinamic text .

  addFooters(doc)
  doc.save("table.pdf");
}

}

i can use

doc.text(600, 80, 'blablabla')

but its not dinamic if i have long table

someone have solution for this ??

Please sign in or create an account to participate in this conversation.