Created
February 26, 2017 19:21
-
-
Save isu3ru/95a7ca695c394c7a0f6e62d936289ef2 to your computer and use it in GitHub Desktop.
A java method to prompt a printer selection and send jasper report print to the selected printer.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void PrintReportToPrinter(JasperPrint jp) throws Exception { | |
PrintService[] lps = PrintServiceLookup.lookupPrintServices(null, null); | |
PrintService srv = (PrintService) JOptionPane.showInputDialog(this, "Select printer", "Printer", JOptionPane.PLAIN_MESSAGE, null, lps, lps[0]); | |
PrinterJob printerJob = PrinterJob.getPrinterJob(); | |
printerJob.setPrintService(srv); | |
PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet(); | |
printRequestAttributeSet.add(new Copies(1)); | |
JRPrintServiceExporter exporter = new JRPrintServiceExporter(); | |
exporter.setExporterInput(new SimpleExporterInput(jp)); | |
exporter.exportReport(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment