[JAVA] get a list of printers
le tanard
-
khoulio -
khoulio -
Hello,
I’m developing a Java application in which I need to have a list of printers available on the system.
The problem is that I’m getting a bit lost: I’ve seen how (with which classes) to change all the settings, but I can’t seem to retrieve a list of printers.
Has anyone here already done this, or have a solution?
Thanks for your help
I’m developing a Java application in which I need to have a list of printers available on the system.
The problem is that I’m getting a bit lost: I’ve seen how (with which classes) to change all the settings, but I can’t seem to retrieve a list of printers.
Has anyone here already done this, or have a solution?
Thanks for your help
1 answer
public void getAllPrinter(){
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
DocFlavor flavor =DocFlavor.INPUT_STREAM.AUTOSENSE;
String mime =flavor.getMimeType();
PrintService printService[] = PrintServiceLookup.lookupPrintServices(flavor, pras);
PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();
for(int i=0;i<printService.length;i++){
System.out.println(printService[i]);
}
ça renvoie par exemple :
Win32 Printer : Microsoft XPS Document Writer
Win32 Printer : HP Deskjet 3920/3940
Win32 Printer : CutePDF Writer
Win32 Printer : Brother HL-5270DN dev
Win32 Printer : Brother HL-5270DN autre
a toi de faire le decoupage par un split.
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
DocFlavor flavor =DocFlavor.INPUT_STREAM.AUTOSENSE;
String mime =flavor.getMimeType();
PrintService printService[] = PrintServiceLookup.lookupPrintServices(flavor, pras);
PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();
for(int i=0;i<printService.length;i++){
System.out.println(printService[i]);
}
ça renvoie par exemple :
Win32 Printer : Microsoft XPS Document Writer
Win32 Printer : HP Deskjet 3920/3940
Win32 Printer : CutePDF Writer
Win32 Printer : Brother HL-5270DN dev
Win32 Printer : Brother HL-5270DN autre
a toi de faire le decoupage par un split.