Código Java:
Ver originalpublic static void imprimirComprobante(int nro){
try{
conn = conexion.obtenerConexion();
String dir
= "DIRECCION REPORTE"; JasperReport reporteJasper = JasperCompileManager.compileReport(dir);
parametro.put("@nro", nro);
JasperPrint mostrarReporte = JasperFillManager.fillReport(reporteJasper,parametro, conn);
// ESTABLECE DATOS DE IMPRESORAS
PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);
int selectedService = 0;
for(int i = 0; i < services.length;i++){
if(services[i].getName().toUpperCase().contains('NOMBRE IMPRESORA')){
selectedService = i;
}
}
job.setPrintService(services[selectedService]);
PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet();
MediaSizeName mediaSizeName = MediaSize.findMedia(4,4,MediaPrintableArea.INCH);
printRequestAttributeSet.add(mediaSizeName);
printRequestAttributeSet.add(new Copies(1));
JRPrintServiceExporter exporter;
exporter = new JRPrintServiceExporter();
exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE, services[selectedService]);
exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE_ATTRIBUTE_SET, services[selectedService].getAttributes());
exporter.setParameter(JRPrintServiceExporterParameter.PRINT_REQUEST_ATTRIBUTE_SET, printRequestAttributeSet);
exporter.
setParameter(JRPrintServiceExporterParameter.
DISPLAY_PAGE_DIALOG,
Boolean.
FALSE); exporter.
setParameter(JRPrintServiceExporterParameter.
DISPLAY_PRINT_DIALOG,
Boolean.
FALSE); exporter.setParameter(JRExporterParameter.JASPER_PRINT, mostrarReporte);
exporter.exportReport();
}catch(JRException ex){
JOptionPane.
showMessageDialog(null,
"Error de JREEXEPCION: " + ex
);
JOptionPane.
showMessageDialog(null,
"ERROR PRINTEREXCEPCION " + ex
); }
}