0

I'm trying to centre some text onto a PDF. I'm using jsPDF and found this solution;

Is there any way to center text with jsPDF?

My problem is I get an error when running this.

split_text_to_size.js:47 Uncaught (in promise) TypeError: Cannot read property 'widths' of undefined(…)
API.getCharWidthsArray @ split_text_to_size.js:47
API.getStringUnitWidth @ split_text_to_size.js:95
<my function>

The function getCharWidthsArray() uses this.internal.getFont() which returns this object:

Object {
  PostScriptName: "Helvetica"
  encoding: "StandardEncoding"
  fontName: "helvetica"
  fontStyle: "normal"
  id: "F1"
  metadata: {}

The metadata object doesn't have anything, yet the function is trying to get Unicode.widths of that object. Is there a work around?

Community
  • 1
  • 1

1 Answers1

0

Hope you got this sorted @Nickelmatt!

For anyone else having issues with this, just include the standard_fonts_metrics.js plug-in for jsPDF. That got rid of the 'widths' of undefined error for me.