List of usage examples for javax.print.attribute HashPrintServiceAttributeSet HashPrintServiceAttributeSet
public HashPrintServiceAttributeSet()
From source file:ru.codemine.pos.service.kkm.template.JasperChequeTemplate.java
public void print(Cheque cheque, String printerName) throws JRException { List<JasperChequeRecord> records = new ArrayList<>(); for (ChequeLine line : cheque.getContent()) { records.add(new JasperChequeRecord(line.getProduct().getName(), line.getQuantity(), "=" + line.getLineTotal())); }/*from w w w . ja v a 2s .co m*/ Map<String, Object> parameters = new HashMap<>(); parameters.put("titleString", cheque.getShop().getOrgName()); parameters.put("reqs", "?? " + cheque.getShop().getOrgInn() + " " + cheque.getShop().getOrgKpp()); parameters.put("currentTime", DateTime.now().toString("dd.MM.YY HH:mm")); parameters.put("currentUser", cheque.getCreator().getUsername()); parameters.put("chequeNumber", "#0011"); parameters.put("chequeTotal", "=" + cheque.getChequeTotal()); parameters.put("paymentType", Cheque.getAvaiblePaymentTypes().get(cheque.getPaymentType())); parameters.put("fromClient", cheque.getChequeTotal().toString()); parameters.put("toClient", "0.0"); JasperReport report = (JasperReport) JRLoader.loadObjectFromFile("reports/ChequeTemplate.jasper"); JRBeanCollectionDataSource dataSource = new JRBeanCollectionDataSource(records); JasperPrint jasperPrint = JasperFillManager.fillReport(report, parameters, dataSource); PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet(); PrintServiceAttributeSet printServiceAttributeSet = new HashPrintServiceAttributeSet(); printServiceAttributeSet.add(new PrinterName(printerName, null)); JRPrintServiceExporter exporter = new JRPrintServiceExporter(); exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); SimplePrintServiceExporterConfiguration configuration = new SimplePrintServiceExporterConfiguration(); configuration.setPrintRequestAttributeSet(printRequestAttributeSet); configuration.setPrintServiceAttributeSet(printServiceAttributeSet); configuration.setDisplayPageDialog(false); configuration.setDisplayPrintDialog(false); exporter.setConfiguration(configuration); exporter.exportReport(); }
From source file:de.cenote.jasperstarter.Report.java
public void print() throws JRException { PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet(); //printRequestAttributeSet.add(MediaSizeName.ISO_A4); if (config.hasCopies()) { printRequestAttributeSet.add(new Copies(config.getCopies().intValue())); }/*from w ww . jav a 2 s .c o m*/ PrintServiceAttributeSet printServiceAttributeSet = new HashPrintServiceAttributeSet(); //printServiceAttributeSet.add(new PrinterName("Fax", null)); JRPrintServiceExporter exporter = new JRPrintServiceExporter(); if (config.hasReportName()) { jasperPrint.setName(config.getReportName()); } exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); SimplePrintServiceExporterConfiguration expConfig = new SimplePrintServiceExporterConfiguration(); if (config.hasPrinterName()) { String printerName = config.getPrinterName(); PrintService service = Printerlookup.getPrintservice(printerName, Boolean.TRUE, Boolean.TRUE); expConfig.setPrintService(service); if (config.isVerbose()) { System.out.println("printer-name: " + ((service == null) ? "No printer found with name \"" + printerName + "\"! Using default." : "found: " + service.getName())); } } //exporter.setParameter(JRExporterParameter.PAGE_INDEX, pageIndex); //exporter.setParameter(JRExporterParameter.START_PAGE_INDEX, pageStartIndex); //exporter.setParameter(JRExporterParameter.END_PAGE_INDEX, pageEndIndex); expConfig.setPrintRequestAttributeSet(printRequestAttributeSet); expConfig.setPrintServiceAttributeSet(printServiceAttributeSet); expConfig.setDisplayPageDialog(Boolean.FALSE); if (config.isWithPrintDialog()) { setLookAndFeel(); expConfig.setDisplayPrintDialog(Boolean.TRUE); } else { expConfig.setDisplayPrintDialog(Boolean.FALSE); } exporter.setConfiguration(expConfig); exporter.exportReport(); }
From source file:org.openvpms.report.jasper.AbstractJasperIMReport.java
/** * Prints a {@code JasperPrint} to a printer. * * @param print the object to print * @param properties the print properties * @throws ReportException if {@code print} contains no pages * @throws JRException for any error *//*from w ww .j av a 2 s . c om*/ private void print(JasperPrint print, PrintProperties properties) throws JRException { if (print.getPages().isEmpty()) { throw new ReportException(NoPagesToPrint); } if (log.isDebugEnabled()) { log.debug("PrinterName: " + properties.getPrinterName()); } JRPrintServiceExporter exporter = new JRPrintServiceExporter(); exporter.setExporterInput(new SimpleExporterInput(print)); PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); aset.add(new Copies(properties.getCopies())); MediaSizeName mediaSize = properties.getMediaSize(); OrientationRequested orientation = properties.getOrientation(); MediaTray tray = properties.getMediaTray(); Sides sides = properties.getSides(); if (mediaSize != null) { if (log.isDebugEnabled()) { log.debug("MediaSizeName: " + mediaSize); } aset.add(mediaSize); } if (orientation != null) { if (log.isDebugEnabled()) { log.debug("Orientation: " + orientation); } aset.add(orientation); } if (tray != null) { if (log.isDebugEnabled()) { log.debug("MediaTray: " + tray); } aset.add(tray); } if (sides != null) { if (log.isDebugEnabled()) { log.debug("Sides: " + sides); } aset.add(sides); } SimplePrintServiceExporterConfiguration printConfiguration = new SimplePrintServiceExporterConfiguration(); printConfiguration.setPrintRequestAttributeSet(aset); // set the printer name PrintServiceAttributeSet serviceAttributeSet = new HashPrintServiceAttributeSet(); serviceAttributeSet.add(new PrinterName(properties.getPrinterName(), null)); printConfiguration.setPrintServiceAttributeSet(serviceAttributeSet); exporter.setConfiguration(printConfiguration); // print it exporter.exportReport(); }