Ver Mensaje Individual
  #2 (permalink)  
Antiguo 20/02/2017, 17:38
abrahamhs
 
Fecha de Ingreso: enero-2009
Ubicación: Kandor
Mensajes: 209
Antigüedad: 15 años, 3 meses
Puntos: 11
Respuesta: PrintQueueStatus en java

Código Java:
Ver original
  1. public static void imprimirComprobante(int nro){
  2.  
  3.     try{
  4.         Connection conn = null;
  5.         conn = conexion.obtenerConexion();
  6.         String dir= "DIRECCION REPORTE";
  7.         JasperReport reporteJasper = JasperCompileManager.compileReport(dir);
  8.         Map parametro = new HashMap();
  9.         parametro.put("@nro", nro);
  10.         JasperPrint mostrarReporte = JasperFillManager.fillReport(reporteJasper,parametro, conn);
  11.  
  12.  
  13.  
  14.     // ESTABLECE DATOS DE IMPRESORAS
  15.  
  16.         PrinterJob job = PrinterJob.getPrinterJob();
  17.         PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);
  18.         int selectedService = 0;
  19.         for(int i = 0; i < services.length;i++){
  20.         if(services[i].getName().toUpperCase().contains('NOMBRE IMPRESORA')){
  21.         selectedService = i;
  22.         }
  23.  
  24.         }
  25.  
  26.           job.setPrintService(services[selectedService]);
  27.           PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet();
  28.           MediaSizeName mediaSizeName = MediaSize.findMedia(4,4,MediaPrintableArea.INCH);
  29.           printRequestAttributeSet.add(mediaSizeName);
  30.           printRequestAttributeSet.add(new Copies(1));
  31.           JRPrintServiceExporter exporter;
  32.           exporter = new JRPrintServiceExporter();
  33.           exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE, services[selectedService]);
  34.         exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE_ATTRIBUTE_SET, services[selectedService].getAttributes());
  35.         exporter.setParameter(JRPrintServiceExporterParameter.PRINT_REQUEST_ATTRIBUTE_SET, printRequestAttributeSet);
  36.         exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PAGE_DIALOG, Boolean.FALSE);
  37.         exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG, Boolean.FALSE);
  38.         exporter.setParameter(JRExporterParameter.JASPER_PRINT, mostrarReporte);
  39.         exporter.exportReport();
  40.     }catch(JRException ex){
  41.         JOptionPane.showMessageDialog(null, "Error de JREEXEPCION: " + ex);
  42.  
  43.     } catch (PrinterException ex) {
  44.         JOptionPane.showMessageDialog(null,"ERROR PRINTEREXCEPCION " + ex);
  45.     }
  46.  
  47. }