Björn
Björn

Reputation: 35

Google Table Chart export to PDF with autotable

Hi I am trying to export a Google Table Chart as a PDF. I have tried it this way:

var doc = new jsPDF('p','pt','a4');
        doc.text(15, 15, 'Batemo Cell Finder Report');
        // doc.addImage(ScatterChart.getChart().getImageURI(), 15, 40, 180, 160);
        doc.autoTable(document.getElementById("table_div"), 15, 15, {
          'width': 200,
          'elementHandlers': specialElementHandlers,
        });
        doc.save('chart.pdf');

But it displays the following console error in the browser:

Uncaught TypeError: Cannot create property 'body' on number '15'
    at parseUserArguments (jspdf.plugin.autotable.js:1276)
    at Object.parseInput (jspdf.plugin.autotable.js:1195)
    at Object.autoTable (jspdf.plugin.autotable.js:1154)
    at HTMLInputElement.<anonymous> (cell_finder.html:287)

How can I get the data displayed. Many thanks in advance!

Upvotes: 0

Views: 164

Answers (1)

WhiteHat
WhiteHat

Reputation: 61275

the google table chart does produce a normal html <table>.
however, it is contained within one or more <div> elements.

maybe autotable is expecting a table element, rather than a div...

try providing the table element directly...

    doc.autoTable(document.querySelector('#table_div table')[0], 15, 15, {
      'width': 200,
      'elementHandlers': specialElementHandlers,
    });

Upvotes: 1

Related Questions