Por: Daniel Alejandro Barrientos Quispe | Publicado el: 2018-03-31 08:51:40 | Pregunta cerrada |
Hola, estoy tratando de imprimir un reporte realizado con jasper report e ireport sin vista previa, el cual ya lo logre pero solo manda a imprimir con la impresora predeterminada del sistema, lo que estoy tratando es de yo definir con que impresora se debe imprimir el codigo actual es el siguiente.
JasperReport reporte;
JasperPrint jasperprint;
Conexion conexion=new Conexion();
try {
//se carga el reporte
reporte= (JasperReport)JRLoader.loadObject( new File("src\\reportes\\ListarPersonal.jasper"));
//se procesa el archivo jasper
jasperprint= JasperFillManager.fillReport(reporte, null,conexion.AbrirConexion());
//impresion de reporte
//TRUE : muestra la ventana de dialogo "preferenciade impresion" false imprime directamente con la impresora predeterminada
JasperPrintManager.printReport(jasperprint, true);
} catch (Exception e) {
JOptionPane.showMessageDialog(null,"Ocurrio un error e");
}
------------------------------------------------------------------
TAMBIEN conseguie este codigo para establecer la impresora pero se demora demasiado en mandar la impresion y aveces ni funciona
try {
//esto para el JasperReport
JasperReport reporte;
JasperPrint jasperPrint;
//se carga el reporte
reporte= (JasperReport)JRLoader.loadObject( new File("src\\reportes\\ListarEstudiantes.jasper"));
//se procesa el archivo jasper
jasperPrint= JasperFillManager.fillReport(reporte, null,conexion.AbrirConexion());
//se manda a la impresora
JRPrintServiceExporter jrprintServiceExporter = new JRPrintServiceExporter();
jrprintServiceExporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint );
jrprintServiceExporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE, impresora );
jrprintServiceExporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG, Boolean.TRUE);
jrprintServiceExporter.exportReport();
} catch (JRException ex) {
System.err.println("Error JRException: " + ex.getMessage());
}
QUISIERA USAR EL PRIMER METODO PERO DEFINIRLE CON QUE IMPRESORA QUIERO IMPRIMIR EL REPORTE. GRACIAS POR SU AYUDA DE ANTEMANO.
- Debes estar logueado para realizar comentarios