-
Notifications
You must be signed in to change notification settings - Fork 17
/
GetstartSample.java
48 lines (38 loc) · 1.64 KB
/
GetstartSample.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
* Use of this source code is governed by the MIT license that can be
* found in the LICENSE file.
*/
import com.github.anastaciocintra.escpos.EscPos;
import com.github.anastaciocintra.output.PrinterOutputStream;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.print.PrintService;
public class GetstartSample {
public void printInfo(String printerName){
//this call is slow, try to use it only once and reuse the PrintService variable.
PrintService printService = PrinterOutputStream.getPrintServiceByName(printerName);
try {
PrinterOutputStream printerOutputStream = new PrinterOutputStream(printService);
EscPos escpos = new EscPos(printerOutputStream);
escpos.info();
// do not forget to close...
escpos.close();
} catch (IOException ex) {
Logger.getLogger(GetstartSample.class.getName()).log(Level.SEVERE, null, ex);
}
}
public static void main(String[] args) {
if(args.length!=1){
System.out.println("Usage: java -jar getstart.jar (\"printer name\")");
System.out.println("Printer list to use:");
String[] printServicesNames = PrinterOutputStream.getListPrintServicesNames();
for(String printServiceName: printServicesNames){
System.out.println(printServiceName);
}
System.exit(0);
}
GetstartSample obj = new GetstartSample();
obj.printInfo(args[0]);
}
}