Print in two printers from idempiere 3.1

100 views
Skip to first unread message

Jose Orlando

unread,
Jul 26, 2017, 11:45:22 PM7/26/17
to iDempiere
Hello

i need to print directly in two printers from idempiere. Invoice is printed in a roll printer (pre printed form), and a work order (any jasper format) is printed in a laser printer

how idempiere select the correct printer? how assign a printer to a jasper report?

any ideas?

thansk,
Jose Orlando
ITSC S.A.

Jose Orlando

unread,
Jul 31, 2017, 9:41:24 AM7/31/17
to iDempiere
Any ideas? for example, in a restaurant implementation, how print in a kitchen printer?

thanks,

Patric

unread,
Jul 31, 2017, 1:23:42 PM7/31/17
to iDempiere
Hi,
I created a basic script to print directly and you can extend it if you want. It is stored on my bitbucket account. (aupatric script_silentprint). It is a basic idea and we use it on Debian, but I think it can be transfered to other opersting systems and it is easy to extend it to your needs.

Regards

Patric

Alan Lescano

unread,
Jul 31, 2017, 1:29:32 PM7/31/17
to idem...@googlegroups.com
Hi Jose Orlando

You can use CUPS as your printer server for the network printers, install the CUPS client in the idempiere server, and then create a process to send the job. Something like:

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();
}



--
You received this message because you are subscribed to the Google Groups "iDempiere" group.
To unsubscribe from this group and stop receiving emails from it, send an email to idempiere+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/idempiere/9cb0f740-51a7-4e06-9126-adf07cdb4c22%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages