Forum How do I...?

Compatibility with CanvasJS


I'm trying to render javascript charts in a PDF. I'm using canvasjs ( for the charting library.

When I try to run prince, I'm getting this error:
`TypeError: undefined value is not an object`

Are there any resources or tips for getting external javascript libraries working with Prince?


Edited by adampal

I just noticed I'm also getting this warning:
`prince: warning: canvas measureText is not yet supported`

Would it be possible to provide a measureText polyfill to get around this issue?
A polyfill would be possible, as long as the results don't need to be too accurate, for example just multiplying the number of characters in the string by a fixed width value.
Thanks Mike. Do you have any documentation for adding the polyfill? I've added this one:

Should I still be getting the warning from prince about measureText being unsupported even after adding the polyfill?

It looks like that polyfill requires an older version of measureText to be present in order to add support for a newer version, however the bigger problem here is that the measureText property appears to be read-only in Prince! We will need to change that or it cannot be overridden in the prototype, although it would still be possible (if awkward) to override it for an individual canvas element.
Thanks for looking into it Mike.
How realistic is it to make that change to Prince?
It would be amazing if Prince was compatible with canvasjs!