question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error using jsPDF cell table() method

See original GitHub issue

Hello,

First, I want to say, what an amazing framework! I was testing it to implement in a current project that I am working on and I am having some issues creating tables on the document. Based on your documentation, I am doing everything correctly. Here is a piece of code so you can check the problem that I am having:

JS File

var data = [
  {
    coin: "100",
    game_group: "GameGroup",
    game_name: "XPTO1",
    game_version: "25",
    machine: "20485861",
    vlt: "0"
  },
  {
    coin: "100",
    game_group: "GameGroup",
    game_name: "XPTO2",
    game_version: "25",
    machine: "20485861",
    vlt: "0"
  }
];

var header = ["coin", "game_group", "game_name", "game_version", "machine", "vlt"]

function save() {
  var doc = new jsPDF()
  doc.text(20, 20, 'Hello world!')
  doc.table(1, 1, data, header)
  doc.save()
}

HTML File

<button onclick="save()">Save</button>

The error that I am having is this:

jspdf.min.js:29 Uncaught Error: Invalid arguments passed to jsPDF.rect
    at Object.l.__private__.rect.l.rect (jspdf.min.js:29)
    at Object._.cell (jspdf.min.js:88)
    at Object._.printHeaderRow (jspdf.min.js:88)
    at Object._.table (jspdf.min.js:88)
    at save (pen.js:25)
    at HTMLButtonElement.onclick (index.html?editors=1111:6)

Here is the codepen link so you can check the problem on your console: https://codepen.io/anon/pen/EGQzNr

Thank you for your attention and support, and keep up the good work!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9

github_iconTop GitHub Comments

2reactions
viraj4422commented, Jan 9, 2019

Try this:

  {
    coin: "100",
    game_group: "GameGroup",
    game_name: "XPTO1",
    game_version: "25",
    machine: "20485861",
    vlt: "0"
  },
  {
    coin: "100",
    game_group: "GameGroup",
    game_name: "XPTO2",
    game_version: "25",
    machine: "20485861",
    vlt: "0"
  }
];
var header = createHeaders(["coin", "game_group", "game_name", "game_version", "machine", "vlt"]);

function createHeaders(keys) {
    return keys.map(key => ({
      'name': key,
      'prompt': key,
      'width':65,
      'align':'center',
      'padding':0
    }));
}

function save() {
  var doc = new jsPDF()
  doc.text(20, 20, 'Hello world!')
  doc.table(1, 1, data, header)
  doc.save()
}

1reaction
Uzlopakcommented, Apr 11, 2019

@viraj4422 @lexcode Yes, it was an annoying bug. Refactored cell.js #2412

Will be fixed in next release.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error using jsPDF cell table() method · Issue #2223 - GitHub
I was testing it to implement in a current project that I am working on and I am having some ... Error using...
Read more >
Angular 8, using jspdf and autotable-jspdf import/usage issues
I found one partial solution with doc.table() here...generates the table....but the import jsPDF returns always errors, I tryed to send to ...
Read more >
TypeError: a is null while working with jspdf autotable - MSDN
This is one of the most common errors in programming. The error means that you are trying to find the firstChild of a...
Read more >
How to Convert HTML Tables into Beautiful PDFs
jsPDF shines when it comes to single-page content generated based on HTML shown in the UI. pdfmake works best when generating PDF content...
Read more >
jsPDF - Documentation - GitHub Pages
jsPDF.API is a STATIC property of jsPDF class. jsPDF.API is an object you can add methods and properties to. The methods / properties...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found