How to print to a printer in Rails

I am developing an app in rails and I need to know how I can print some file through thermal printer. There is anyone that can explain me how do that? It's better to print file directly from rails or js?

Thanks in advance.