);
}
pageOffset = firstPageIndex;
PrinterJob printJob = PrinterJob.getPrinterJob();
// fix for bug ID 6255588 from Sun bug database
initPrinterJobFields(printJob);
PageFormat pageFormat = printJob.defaultPage();
Paper paper = pageFormat.getPaper();
printJob.setJobName("JasperReports - " + jasperPrint.getName());
switch (jasperPrint.getOrientation())
{
case JRReport.ORIENTATION_LANDSCAPE :
{
pageFormat.setOrientation(PageFormat.LANDSCAPE);
paper.setSize(jasperPrint.getPageHeight(), jasperPrint.getPageWidth());
paper.setImageableArea(
0,
0,
jasperPrint.getPageHeight(),
jasperPrint.getPageWidth()
);
break;
}
case JRReport.ORIENTATION_PORTRAIT :
default :
{
pageFormat.setOrientation(PageFormat.PORTRAIT);
paper.setSize(jasperPrint.getPageWidth(), jasperPrint.getPageHeight());
paper.setImageableArea(
0,
0,
jasperPrint.getPageWidth(),
jasperPrint.getPageHeight()
);
}
}
pageFormat.setPaper(paper);
Book book = new Book();
book.append(this, pageFormat, lastPageIndex - firstPageIndex + 1);
printJob.setPageable(book);
try
{
if (service == null) {
if (printJob.printDialog()) {
printJob.print();
}
} else {
printJob.setPrintService(service);
printJob.print();
}
}
catch (Exception ex)
{
throw new JRException("Error printing report.", ex);