List of usage examples for javax.print.attribute PrintRequestAttributeSet add
public boolean add(Attribute attribute);
From source file:ru.trett.cis.services.PrinterServiceImpl.java
@Override public String print(String file) throws ApplicationException, FileNotFoundException, PrintException { DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE; PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); aset.add(MediaSizeName.ISO_A4); PrintService printServices = PrintServiceLookup.lookupDefaultPrintService(); if (printServices == null) throw new ApplicationException("Default printer not found"); LOGGER.info("Default printer is " + printServices.getName()); DocPrintJob printJob = printServices.createPrintJob(); FileInputStream fis = new FileInputStream(file); Doc doc = new SimpleDoc(fis, flavor, null); printJob.print(doc, aset);/*from w ww .ja va2 s . c om*/ return printServices.getName(); }
From source file:com.aw.core.report.ReportFileGenerator.java
public String generateAndPrint(String reportName, Map params, String tempDirectory, Connection conn) throws JRException { // force temp directory end with "/" // tempDirectory = formatDirectory(tempDirectory); // String fullOutFileName = generateFile(conn); // String fullPdfFileName = fullOutFileName + ".pdf"; // JasperExportManager.exportReportToPdfFile(fullOutFileName, fullPdfFileName); //Report loading and compilation // JasperDesign jasperDesign = JRXmlLoader.load(compiledReport); // JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign); // - Report execution // JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, conn); try {/*from w ww . j a va2 s. c om*/ // - Report creation to printer PrinterJob job = PrinterJob.getPrinterJob(); DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE; // This is the Flavour JasperReports uses PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); aset.add(MediaSizeName.ISO_A4); // ..or whatever the document size is PrintService service = null; if (job.printDialog(aset)) service = job.getPrintService(); InputStream jasperReport = new FileInputStream("C:/ProgFile/iReport-2.0.2/CorrelativoDocumento.jasper"); JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, conn); // Export the report using the JasperPrint instance JRExporter exporter = new JRPrintServiceExporter(); exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE_ATTRIBUTE_SET, service.getAttributes()); exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PAGE_DIALOG, Boolean.FALSE); exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG, Boolean.FALSE); exporter.exportReport(); // String fullPdfFileName = "D:\\test.pdf"; // JasperExportManager.exportReportToPdfFile(jasperPrint, fullPdfFileName); return null; } catch (FileNotFoundException e) { throw AWBusinessException.wrapUnhandledException(logger, e); } }
From source file:JuliaSet3.java
public void print() { // Get a list of all printers that can handle Printable objects. DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE; PrintService[] services = PrintServiceLookup.lookupPrintServices(flavor, null); // Set some define printing attributes PrintRequestAttributeSet printAttributes = new HashPrintRequestAttributeSet(); printAttributes.add(OrientationRequested.LANDSCAPE); // landscape mode printAttributes.add(Chromaticity.MONOCHROME); // print in mono // Display a dialog that allows the user to select one of the // available printers and to edit the default attributes PrintService service = ServiceUI.printDialog(null, 100, 100, services, null, null, printAttributes); // If the user canceled, don't do anything if (service == null) return;//from w ww.java 2 s. c om // Now call a method defined below to finish the printing printToService(service, printAttributes); }
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())); }// w ww .j a v a 2 s . co 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:edu.ku.brc.specify.ui.containers.ContainerTreePanel.java
/** * @param actionableTree/*from w w w .j a v a 2 s. com*/ */ public void print(final JTree actionableTree) { /*if (true) { PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); aset.add(OrientationRequested.LANDSCAPE); aset.add(new Copies(2)); aset.add(new JobName("My job", null)); // Create a print job PrinterJob pj = PrinterJob.getPrinterJob(); pj.setPrintable(this); // locate a print service that can handle the request PrintService[] services = PrinterJob.lookupPrintServices(); if (services.length > 0) { System.out.println("selected printer " + services[0].getName()); try { pj.setPrintService(services[0]); pj.pageDialog(aset); if(pj.printDialog(aset)) { pj.print(aset); } } catch (PrinterException pe) { System.err.println(pe); } } return; }*/ DefaultMutableTreeNode clonedTree = GhostActionableTree .makeDeepCopy((DefaultMutableTreeNode) actionableTree.getModel().getRoot()); GhostActionableTree printTree = new GhostActionableTree(this, new DefaultTreeModel(clonedTree)); printTree.setRowHeight(ROW_HEIGHT); //printTree.setEditable(false); //printTree.setVisibleRowCount(15); ContainerTreeRenderer renderer = new ContainerTreeRenderer(null, false, false); renderer.setBGColor(Color.WHITE); renderer.setFont(getFont().deriveFont(8.0f)); //renderer.setLeafIcon(IconManager.getIcon(CollectionObject.class.getSimpleName(), IconManager.IconSize.Std32)); //renderer.setVerticalTextPosition(SwingConstants.CENTER); printTree.setCellRenderer(renderer); for (int row = 0; row < printTree.getRowCount(); row++) { printTree.expandRow(row); } PrintablePanel p = new PrintablePanel(new BorderLayout(), printTree); p.add(printTree, BorderLayout.CENTER); PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); //PrinterResolution pr = new PrinterResolution(300, 300, PrinterResolution.DPI); //MediaPrintableArea mpa = new MediaPrintableArea(8,21, 210-16, 296-42, MediaPrintableArea.MM); //aset.add( MediaSizeName.IS); //aset.add( pr ); //aset.add( mpa ); aset.add(new Copies(1)); aset.add(OrientationRequested.PORTRAIT); aset.add(PrintQuality.HIGH); PrinterJob job = PrinterJob.getPrinterJob(); /*PageFormat pageFormat = job.defaultPage(); Paper paper = pageFormat.getPaper(); paper.setSize(pageFormat.getWidth(), pageFormat.getHeight()); paper.setImageableArea( 0, 0, pageFormat.getWidth(), pageFormat.getHeight() ); //aset.add( Fidelity.FIDELITY_TRUE ); pageFormat.setPaper(paper); Book book = new Book(); book.append(p, pageFormat, 1); job.setPageable(book);*/ job.setPrintable(p); boolean ok = job.printDialog(); if (ok) { try { job.print(aset); } catch (PrinterException ex) { ex.printStackTrace(); /* The job did not successfully complete */ } } }
From source file:com.sos.jitl.jasperreports.JobSchedulerJasperReportJob.java
/** * Dokument drucken.//from w w w .j a v a 2 s . co m * * @throws Exception */ private String printDocument() throws Exception { try { // druckername bestimmen String prName = getPrinter(); if (sosString.parseToString(prName).length() > 0) { JasperPrint jasperPrint = (JasperPrint) JRLoader.loadObject(filledReportFile); net.sf.jasperreports.engine.export.JRPrintServiceExporter exporter = new net.sf.jasperreports.engine.export.JRPrintServiceExporter(); // set the report to print exporter.setParameter( net.sf.jasperreports.engine.export.JRPrintServiceExporterParameter.JASPER_PRINT, jasperPrint); // count of report to print javax.print.attribute.PrintRequestAttributeSet aset = new javax.print.attribute.HashPrintRequestAttributeSet(); aset.add(new Copies(getPrinterCopies())); aset.add(MediaSizeName.ISO_A4); exporter.setParameter( net.sf.jasperreports.engine.export.JRPrintServiceExporterParameter.PRINT_REQUEST_ATTRIBUTE_SET, aset); // let the exporter know which printer we want to print on javax.print.attribute.PrintServiceAttributeSet serviceAttributeSet = new javax.print.attribute.HashPrintServiceAttributeSet(); serviceAttributeSet.add(new javax.print.attribute.standard.PrinterName(prName, null)); exporter.setParameter( net.sf.jasperreports.engine.export.JRPrintServiceExporterParameter.PRINT_SERVICE_ATTRIBUTE_SET, serviceAttributeSet); // print it exporter.exportReport(); spooler_log.info("..report successfully printed " + getPrinterCopies() + "x."); return "..report successfully printed " + getPrinterCopies() + "x."; } return ""; } catch (Exception e) { throw new Exception("..error in " + SOSClassUtil.getMethodName() + " " + e); } }
From source file:org.apache.camel.component.printer.PrinterProducer.java
private PrintRequestAttributeSet assignPrintAttributes() throws PrintException { PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet(); if (config.getCopies() >= 1) { printRequestAttributeSet.add(new Copies(config.getCopies())); } else {/*w w w . j a v a2 s . c o m*/ throw new PrintException("Number of print copies should be greater than zero"); } printRequestAttributeSet.add(config.getMediaSizeName()); printRequestAttributeSet.add(config.getInternalSides()); return printRequestAttributeSet; }
From source file:org.openmrs.module.pharmacy.page.controller.PharmacyGroupPageController.java
void printOrder(int orderID) { try {//w w w. ja va 2s . c o m DrugOrder order = (DrugOrder) Context.getOrderService().getOrder(orderID); drugorders drugorder = Context.getService(drugordersService.class).getDrugOrderByOrderID(orderID); PrintService service = PrintServiceLookup.lookupDefaultPrintService(); String OrderDetails = drugorder.getDrugName().getDisplayString() + " " + order.getDose() + " " + order.getDoseUnits().getDisplayString() + " " + order.getDuration() + " " + order.getDurationUnits().getDisplayString() + " " + order.getQuantity() + " " + order.getQuantityUnits() + "\n" + "Route: " + order.getRoute().getDisplayString() + " " + "Frequency: " + order.getFrequency().getName() + "\n" + "Start Date: " + drugorder.getStartDate().toString() + "\n" + "Patient Instructions: " + drugorder.getPatientInstructions(); try (InputStream is = new ByteArrayInputStream(OrderDetails.getBytes())) { PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet(); pras.add(new Copies(1)); if (service != null) { DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE; Doc doc = new SimpleDoc(is, flavor, null); DocPrintJob job = service.createPrintJob(); job.print(doc, pras); } } } catch (IOException | PrintException ex) { Logger.getLogger(PharmacyGroupPageController.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:org.openmrs.module.pharmacy.page.controller.PharmacySinglePageController.java
void printOrder(int orderID) { try {/*w w w. jav a 2 s. c o m*/ DrugOrder order = (DrugOrder) Context.getOrderService().getOrder(orderID); drugorders drugorder = Context.getService(drugordersService.class).getDrugOrderByOrderID(orderID); PrintService service = PrintServiceLookup.lookupDefaultPrintService(); String OrderDetails = drugorder.getDrugName().getDisplayString() + " " + order.getDose() + " " + order.getDoseUnits().getDisplayString() + " " + order.getDuration() + " " + order.getDurationUnits().getDisplayString() + " " + order.getQuantity() + " " + order.getQuantityUnits() + "\n" + "Route: " + order.getRoute().getDisplayString() + " " + "Frequency: " + order.getFrequency().getName() + "\n" + "Start Date: " + drugorder.getStartDate().toString() + "\n" + "Patient Instructions: " + drugorder.getPatientInstructions(); InputStream is = new ByteArrayInputStream(OrderDetails.getBytes()); PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet(); pras.add(new Copies(1)); if (service != null) { DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE; Doc doc = new SimpleDoc(is, flavor, null); DocPrintJob job = service.createPrintJob(); job.print(doc, pras); } is.close(); } catch (IOException | PrintException ex) { Logger.getLogger(PharmacySinglePageController.class.getName()).log(Level.SEVERE, null, ex); } }
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 ww w .j av a 2 s. co m 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(); }