Ver Mensaje Individual
  #2 (permalink)  
Antiguo 23/04/2014, 10:25
marcusaurelio
 
Fecha de Ingreso: enero-2007
Mensajes: 285
Antigüedad: 17 años, 3 meses
Puntos: 21
Respuesta: implments printable y seleccionar una impresora

ya lo resolvi... pero ahora.. necesito hacer un eventlistener para la impresion.. que me valla diciendo en que estado va quedando.. es decir. si comienza, si esta imprimiendo, si termino, y demas.. pero no lo consigo.. para printerJob.. veo que si esta para printJob.. pero no puedo implementarlo..

al menos necesitaria.. saber si la impresora esta prendida, enchufada o activa.. ya que por medio de este code...


Código:
public class MyPrintServiceAttributeListener implements PrintServiceAttributeListener {

    @Override
    public void attributeUpdate(PrintServiceAttributeEvent psae) {
        PrintService service = psae.getPrintService();
        Attribute[] attrs = psae.getAttributes().toArray();
        for (int i = 0; i < attrs.length; i++) {
            String attrName = attrs[i].getName();
            String attrValue = attrs[i].toString();
            System.out.println(service.getName()+": "+attrName+": "+attrValue+"\n");
        }
    }
}
pero solo me dice

Brother QL-570 LE: queued-job-count: 1

Brother QL-570 LE: printer-is-accepting-jobs: accepting-jobs

y siempre me dice printer-is-accepting-jobs: accepting-jobs, por mas que la apague..

hay manera de lograrlo esto.?

dejo el codigo de hasta donde voy.. por si a alguien le sirve
Código:
private void Imprimir() {

        PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);
        String printName = "Brother QL-570 LE";
        //String printName="PDFCreator";

        if (services.length > 0) {
            try {
                PrintService myService = null;
                int hayImpresora = 0;
                for (PrintService service : services) {
                    //System.out.println(service.getName());
                    if (service.getName().equals(printName)) {

                        myService = service;
                        hayImpresora = 1;
                        break;
                    }
                }

                if (hayImpresora == 0) {
                    JOptionPane.showMessageDialog(null, "No se Encontro la Impresora: " + printName);
                    //System.exit(0);
                }
                // myService.addPrintServiceAttributeListener(new MyPrintServiceAttributeListener());

                PrinterJob job = PrinterJob.getPrinterJob();

                job.getPrintService().addPrintServiceAttributeListener(null);
                PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
                aset.add(OrientationRequested.LANDSCAPE);
                aset.add(new MediaPrintableArea(2, 2, 29, 90, MediaPrintableArea.MM));

                job.setPrintService(myService);
                job.setPrintable(this);
                job.print(aset);

            } catch (PrinterException ex) {
                Logger.getLogger(dialogImprmirEtiqueta.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }