Home » Jquery » javascript – JSPDF Autotable Dynamic Column Width?

javascript – JSPDF Autotable Dynamic Column Width?

Posted by: admin February 22, 2020 Leave a comment


This is my simple code for generating a pdf using the autotable. The problem is this table is used app wide and each table can have any number of columns. I need the auto table to expand the column based on the size of the header length. How can I do that?

 const pdf = new window.jsPDF('p', 'pt', 'letter');
    var data = pdf.autoTableHtmlToJson(document.getElementById('dataTable'));
    var height = pdf.internal.pageSize.height;
    pdf.text(this.titleService.getTitle(), 50, 50);
    pdf.autoTable(data.columns, data.data, {
      startY: 100
    pdf.autoTable(data.columns, data.data, {
      startY:  pdf.autoTableEndPosY() + 50
    pdf.autoTable(data.columns, data.data, {
      startY: height,
      addPageContent: function(data) {
        pdf.text("After page content", 50, height - data.settings.margin.bottom - 20);
    pdf.save(this.titleService.getTitle() + '.pdf')
How to&Answer: