angularjspdfhtml-to-pdfjspdf-autotable

How to get the finalY of lastAutoTable in jspdf-autoTable


I am using angular 9.I have a requirement to convert a html table with some content above and below the table into pdf. I am using jspdf-autotable.I followed the examples in the link https://github.com/simonbengtsson/jsPDF-AutoTable/blob/master/examples/examples.js and I am able to write a heading and then generate the table.The problem is when I need to add some text lines below the table.

My code is as below.

generatePdf(){
const doc = new jsPDF();
doc.setFontSize(18)
doc.text('ATTENDANCE REPORT FOR DEPOT - '+this.depotId, 14, 22);
autoTable(doc, { html: '#report-per-depot',startY: 30, });
doc.text(" ", 14, doc.lastAutoTable.finalY + 10)
doc.save('AttandancePerDepot.pdf');

}

The error I get is

Property 'lastAutoTable' does not exist on type 'jsPDF'.

I tried to import lastAutoTable as, import lastAutoTable from 'jspdf-autotable';
I doesnt show any error,but I am not sure how to get the finalY from it.

  lastAutoTable(doc,{});

The above doesnt show error but its return type is void.So this is where I am stuck. How do I get the finalY position in angular 9 or 10?


Solution

  • You're getting this error because Typescript is a strongly Typed language & lastAutoTable is not defined in the index.d.ts file (under jsPdf node module).

    Below is a small hack to get around this error & get finalY value.

    import jsPDF from 'jspdf';
    import 'jspdf-autotable';
        
    let finalY = (doc as any).lastAutoTable.finalY;
    

    This worked for me in my Angular 10 project