Example usage for javax.print PrintService getName

List of usage examples for javax.print PrintService getName

Introduction

In this page you can find the example usage for javax.print PrintService getName.

Prototype

public String getName();

Source Link

Document

Returns a string name for this print service which may be used by applications to request a particular print service.

Usage

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  w w.j a  va2s  .  c om*/
    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:com.turborep.turbotracker.banking.controller.BankingController.java

@RequestMapping(value = "/selectprinter", method = RequestMethod.POST)
public @ResponseBody String selectPrinter(
        @RequestParam(value = "bankAccounts", required = false) Integer bankAccountsID,
        @RequestParam(value = "checksDate", required = false) Date checkDate,
        @RequestParam(value = "checkType", required = false) String checkType,
        @RequestParam(value = "checkNumber", required = false) Integer checkNumber,
        HttpServletResponse theResponse) throws IOException {
    Motransaction aMotransaction = new Motransaction();

    PrintService[] printServices = PrinterJob.lookupPrintServices();
    StringBuilder sbr = new StringBuilder();
    String sep = "";
    for (PrintService printService : printServices) {
        sbr.append(sep);/*ww  w . jav  a2  s .  co  m*/
        sbr.append(printService.getName());
        sep = ",";
    }
    return sbr.toString();
}

From source file:org.efaps.tests.Printer.java

static PrintService getPrintService4Name(final String _name) {
    PrintService ret = null;/*from  w w w  .j a  va2  s  . co m*/
    final PrintService[] pservices = PrintServiceLookup.lookupPrintServices(null, null);
    if (!ArrayUtils.isEmpty(pservices)) {
        for (final PrintService serv : pservices) {
            if (serv.getName().equals(_name)) {
                ret = serv;
                break;
            }
        }
    }
    return ret;
}

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
            }/*from w  w w.  j  a  va2 s.  c om*/

            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.pentaho.platform.plugin.action.builtin.PrintComponent.java

/**
 * Takes a printer name and find the associated PrintService. If no match can be made it randomly picks the first
 * printer listed from the call to lookupPrintServices.
 * /*from  w ww  .  j  av  a 2 s.  c o  m*/
 * @param printerName
 * @return PrintService referenced by the printerName
 */
public PrintService getPrinterInternal(final String printerName, final String lastPrinterName) {
    // The parameter value was not provided, and we are allowed to create
    // user interface forms

    PrintService[] services = PrinterJob.lookupPrintServices();
    for (PrintService element : services) {
        if (element.getName().equals(printerName)) {
            return element;
        }
    }
    if (feedbackAllowed()) {
        // If it's not valid then lets find one and end this current run.
        ArrayList values = new ArrayList();
        for (PrintService element : services) {
            String value = element.getName();
            values.add(value);
        }
        createFeedbackParameter(StandardSettings.PRINTER_NAME,
                Messages.getInstance().getString("PrintComponent.USER_PRINTER_NAME"), "", lastPrinterName, //$NON-NLS-1$//$NON-NLS-2$
                values, null, "select"); //$NON-NLS-1$
        promptNeeded();
        return null;
    }
    return services[0];
}

From source file:org.pentaho.platform.plugin.action.builtin.PrintComponent.java

/**
 * Takes a printer name and find the associated PrintService. If no match can be made it randomly picks the first
 * printer listed from the call to lookupPrintServices.
 * /*from   w ww  .ja  v  a 2s .c o  m*/
 * @param printerName
 * @return PrintService referenced by the printerName
 */
public static PrintService getPrinter(final String printerName) {
    // The parameter value was not provided, and we are allowed to create
    // user interface forms

    PrintService[] services = PrinterJob.lookupPrintServices();
    for (PrintService element : services) {
        if (element.getName().equals(printerName)) {
            return element;
        }
    }
    return services[0];
}

From source file:org.pentaho.platform.plugin.action.jfreereport.JFreeReportComponent.java

public boolean print(final MasterReport report, final String jobName, final String printerName) {
    boolean result = false;
    if (jobName != null) {
        report.getReportConfiguration().setConfigProperty(PrintUtil.PRINTER_JOB_NAME_KEY,
                String.valueOf(jobName));
    }//w w w .  j  av a 2  s.  c  om

    PrintService printer = null;
    PrintService[] services = PrintServiceLookup.lookupPrintServices(DocFlavor.SERVICE_FORMATTED.PAGEABLE,
            null);
    for (final PrintService service : services) {
        if (service.getName().equals(printerName)) {
            printer = service;
        }
    }
    if ((printer == null) && (services.length > 0)) {
        printer = services[0];
    }

    try {
        Java14PrintUtil.printDirectly(report, printer);
        result = true;
    } catch (PrintException e) {
        //ignore
    } catch (ReportProcessingException e) {
        //ignore
    }
    return result;
}

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/*from   w  w  w.j  a va2  s .c o  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//  w  ww. j  a  va2 s.c  o 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 {//from   www  .j a  v a2 s .  c  o  m
        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;
}