}
}
if (printService == null)
{
throw new JRException("No suitable print service found.");
}
try
{
printerJob.setPrintService(printService);
}
catch (PrinterException e)
{
throw new JRException(e);
}
PrintRequestAttributeSet printRequestAttributeSet = null;
if(displayPrintDialogOnlyOnce || displayPageDialogOnlyOnce)
{
printRequestAttributeSet = new HashPrintRequestAttributeSet();
setDefaultPrintRequestAttributeSet(printRequestAttributeSet);
setOrientation((JasperPrint)jasperPrintList.get(0), printRequestAttributeSet);
if(displayPageDialogOnlyOnce)
{
if(printerJob.pageDialog(printRequestAttributeSet) == null)
{
return;
}
else
{
displayPageDialog = false;
}
}
if(displayPrintDialogOnlyOnce)
{
if(!printerJob.printDialog(printRequestAttributeSet))
{
printStatus = new Boolean[]{Boolean.FALSE};
return;
}
else
{
displayPrintDialog = false;
}
}
}
List status = new ArrayList();
// fix for bug ID artf1455 from jasperforge.org bug database
for(reportIndex = 0; reportIndex < jasperPrintList.size(); reportIndex++)
{
setJasperPrint((JasperPrint)jasperPrintList.get(reportIndex));
exporter = new JRGraphics2DExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.PROGRESS_MONITOR, parameters.get(JRExporterParameter.PROGRESS_MONITOR));
exporter.setParameter(JRExporterParameter.OFFSET_X, parameters.get(JRExporterParameter.OFFSET_X));
exporter.setParameter(JRExporterParameter.OFFSET_Y, parameters.get(JRExporterParameter.OFFSET_Y));
exporter.setParameter(JRGraphics2DExporterParameter.ZOOM_RATIO, parameters.get(JRGraphics2DExporterParameter.ZOOM_RATIO));
exporter.setParameter(JRExporterParameter.CLASS_LOADER, classLoader);
exporter.setParameter(JRExporterParameter.URL_HANDLER_FACTORY, urlHandlerFactory);
exporter.setParameter(JRExporterParameter.FILE_RESOLVER, fileResolver);
if (parameters.containsKey(JRExporterParameter.FILTER))
{
exporter.setParameter(JRExporterParameter.FILTER, filter);
}
exporter.setParameter(JRGraphics2DExporterParameter.MINIMIZE_PRINTER_JOB_SIZE, parameters.get(JRGraphics2DExporterParameter.MINIMIZE_PRINTER_JOB_SIZE));
if(displayPrintDialog || displayPageDialog ||
(!displayPrintDialogOnlyOnce && !displayPageDialogOnlyOnce))
{
printRequestAttributeSet = new HashPrintRequestAttributeSet();
setDefaultPrintRequestAttributeSet(printRequestAttributeSet);
setOrientation(jasperPrint, printRequestAttributeSet);
}
try
{
if (!isModeBatch)
{
printRequestAttributeSet.add(new PageRanges(startPageIndex + 1, endPageIndex + 1));
}
printerJob.setJobName("JasperReports - " + jasperPrint.getName());
if (displayPageDialog)
{
printerJob.pageDialog(printRequestAttributeSet);
}
if (displayPrintDialog)
{
if (printerJob.printDialog(printRequestAttributeSet))
{
status.add(Boolean.TRUE);
printerJob.print(printRequestAttributeSet);
}
else
{
status.add(Boolean.FALSE);
}
}
else
{
PageFormat pageFormat = printerJob.defaultPage();
Paper paper = pageFormat.getPaper();
switch (jasperPrint.getOrientationValue())
{
case LANDSCAPE :
{
pageFormat.setOrientation(PageFormat.LANDSCAPE);
paper.setSize(jasperPrint.getPageHeight(), jasperPrint.getPageWidth());
paper.setImageableArea(
0,
0,
jasperPrint.getPageHeight(),
jasperPrint.getPageWidth()
);
break;
}
case PORTRAIT :
default :
{
pageFormat.setOrientation(PageFormat.PORTRAIT);
paper.setSize(jasperPrint.getPageWidth(), jasperPrint.getPageHeight());
paper.setImageableArea(
0,
0,
jasperPrint.getPageWidth(),
jasperPrint.getPageHeight()
);
}
}
// setting the paper object back as getPaper() returns a clone
pageFormat.setPaper(paper);
printerJob.setPrintable(this, pageFormat);
printerJob.print(printRequestAttributeSet);
}
}
catch (PrinterException e)
{
throw new JRException(e);
}
}
printStatus = (Boolean[]) status.toArray(new Boolean[status.size()]);
printService = printerJob.getPrintService();