import java.awt.print.Printable;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import javax.print.*;
import javax.print.attribute.*;
import javax.print.attribute.standard.*;
import javax.print.event.PrintJobEvent;
public class ListPrinters {
public static void main(String[] args) throws PrinterException{
PrintService defServ = PrintServiceLookup.lookupDefaultPrintService();
System.out.println("Default PrintService: "+defServ);
PrintService[] serv = PrintServiceLookup.lookupPrintServices(null, null);
if (serv.length==0) {
System.out.println("no PrintService found");
} else {
System.out.println("number of Services "+serv.length);
}
for (int i = 0; i
PrintServiceAttributeSet psa = serv[i].getAttributes();
System.out.println("printer name "+(i+1)+" "+psa.get(PrinterName.class));
System.out.println("accepting "+psa.get(PrinterIsAcceptingJobs.class));
}
}
Nice demonstration. It helps me in setting my available printer options on a customized application for printing.
ReplyDeleteThanks. Complete the line with the for loop with "< serv.length; i++) { .... }".
ReplyDelete