How to pass data from a table to a PDF report using React and JSPDF?

Asked

Viewed 721 times

-1

Follows my code:

exportar = () => {
        var doc = new jsPDF()
        var d = new Date();
        var texto = "Generator PDF"
        var mes = d.getMonth() + 1;
        doc.setFont('times', 'bold')
        doc.setFontSize(14)
        doc.text(10, 10, texto);
        doc.output('dataurlnewwindow', 'Clientes_'+d.getDate()+'/'+mes+'/'+d.getFullYear()+'.pdf')
    }

The way it is generates a PDF file with the value of the text variable, but I need to know how to pass the data from the table to this report.

Before you tell me to go into the JSPDF documentation.

  • Hello the goal is to generate a PDF with the data that is in a table? Why not use the PDF-Autotable? https://simonbengtsson.github.io/jsPDF-AutoTable/#

1 answer

1


Use the jsPDf-Autotable library. Simply retrieve your html table and move to the library and it will export the pdf file from your table.

var doc = new jsPDF('p', 'pt');
var elem = document.getElementById("basic-table");
var res = doc.autoTableHtmlToJson(elem);
doc.autoTable(res.columns, res.data);
doc.save("table.pdf");

Browser other questions tagged

You are not signed in. Login or sign up in order to post.