Omsl
Omsl

Reputation: 302

doc.autotable.previous is undefined in jsPDF

I' m using jspdf with vue. I want the text to come under that table after adding a table, but I get the error doc.autotable.previous is undefined.

    exportPdf(){
      var doc = new jsPDF('l', 'pt');
      doc.setFontSize(20);
      doc.text(170, 20, 'Ürün Teslim Belgesi',{
        halign: 'center',
        valign: 'middle'
      });
      var vm = this;
      var columns = [
        {title: "Ürün", dataKey: 'product'},
        {title: 'Tip', dataKey: 'type'},
        {title: 'Adet', dataKey: 'piece'},
        {title: 'Tarih', dataKey: 'date'}
      ];
      doc.autoTable(
        columns, vm.products,{
          margin: {left: 35},
          headStyles: {halign: 'center', valign: 'middle'},
          theme: 'grid',
          tableWidth: 'auto',
          fontSize: 8,
          overflow: 'linebreak',
        });
      doc.setProperties({
          title: 'xxx',
          subject: 'yyy',
          author: 'ttt',
          keywords: 'qqq',
          creator: 'www'
        });
      doc.text("example text example text example text example text.", 14, doc.autoTable.previous.finalY + 10);
        doc.save('test.pdf');
      },

Thank you very much if you can help, have a nice day.

Upvotes: 0

Views: 1421

Answers (1)

Michal Levý
Michal Levý

Reputation: 37923

Seems strange to me - tried your code and I got settings.styles is undefined error instead the one you describing. It seems you mixing options from Styling options and Other options

Following code works just fine (had to replace data - jspdf 1.5.3, jspdf-autotable 3.2.11):

var doc = new jsPDF("l", "pt");
  doc.setFontSize(20);
  doc.text(170, 20, "Ürün Teslim Belgesi", {
    halign: "center",
    valign: "middle"
  });
  var products = [
    { product: "Retro", type: "Shoes", piece: 1, date: "1.1.2020" }
  ];
  var columns = [
    { title: "Ürün", dataKey: "product" },
    { title: "Tip", dataKey: "type" },
    { title: "Adet", dataKey: "piece" },
    { title: "Tarih", dataKey: "date" }
  ];
  doc.autoTable(columns, products, {    
    theme: "grid",
    styles: {
      fontSize: 8,
      overflow: "linebreak"
    },
    headStyles: { halign: "center", valign: "middle" },
    tableWidth: "auto",
    margin: { left: 35 }
  });
  doc.setProperties({
    title: "xxx",
    subject: "yyy",
    author: "ttt",
    keywords: "qqq",
    creator: "www"
  });
  doc.text(
    "example text example text example text example text.",
    14,
    doc.autoTable.previous.finalY + 10
  );
  doc.save("test.pdf");

Upvotes: 1

Related Questions