Well, you likely have to write some sort of native code to communicate with the operating system, which has drivers for the printer.
However, this is probably not easy, and I would think that there are already third party libraries out there that have solved this problem. So google around for solutions that other people have made.