);
}
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.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()
);
}
}
pageFormat.setPaper(paper);
Book book = new Book();
book.append(this, pageFormat, lastPageIndex - firstPageIndex + 1);
printJob.setPageable(book);
try
{
if (withPrintDialog)
{
if (printJob.printDialog())
{
printJob.print();
}
else
{
isOK = false;
}
}
else
{
printJob.print();
}
}
catch (Exception ex)
{
throw new JRException("Error printing report.", ex);