Closed palanganero closed 4 years ago
hi @palanganero,
the answer is PrinterOutputStream.getListPrintServicesNames()
you can make something like this:
public static void main(String[] args) throws IOException {
if(args.length!=1){
System.out.println("Usage: java -jar xyz.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);
}
PrintService printService = PrinterOutputStream.getPrintServiceByName(args[0]);
ok, thank you. But If I had more than one device connected to bluetooth or even had more than one printer, how does this software distinguish which device to send the data to?
This is same list of windows installed printers. Each printer have one unique name.
When you print one notepad document You notice this same list
ok I understand. And will this code print a simple hello world? `package impresoratickets;
import com.github.anastaciocintra.escpos.EscPos; import com.github.anastaciocintra.escpos.image.EscPosImage; import java.io.Closeable; import java.io.Flushable; import java.io.IOException; import java.io.OutputStream; import java.io.UnsupportedEncodingException; import java.util.Objects; import java.util.Properties;
import com.github.anastaciocintra.escpos.barcode.BarCodeWrapperInterface; import com.github.anastaciocintra.escpos.image.ImageWrapperInterface; import com.github.anastaciocintra.output.PrinterOutputStream; import javax.print.PrintService;
public class ImpresoraTickets { public static void main(String[] args) throws IOException {
PrintService printService = PrinterOutputStream.getPrintServiceByName("printer_name"); PrinterOutputStream printerOutputStream = new PrinterOutputStream(printService); EscPos escpos = new EscPos(printerOutputStream); escpos.writeLF("Hello Wold"); escpos.feed(5); escpos.cut(EscPos.CutMode.FULL); escpos.close(); }
}`
yes, it should print Hello World
ok, thank you!
count on me see you
any exception?
and what command should be sent to open the cash drawer?
In this line it asks me for the name of the printer, where can I find the name of the printer?
PrintService printService = PrinterOutputStream.getPrintServiceByName("printerName");