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
This commit is contained in:
parent
f479ca2beb
commit
a50e471830
|
@ -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<pip.length; i++) {
|
||||
if ("CURRENT_LANG".equalsIgnoreCase(pip[i].getParameterName())) {
|
||||
currLang = (Language)pip[i].getParameter();
|
||||
if (ReportCtl.PARAM_PRINT_FORMAT.equalsIgnoreCase(pip[i].getParameterName())) {
|
||||
printFormat = (MPrintFormat)pip[i].getParameter();
|
||||
}
|
||||
if (ReportCtl.PARAM_PRINT_INFO.equalsIgnoreCase(pip[i].getParameterName())) {
|
||||
printInfo = (PrintInfo)pip[i].getParameter();
|
||||
}
|
||||
if (ReportCtl.PARAM_PRINTER_NAME.equalsIgnoreCase(pip[i].getParameterName())) {
|
||||
printerName = (String)pip[i].getParameter();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (printFormat!=null) {
|
||||
if (printInfo!=null) {
|
||||
// Set the language of the print format if we're printing a document
|
||||
if (printInfo.isDocument()) {
|
||||
currLang = printFormat.getLanguage();
|
||||
}
|
||||
}
|
||||
// Set printer name unless already set.
|
||||
if (printerName==null) {
|
||||
printerName = printFormat.getPrinterName();
|
||||
}
|
||||
}
|
||||
|
||||
params.put("CURRENT_LANG", currLang.getAD_Language());
|
||||
params.put(JRParameter.REPORT_LOCALE, currLang.getLocale());
|
||||
|
||||
|
@ -525,7 +563,35 @@ public class ReportStarter implements ProcessCall, ClientProcess
|
|||
log.info( "ReportStarter.startProcess print report -" + jasperPrint.getName());
|
||||
//RF 1906632
|
||||
if (!processInfo.isBatch()) {
|
||||
JasperPrintManager.printReport( jasperPrint, false);
|
||||
|
||||
// Get printer job
|
||||
PrinterJob printerJob = org.compiere.print.CPrinter.getPrinterJob(printerName);
|
||||
// Set print request attributes
|
||||
|
||||
// Paper Attributes:
|
||||
PrintRequestAttributeSet prats = new HashPrintRequestAttributeSet();
|
||||
|
||||
// add: copies, job-name, priority
|
||||
if (printInfo.isDocumentCopy() || printInfo.getCopies() < 1)
|
||||
prats.add (new Copies(1));
|
||||
else
|
||||
prats.add (new Copies(printInfo.getCopies()));
|
||||
Locale locale = Language.getLoginLanguage().getLocale();
|
||||
prats.add(new JobName(printFormat.getName() + "_" + pi.getRecord_ID(), locale));
|
||||
prats.add(PrintUtil.getJobPriority(jasperPrint.getPages().size() , printInfo.getCopies(), true));
|
||||
|
||||
// Create print service exporter
|
||||
JRPrintServiceExporter exporter = new JRPrintServiceExporter();;
|
||||
// Set parameters
|
||||
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
|
||||
exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE, printerJob.getPrintService());
|
||||
exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE_ATTRIBUTE_SET, printerJob.getPrintService().getAttributes());
|
||||
exporter.setParameter(JRPrintServiceExporterParameter.PRINT_REQUEST_ATTRIBUTE_SET, prats);
|
||||
exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PAGE_DIALOG, Boolean.FALSE);
|
||||
exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG, Boolean.FALSE);
|
||||
// Print report / document
|
||||
exporter.exportReport();
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -18,6 +18,7 @@ package org.compiere.print;
|
|||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Properties;
|
||||
import java.util.Vector;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.adempiere.exceptions.AdempiereException;
|
||||
|
@ -54,6 +55,13 @@ public class ReportCtl
|
|||
{
|
||||
} // ReportCtrl
|
||||
|
||||
/**
|
||||
* Constants used to pass process parameters to Jasper Process
|
||||
*/
|
||||
public static final String PARAM_PRINTER_NAME = "PRINTER_NAME";
|
||||
public static final String PARAM_PRINT_FORMAT = "PRINT_FORMAT";
|
||||
public static final String PARAM_PRINT_INFO = "PRINT_INFO";
|
||||
|
||||
/** Static Logger */
|
||||
private static CLogger s_log = CLogger.getCLogger (ReportCtl.class);
|
||||
|
||||
|
@ -183,7 +191,7 @@ public class ReportCtl
|
|||
MQuery query = MQuery.get (ctx, pi.getAD_PInstance_ID(), TableName);
|
||||
PrintInfo info = new PrintInfo(pi);
|
||||
re = new ReportEngine(ctx, format, query, info);
|
||||
createOutput(re, pi.isPrintPreview());
|
||||
createOutput(re, pi.isPrintPreview(), null);
|
||||
return true;
|
||||
}
|
||||
//
|
||||
|
@ -197,7 +205,7 @@ public class ReportCtl
|
|||
}
|
||||
}
|
||||
|
||||
createOutput(re, pi.isPrintPreview());
|
||||
createOutput(re, pi.isPrintPreview(), null);
|
||||
return true;
|
||||
} // startStandardReport
|
||||
|
||||
|
@ -226,7 +234,7 @@ public class ReportCtl
|
|||
PrintInfo info = new PrintInfo(pi);
|
||||
|
||||
ReportEngine re = new ReportEngine(Env.getCtx(), format, query, info);
|
||||
createOutput(re, pi.isPrintPreview());
|
||||
createOutput(re, pi.isPrintPreview(), null);
|
||||
return true;
|
||||
} // startFinReport
|
||||
|
||||
|
@ -243,6 +251,21 @@ public class ReportCtl
|
|||
return startDocumentPrint(type, Record_ID, null, -1, IsDirectPrint);
|
||||
}
|
||||
|
||||
/**
|
||||
* Start Document Print for Type with specified printer. Always direct print.
|
||||
* @param type document type in ReportEngine
|
||||
* @param customPrintFormat Custom print format. Can be null.
|
||||
* @param Record_ID id
|
||||
* @param parent The window which invoked the printing
|
||||
* @param WindowNo The windows number which invoked the printing
|
||||
* @param printerName Specified printer name
|
||||
* @return true if success
|
||||
*/
|
||||
public static boolean startDocumentPrint(int type, MPrintFormat customPrintFormat, int Record_ID, ASyncProcess parent, int WindowNo, String printerName)
|
||||
{
|
||||
return(startDocumentPrint(type, customPrintFormat, Record_ID, parent, WindowNo, true, printerName));
|
||||
}
|
||||
|
||||
/**
|
||||
* Start Document Print for Type.
|
||||
* Called also directly from ProcessDialog, VInOutGen, VInvoiceGen, VPayPrint
|
||||
|
@ -253,8 +276,23 @@ public class ReportCtl
|
|||
* @param IsDirectPrint if true, prints directly - otherwise View
|
||||
* @return true if success
|
||||
*/
|
||||
public static boolean startDocumentPrint (int type, int Record_ID, ASyncProcess parent, int WindowNo,
|
||||
boolean IsDirectPrint)
|
||||
public static boolean startDocumentPrint(int type, int Record_ID, ASyncProcess parent, int WindowNo,
|
||||
boolean IsDirectPrint)
|
||||
{
|
||||
return(startDocumentPrint(type, null, Record_ID, parent, WindowNo, IsDirectPrint, null ));
|
||||
}
|
||||
|
||||
/**
|
||||
* Start Document Print for Type with specified printer.
|
||||
* @param type document type in ReportEngine
|
||||
* @param Record_ID id
|
||||
* @param parent The window which invoked the printing
|
||||
* @param WindowNo The windows number which invoked the printing
|
||||
* @param printerName Specified printer name
|
||||
* @return true if success
|
||||
*/
|
||||
public static boolean startDocumentPrint (int type, MPrintFormat customPrintFormat, int Record_ID, ASyncProcess parent, int WindowNo,
|
||||
boolean IsDirectPrint, String printerName)
|
||||
{
|
||||
ReportEngine re = ReportEngine.get (Env.getCtx(), type, Record_ID);
|
||||
if (re == null)
|
||||
|
@ -280,20 +318,31 @@ public class ReportCtl
|
|||
}
|
||||
return false;
|
||||
}
|
||||
if (customPrintFormat!=null) {
|
||||
// Use custom print format if available
|
||||
re.setPrintFormat(customPrintFormat);
|
||||
}
|
||||
|
||||
if(re.getPrintFormat() != null)
|
||||
if(re.getPrintFormat()!=null)
|
||||
{
|
||||
MPrintFormat format = re.getPrintFormat();
|
||||
if(format.getJasperProcess_ID() > 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<ProcessInfoParameter> jasperPrintParams = new Vector<ProcessInfoParameter>();
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue