java seleccionar impresora

Solutions on MaxInterview for java seleccionar impresora by the best coders in the world

showing results for - "java seleccionar impresora"
Isra
04 Sep 2018
1 1import javax.print.PrintService;
2import javax.print.PrintServiceLookup;
3import javax.print.attribute.Attribute;
4import javax.print.attribute.AttributeSet;
5import javax.print.attribute.HashAttributeSet;
6import javax.print.attribute.PrintServiceAttributeSet;
7import javax.print.attribute.standard.Destination;
8import javax.print.attribute.standard.PrinterInfo;
9import javax.print.attribute.standard.PrinterIsAcceptingJobs;
10import javax.print.attribute.standard.PrinterLocation;
11import javax.print.attribute.standard.PrinterMakeAndModel;
12import javax.print.attribute.standard.PrinterName;
13import javax.print.attribute.standard.PrinterState;
14
15/**
16 * Ejemplos para ver tus impresoras
17 * @author Peiretti
18 */
19public class PrintExamples {
20
21    /**
22     * @param args
23     */
24    public static void main(String[] args) {
25
26        printAvailable();
27        printDefault();
28        printByName("MiImpresora");
29    }
30
31    public static void printAvailable() {
32
33        // busca los servicios de impresion...
34        PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);
35
36        // -- ver los atributos de las impresoras...
37        for (PrintService printService : services) {
38
39            System.out.println(" ---- IMPRESORA: " + printService.getName());
40
41            PrintServiceAttributeSet printServiceAttributeSet = printService.getAttributes();
42
43            System.out.println("--- atributos");
44
45            // todos los atributos de la impresora
46            Attribute[] a = printServiceAttributeSet.toArray();
47            for (Attribute unAtribute : a) {
48                System.out.println("atributo: " + unAtribute.getName());
49            }
50
51            System.out.println("--- viendo valores especificos de los atributos ");
52
53            // valor especifico de un determinado atributo de la impresora
54            System.out.println("PrinterLocation: " + printServiceAttributeSet.get(PrinterLocation.class));
55            System.out.println("PrinterInfo: " + printServiceAttributeSet.get(PrinterInfo.class));
56            System.out.println("PrinterState: " + printServiceAttributeSet.get(PrinterState.class));
57            System.out.println("Destination: " + printServiceAttributeSet.get(Destination.class));
58            System.out.println("PrinterMakeAndModel: " + printServiceAttributeSet.get(PrinterMakeAndModel.class));
59            System.out.println("PrinterIsAcceptingJobs: " + printServiceAttributeSet.get(PrinterIsAcceptingJobs.class));
60
61        }
62
63    }
64
65    public static void printDefault() {
66
67        // tu impresora por default
68        PrintService service = PrintServiceLookup.lookupDefaultPrintService();
69        System.out.println("Tu impresora por default es: " + service.getName());
70
71    }
72
73    public static void printByName(String printName) {
74
75        PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);
76
77        // buscar por el nombre de la impresora (nombre que le diste en tu S.O.)
78        // en "aset" puedes agregar mas atributos de busqueda
79        AttributeSet aset = new HashAttributeSet();
80        aset.add(new PrinterName(printName, null));
81        //aset.add(ColorSupported.SUPPORTED); // si quisieras buscar ademas las que soporten color
82
83        services = PrintServiceLookup.lookupPrintServices(null, aset);
84        if(services.length == 0){
85            System.out.println("No se encontro impresora con nombre " + printName);
86        }
87        for (PrintService printService : services) {
88            System.out.println(printService.getName());
89        }
90    }
91}
92 2
93 3
94 4
95 5
96 6
97 7
98 8
99 9
10010
10111
10212
10313
10414
10515
10616
10717
10818
10919
11020
11121
11222
11323
11424
11525
11626
11727
11828
11929
12030
12131
12232
12333
12434
12535
12636
12737
12838
12939
13040
13141
13242
13343
13444
13545
13646
13747
13848
13949
14050
14151
14252
14353
14454
14555
14656
14757
14858
14959
15060
15161
15262
15363
15464
15565
15666
15767
15868
15969
16070
16171
16272
16373
16474
16575
16676
16777
16878
16979
17080
17181
17282
17383
17484
17585
17686
17787
17888
17989
18090
18191
182