List of usage examples for javax.print PrintServiceLookup lookupDefaultPrintService
public static final PrintService lookupDefaultPrintService()
From source file:org.apache.camel.component.printer.PrinterOperations.java
public PrinterOperations() throws PrintException { printService = PrintServiceLookup.lookupDefaultPrintService(); if (printService == null) { throw new PrintException("Printer lookup failure. No default printer set up for this host"); }/*from w ww . j ava 2s . co m*/ job = printService.createPrintJob(); flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE; printRequestAttributeSet = new HashPrintRequestAttributeSet(); printRequestAttributeSet.add(new Copies(1)); printRequestAttributeSet.add(MediaSizeName.NA_LETTER); printRequestAttributeSet.add(Sides.ONE_SIDED); }
From source file:org.apache.camel.component.printer.PrinterProducer.java
private PrintService assignPrintService() throws PrintException { PrintService printService;/* www .j av a 2s . c o m*/ if ((config.getHostname().equalsIgnoreCase("localhost")) && (config.getPrintername().equalsIgnoreCase("/default"))) { printService = PrintServiceLookup.lookupDefaultPrintService(); } else { PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null); setPrinter("\\\\" + config.getHostname() + "\\" + config.getPrintername()); int position = findPrinter(services, printer); if (position < 0) { throw new PrintException("No printer found with name: " + printer + ". Please verify that the host and printer are registered and reachable from this machine."); } printService = services[position]; } return printService; }
From source file:org.nuclos.server.report.ejb3.ReportFacadeBean.java
public NuclosReportRemotePrintService lookupDefaultPrintService() throws NuclosReportException { PrintService ps = PrintServiceLookup.lookupDefaultPrintService(); if (ps == null) { String defprinter = System.getProperty("javax.print.defaultPrinter"); if (defprinter != null) { PrintService[] prservices = PrintServiceLookup.lookupPrintServices(null, null); if (null == prservices || 0 >= prservices.length) { throw new NuclosReportException( "Es ist kein passender Print-Service installiert. " + defprinter); // @todo }/* w w w . ja v a 2 s . com*/ for (int i = 0; i < prservices.length; i++) { PrintService printService = prservices[i]; if (printService.getName().equals(defprinter)) { return new NuclosReportRemotePrintService(printService); } } throw new NuclosReportException( "Es ist kein passender Default Print-Service installiert. " + defprinter); // @todo } throw new NuclosReportException("Es ist kein passender Default Print-Service installiert."); // @todo } return new NuclosReportRemotePrintService(ps); }
From source file:org.nuclos.server.report.ejb3.ReportFacadeBean.java
public NuclosReportRemotePrintService[] lookupPrintServices(DocFlavor flavor, AttributeSet as) throws NuclosReportException { PrintService prservDflt = PrintServiceLookup.lookupDefaultPrintService(); PrintService[] prservices = PrintServiceLookup.lookupPrintServices(flavor, as); if (null == prservices || 0 >= prservices.length) { if (null != prservDflt) { prservices = new PrintService[] { prservDflt }; } else {//from w w w . j av a 2 s . c o m throw new NuclosReportException("Es ist kein passender Print-Service installiert."); // @todo } } NuclosReportRemotePrintService[] rprservices = new NuclosReportRemotePrintService[prservices.length]; for (int i = 0; i < prservices.length; i++) { rprservices[i] = new NuclosReportRemotePrintService(prservices[i]); } return rprservices; }
From source file:org.openmrs.module.pharmacy.page.controller.PharmacyGroupPageController.java
void printOrder(int orderID) { try {/* w w w . j ava2 s . c om*/ 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 {/*from w w w.j a va2 s . com*/ 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.pentaho.reporting.engine.classic.extensions.modules.java14print.Java14PrintUtil.java
private static PrintService lookupPrintService() throws PrintException { final PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService(); if (defaultService != null && defaultService.isDocFlavorSupported(DocFlavor.SERVICE_FORMATTED.PAGEABLE)) { return defaultService; }//from www. j a v a 2 s . c om final PrintService printService; final PrintService[] services = PrintServiceLookup.lookupPrintServices(DocFlavor.SERVICE_FORMATTED.PAGEABLE, null); if (services.length == 0) { throw new PrintException("Unable to find a matching print service implementation."); } printService = services[0]; return printService; }
From source file:org.pentaho.reporting.platform.plugin.SimpleReportingAction.java
/** * Perform the primary function of this component, this is, to execute. This method will be invoked immediately following a successful validate(). * * @return true if successful execution//w w w. j a va 2 s . co m * @throws Exception */ public boolean _execute() throws Exception { final MasterReport report = getReport(); try { final DefaultParameterContext parameterContext = new DefaultParameterContext(report); // open parameter context final ValidationResult vr = applyInputsToReportParameters(parameterContext, null); if (vr.isEmpty() == false) { return false; } parameterContext.close(); if (isPrint()) { // handle printing // basic logic here is: get the default printer, attempt to resolve the user specified printer, default back as needed PrintService printService = PrintServiceLookup.lookupDefaultPrintService(); if (StringUtils.isEmpty(getPrinter()) == false) { final PrintService[] services = PrintServiceLookup .lookupPrintServices(DocFlavor.SERVICE_FORMATTED.PAGEABLE, null); for (final PrintService service : services) { if (service.getName().equals(printer)) { printService = service; } } if ((printer == null) && (services.length > 0)) { printService = services[0]; } } Java14PrintUtil.printDirectly(report, printService); return true; } final String outputType = computeEffectiveOutputTarget(); final ReportOutputHandler reportOutputHandler = createOutputHandlerForOutputType(outputType); if (reportOutputHandler == null) { log.warn(Messages.getInstance().getString("ReportPlugin.warnUnprocessableRequest", outputType)); return false; } synchronized (reportOutputHandler.getReportLock()) { try { pageCount = reportOutputHandler.generate(report, acceptedPage, outputStream, getYieldRate()); return pageCount != -1; } finally { reportOutputHandler.close(); } } } catch (Throwable t) { log.error(Messages.getInstance().getString("ReportPlugin.executionFailed"), t); //$NON-NLS-1$ } // lets not pretend we were successfull, if the export type was not a valid one. return false; }
From source file:org.pentaho.reporting.platform.plugin.SimpleReportingComponent.java
/** * Perform the primary function of this component, this is, to execute. This method will be invoked immediately following a successful validate(). * * @return true if successful execution/*from w ww . java2s. co m*/ * @throws Exception */ public boolean execute() throws Exception { final MasterReport report = getReport(); try { final DefaultParameterContext parameterContext = new DefaultParameterContext(report); // open parameter context final ValidationResult vr = applyInputsToReportParameters(parameterContext, null); if (vr.isEmpty() == false) { return false; } parameterContext.close(); if (isPrint()) { // handle printing // basic logic here is: get the default printer, attempt to resolve the user specified printer, default back as needed PrintService printService = PrintServiceLookup.lookupDefaultPrintService(); if (StringUtils.isEmpty(getPrinter()) == false) { final PrintService[] services = PrintServiceLookup .lookupPrintServices(DocFlavor.SERVICE_FORMATTED.PAGEABLE, null); for (final PrintService service : services) { if (service.getName().equals(printer)) { printService = service; } } if ((printer == null) && (services.length > 0)) { printService = services[0]; } } Java14PrintUtil.printDirectly(report, printService); return true; } final String outputType = computeEffectiveOutputTarget(); final ReportOutputHandler reportOutputHandler = createOutputHandlerForOutputType(outputType); if (reportOutputHandler == null) { log.warn(Messages.getInstance().getString("ReportPlugin.warnUnprocessableRequest", outputType)); return false; } synchronized (reportOutputHandler.getReportLock()) { try { pageCount = reportOutputHandler.generate(report, acceptedPage, outputStream, getYieldRate()); return pageCount != -1; } finally { reportOutputHandler.close(); } } } catch (Throwable t) { log.error(Messages.getInstance().getString("ReportPlugin.executionFailed"), t); //$NON-NLS-1$ } // lets not pretend we were successfull, if the export type was not a valid one. return false; }
From source file:org.saiku.adhoc.service.report.SaikuReportingComponent.java
public boolean execute() throws Exception { final MasterReport report = getReport(); try {// w w w . ja v a 2 s .c om final DefaultParameterContext parameterContext = new DefaultParameterContext(report); // open parameter context final ValidationResult vr = applyInputsToReportParameters(parameterContext, null); if (vr.isEmpty() == false) { return false; } parameterContext.close(); if (isPrint()) { // handle printing // basic logic here is: get the default printer, attempt to resolve the user specified printer, default // back as needed PrintService printService = PrintServiceLookup.lookupDefaultPrintService(); if (StringUtils.isEmpty(getPrinter()) == false) { final PrintService[] services = PrintServiceLookup .lookupPrintServices(DocFlavor.SERVICE_FORMATTED.PAGEABLE, null); for (final PrintService service : services) { if (service.getName().equals(printer)) { printService = service; } } if ((printer == null) && (services.length > 0)) { printService = services[0]; } } Java14PrintUtil.printDirectly(report, printService); return true; } final String outputType = computeEffectiveOutputTarget(); final ReportOutputHandler reportOutputHandler = createOutputHandlerForOutputType(outputType); if (reportOutputHandler == null) { log.warn(Messages.getInstance().getString("ReportPlugin.warnUnprocessableRequest", outputType)); return false; } synchronized (reportOutputHandler.getReportLock()) { try { pageCount = reportOutputHandler.generate(report, acceptedPage, outputStream, getYieldRate()); return pageCount != -1; } finally { reportOutputHandler.close(); } } } catch (Throwable t) { log.error(Messages.getInstance().getString("ReportPlugin.executionFailed"), t); //$NON-NLS-1$ } // lets not pretend we were successfull, if the export type was not a valid one. return false; }