[Chartjs]-Export chart.js canvas to prawn-pdf in rails

0๐Ÿ‘

โœ…

chart.js has a method toDataUrl()

toDataUrl is a canvas property (https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toDataURL).

It returns an image representation of the canvas (default is png) in base 64 encoded format. Since Prawn needs an image path, you need to send this base 64 string to the server and save it as a file (see How to save a base64 string as an image using ruby) and then have Prawn use the location of the saved file.

Leave a comment