jsPDF icon indicating copy to clipboard operation
jsPDF copied to clipboard

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

Open johnEthicalTechnology opened this issue 5 years ago • 6 comments

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()

johnEthicalTechnology avatar Dec 31 '20 04:12 johnEthicalTechnology

You have a typo in your code snippet ;)

Commission_Payabl: 'testing'

This results in an undefined text for a cell.

HackbrettXXX avatar Jan 11 '21 10:01 HackbrettXXX

Oh lol head slap. Thanks!

johnEthicalTechnology avatar Jan 12 '21 01:01 johnEthicalTechnology

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.

stiofand avatar Feb 16 '21 14:02 stiofand

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.

HackbrettXXX avatar Feb 17 '21 08:02 HackbrettXXX

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

michael-aries11 avatar Jun 12 '21 06:06 michael-aries11

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

mgeorgee avatar Aug 10 '22 01:08 mgeorgee