private void print(MInOut shipment) {
ReportEngine re = ReportEngine.get (Env.getCtx(), ReportEngine.SHIPMENT, shipment.get_ID(), get_TrxName());
if(re.getPrintFormat() != null) {
re.getPrintInfo().setPrinterName("Lexmark_MX511de");
re.print();
}
}
private void print(JasperPrint jasperPrint) throws PrinterException, JRException {
PrinterJob job = PrinterJob.getPrinterJob();
// Create an array of PrintServices
PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);
int selectedService = 0;
// Scan found services to see if anyone suits our needs
boolean found = false;
for(int i = 0; i < services.length;i++){
if(services[i].getName().contains("Lexmark_MX511de")){
//If the service is named as what we are querying we select it
found = true;
selectedService = i;
}
}
if (!found)
log.severe("Can't find printer " + p_PrinterName);
job.setPrintService(services[selectedService]);
PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet();
MediaSizeName mediaSizeName = MediaSizeName.ISO_A4;
printRequestAttributeSet.add(mediaSizeName);
printRequestAttributeSet.add(new Copies(1));
JRPrintServiceExporter exporter = new JRPrintServiceExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
// We set the selected service and pass it as a paramenter
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.exportReport();
}