// Linux: print queues like "draft", "normal", "photo", etc
// Windows: use physical printername like "Epson Stylus COLOR 680" or "HP LaserJet 5000 Series PCL"
PrinterName printerName = new PrinterName("normal", Locale.getDefault());
printServiceAttributeSet.add(printerName);
JRPrintServiceExporter exporter = new JRPrintServiceExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(
JRPrintServiceExporterParameter.PRINT_REQUEST_ATTRIBUTE_SET,
printRequestAttributeSet);
exporter.setParameter(
JRPrintServiceExporterParameter.PRINT_SERVICE_ATTRIBUTE_SET,
printServiceAttributeSet);
exporter.setParameter(
JRPrintServiceExporterParameter.DISPLAY_PAGE_DIALOG,
Boolean.FALSE);
exporter.setParameter(
JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG,
Boolean.TRUE);
boolean preview = true;
try {
if (preview) {
// preview is started in non_modal
JasperViewer.viewReport(jasperPrint, false);
} else {
exporter.exportReport();
}
} catch (JRException je) {
System.out.println(
"Error printing report:\n" + je.getMessage());
}