开发者

How to print to Windows USB printer from Java?

I have a kiosk application that runs under Windows. I would like to be able to print to a Windows printer connected via USB from a Java app. I can't use the JavaCOMM library as the printer is not serial or USB. I've read about th开发者_开发知识库e Java print API but it looks like it only prints images, I would like to be able to send raw text to the printer.


The Java Print API can do much more as just print images. Have a look at the SDK Printing tutorial, there is everything you need.

What about this, you just provide a char array with your chars:

char[] printdata = "hello world\n".toCharArray();
DocFlavor flavor = DocFlavor.CHAR_ARRAY.TEXT_PLAIN;
PrintService pservice = PrintServiceLookup.lookupDefaultPrintService();
DocPrintJob pjob = pservice.createPrintJob();
Doc doc= new SimpleDoc(printdata, flavor, null);
job.print(doc, null);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜