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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
| package printservice;
import com.sun.jna.platform.win32.Winspool;
import com.sun.jna.platform.win32.WinspoolUtil;
import java.util.Arrays;
import javax.print.DocFlavor;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.PrintRequestAttributeSet;
import javax.print.attribute.standard.ColorSupported;
import javax.print.attribute.standard.PDLOverrideSupported;
import javax.print.attribute.standard.PagesPerMinute;
import javax.print.attribute.standard.PagesPerMinuteColor;
import javax.print.attribute.standard.PrinterInfo;
import javax.print.attribute.standard.PrinterIsAcceptingJobs;
import javax.print.attribute.standard.PrinterLocation;
import javax.print.attribute.standard.PrinterMakeAndModel;
import javax.print.attribute.standard.PrinterMessageFromOperator;
import javax.print.attribute.standard.PrinterMoreInfo;
import javax.print.attribute.standard.PrinterMoreInfoManufacturer;
import javax.print.attribute.standard.PrinterName;
import javax.print.attribute.standard.PrinterState;
import javax.print.attribute.standard.PrinterStateReasons;
import javax.print.attribute.standard.PrinterURI;
import javax.print.attribute.standard.QueuedJobCount;
public class Main {
public static void main(String... args) {
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
PrintService printService1[] = PrintServiceLookup.lookupPrintServices(DocFlavor.URL.PNG, pras);
for (int i = 0; i < printService1.length; i++) {
System.out.println(printService1[i].getDefaultAttributeValue(PrinterMakeAndModel.class));
}
Arrays.stream(PrintServiceLookup.lookupPrintServices(DocFlavor.URL.PNG, pras))
.forEach(Main::outputPrintServiceDetails);
Arrays.stream(WinspoolUtil.getAllPrinterInfo2())
.forEach(Main::outputPrinterDetails);
}
private static void outputPrintServiceDetails(final PrintService service) {
System.out.println("--New Printer--");
System.out.println(service.getName());
System.out.printf("Supports color: %b%n", service.getAttributes().get(ColorSupported.class));
System.out.printf("Page per minutes: %d%n", service.getAttributes().get(PagesPerMinute.class));
System.out.printf("Page per minutes color: %d%n", service.getAttributes().get(PagesPerMinuteColor.class));
System.out.printf("PDL override supported: %b%n", service.getAttributes().get(PDLOverrideSupported.class));
System.out.printf("Printer info: %s%n", service.getAttributes().get(PrinterInfo.class));
System.out.printf("Accepts jobs: %b%n", service.getAttributes().get(PrinterIsAcceptingJobs.class));
System.out.printf("Printer location: %s%n", service.getAttributes().get(PrinterLocation.class));
System.out.printf("Maker and model: %s%n", service.getAttributes().get(PrinterMakeAndModel.class));
System.out.printf("Message from operator: %s%n", service.getAttributes().get(PrinterMessageFromOperator.class));
System.out.printf("More info: %s%n", service.getAttributes().get(PrinterMoreInfo.class));
System.out.printf("More info manufacturer: %s%n", service.getAttributes().get(PrinterMoreInfoManufacturer.class));
System.out.printf("Printer name: %s%n", service.getAttributes().get(PrinterName.class));
System.out.printf("State: %s%n", service.getAttributes().get(PrinterState.class));
System.out.printf("State reasons: %s%n", service.getAttributes().get(PrinterStateReasons.class));
System.out.printf("URI: %s%n", service.getAttributes().get(PrinterURI.class));
System.out.printf("Queued job count: %s%n", service.getAttributes().get(QueuedJobCount.class));
}
private static void outputPrinterDetails(final Winspool.PRINTER_INFO_2 info) {
System.out.println("--INFO--");
System.out.println(info.pServerName);
System.out.println(info.pPrinterName);
System.out.println(info.pShareName);
System.out.println(info.pPortName);
System.out.println(info.pDriverName);
System.out.println(info.pComment);
System.out.println(info.pLocation);
System.out.println(info.pDevMode);
System.out.println(info.pSepFile);
System.out.println(info.pPrintProcessor);
System.out.println(info.pDatatype);
System.out.println(info.pParameters);
System.out.println(info.pSecurityDescriptor);
System.out.println(info.Attributes);
System.out.println(info.Priority);
System.out.println(info.DefaultPriority);
System.out.println(info.StartTime);
System.out.println(info.UntilTime);
System.out.println(info.Status);
System.out.println(info.cJobs);
System.out.println(info.AveragePPM);
}
} |
Partager