From a50e471830ae183dc630fcd8eae76477436f471f Mon Sep 17 00:00:00 2001 From: usrdno Date: Mon, 22 Mar 2010 09:24:29 +0000 Subject: [PATCH] BF 2973169 - Jasper documents always prints on system default printer. Now documents are printed on the printer selected in Adempiere or the printer specified on the print format (as it works with the old reports). https://sourceforge.net/tracker/index.php?func=detail&aid=2973169&group_id=176962&atid=879332 Link to SF Tracker: http://sourceforge.net/support/tracker.php?aid=2973169 --- .../org/compiere/report/ReportStarter.java | 76 +++++++++++++++-- client/src/org/compiere/print/ReportCtl.java | 81 +++++++++++++++---- 2 files changed, 138 insertions(+), 19 deletions(-) diff --git a/JasperReports/src/org/compiere/report/ReportStarter.java b/JasperReports/src/org/compiere/report/ReportStarter.java index 58034ead2d..21b00d2758 100644 --- a/JasperReports/src/org/compiere/report/ReportStarter.java +++ b/JasperReports/src/org/compiere/report/ReportStarter.java @@ -13,6 +13,7 @@ *****************************************************************************/ package org.compiere.report; +import java.awt.print.PrinterJob; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; @@ -45,8 +46,16 @@ import java.util.logging.Level; import javax.naming.InitialContext; import javax.naming.NamingException; +import javax.print.attribute.HashPrintRequestAttributeSet; +import javax.print.attribute.PrintRequestAttributeSet; +import javax.print.attribute.standard.Copies; +import javax.print.attribute.standard.JobName; +import javax.print.attribute.standard.MediaPrintableArea; +import javax.print.attribute.standard.MediaSize; +import javax.print.attribute.standard.MediaSizeName; import net.sf.jasperreports.engine.JRException; +import net.sf.jasperreports.engine.JRExporterParameter; import net.sf.jasperreports.engine.JRParameter; import net.sf.jasperreports.engine.JasperCompileManager; import net.sf.jasperreports.engine.JasperExportManager; @@ -54,6 +63,8 @@ import net.sf.jasperreports.engine.JasperFillManager; import net.sf.jasperreports.engine.JasperPrint; import net.sf.jasperreports.engine.JasperPrintManager; import net.sf.jasperreports.engine.JasperReport; +import net.sf.jasperreports.engine.export.JRPrintServiceExporter; +import net.sf.jasperreports.engine.export.JRPrintServiceExporterParameter; import net.sf.jasperreports.engine.util.JRLoader; import org.adempiere.exceptions.DBException; @@ -63,7 +74,13 @@ import org.compiere.model.MAttachment; import org.compiere.model.MAttachmentEntry; import org.compiere.model.MBPartner; import org.compiere.model.MProcess; +import org.compiere.model.PrintInfo; import org.compiere.model.X_AD_PInstance_Para; +import org.compiere.print.MPrintFormat; +import org.compiere.print.MPrintPaper; +import org.compiere.print.PrintUtil; +import org.compiere.print.ReportCtl; +import org.compiere.print.layout.LayoutEngine; import org.compiere.process.ClientProcess; import org.compiere.process.ProcessCall; import org.compiere.process.ProcessInfo; @@ -475,16 +492,37 @@ public class ReportStarter implements ProcessCall, ClientProcess params.put("AD_PINSTANCE_ID", new Integer( AD_PInstance_ID)); Language currLang = Env.getLanguage(Env.getCtx()); + String printerName = null; + MPrintFormat printFormat = null; + PrintInfo printInfo = null; ProcessInfoParameter[] pip = pi.getParameter(); - // Check for language parameter + // Get print format and print info parameters if (pip!=null) { for (int i=0; i 0) { - PrintInfo info = re.getPrintInfo(); ProcessInfo pi = new ProcessInfo ("", format.getJasperProcess_ID()); pi.setPrintPreview( !IsDirectPrint ); pi.setRecord_ID ( Record_ID ); - if (info.isDocument()) { - ProcessInfoParameter pip = new ProcessInfoParameter("CURRENT_LANG", format.getLanguage(), null, null, null); - pi.setParameter(new ProcessInfoParameter[]{pip}); + Vector jasperPrintParams = new Vector(); + ProcessInfoParameter pip; + if (printerName!=null && printerName.trim().length()>0) { + // Override printer name + pip = new ProcessInfoParameter(PARAM_PRINTER_NAME, printerName, null, null, null); } + pip = new ProcessInfoParameter(PARAM_PRINT_FORMAT, format, null, null, null); + jasperPrintParams.add(pip); + pip = new ProcessInfoParameter(PARAM_PRINT_INFO, re.getPrintInfo(), null, null, null); + jasperPrintParams.add(pip); + + pi.setParameter(jasperPrintParams.toArray(new ProcessInfoParameter[]{})); // Execute Process if (Ini.isClient()) @@ -319,7 +368,7 @@ public class ReportCtl } else { - createOutput(re, !IsDirectPrint); + createOutput(re, !IsDirectPrint, printerName); if (IsDirectPrint) { ReportEngine.printConfirm (type, Record_ID); @@ -357,12 +406,16 @@ public class ReportCtl return startDocumentPrint (ReportEngine.CHECK, C_PaySelectionCheck_ID, null, -1, IsDirectPrint); } // startCheckPrint - private static void createOutput(ReportEngine re, boolean printPreview) + private static void createOutput(ReportEngine re, boolean printPreview, String printerName) { if (printPreview) preview(re); - else - re.print(); + else { + if (printerName!=null) { + re.getPrintInfo().setPrinterName(printerName); + } + re.print(); + } } /**