Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getTextDimensions expects text-parameter to be of type String or type Number or an Array of Strings. #3053

Closed
johnEthicalTechnology opened this issue Dec 31, 2020 · 6 comments

Comments

@johnEthicalTechnology
Copy link

johnEthicalTechnology commented Dec 31, 2020

I'm using Typescript in a React project and I follow the example for creating a table on the Live Demo site but I get the following error: getTextDimensions expects text-parameter to be of type String or type Number or an Array of Strings.

I check the type of the arguments for .table() and the headers argument is string[] which is unexpected because the demo is using object[]. I change to the type asked for by the argument but I still get the same error.

Below is an MCVE in node:

const { jsPDF } = require('jspdf')

function test() {
  const test = new jsPDF('landscape')
  const headers = [
    'Name',
    'Student_Date_Of_Birth',
    'Student_ID_No_Course',
    'Course',
    'Course_Total_Tuition_Fee',
    'Course_Intake',
    'Course_Year',
    'Course_Start_Month',
    'Commission_Rate',
    'Commission_Payable'
  ]
  const invoiceObjectTableRows = [
    {
      Name: 'testing',
      Student_Date_Of_Birth: 'testing',
      Student_ID_No_Course: 'testing',
      Course: 'testing',
      Course_Total_Tuition_Fee: 'testing',
      Course_Intake: 'testing',
      Course_Year: 'testing',
      Course_Start_Month: 'testing',
      Commission_Rate: 'testing',
      Commission_Payabl: 'testing'
    }
  ]
  test.table(5, 105, invoiceObjectTableRows, headers, { autoSize: true })
}

test()
@HackbrettXXX
Copy link
Collaborator

You have a typo in your code snippet ;)

Commission_Payabl: 'testing'

This results in an undefined text for a cell.

@johnEthicalTechnology
Copy link
Author

Oh lol head slap. Thanks!

@stiofand
Copy link

stiofand commented Feb 16, 2021

Why is this closed? The documentation is still in conflict with the examples. We haven't been able to get this to work with our existing data set at all.

@HackbrettXXX
Copy link
Collaborator

In this particular case, it was really just the typo. You can pass string headers as long as you set autoSize: true. The issue was fixed in #3087.

@michael-aries11
Copy link

Thanks. This typo had got my head spinning for days.

@mgeorgee
Copy link

Thanks. I had a trailing white space in one of the header columns.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants