Package javax.print

Examples of javax.print.PrintService


            reportfields.put("TICKET", ticket);
            reportfields.put("PLACE", ticketext);

            JasperPrint jp = JasperFillManager.fillReport(jr, reportparams, new JRMapArrayDataSource(new Object[] { reportfields } ));
           
            PrintService service = ReportUtils.getPrintService(m_App.getProperties().getProperty("machine.printername"));
           
            JRPrinterAWT300.printPages(jp, 0, jp.getPages().size() - 1, service);
           
        } catch (Exception e) {
            MessageInf msg = new MessageInf(MessageInf.SGN_WARNING, AppLocal.getIntString("message.cannotloadreport"), e);
View Full Code Here


    @Override
    public void endReceipt() {

        try {

            PrintService ps;

            if (printservice == null) {
                String[] printers = ReportUtils.getPrintNames();
                if (printers.length == 0) {
                    logger.warning(AppLocal.getIntString("message.noprinters"));
                    ps = null;
                } else {
                    SelectPrinter selectprinter = SelectPrinter.getSelectPrinter(parent, printers);
                    selectprinter.setVisible(true);
                    if (selectprinter.isOK()) {
                        ps = ReportUtils.getPrintService(selectprinter.getPrintService());
                    } else {
                        ps = null;
                    }
                }
            } else {
                ps = printservice;
            }

            if (ps != null)  {

                PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
                aset.add(OrientationRequested.PORTRAIT);
                aset.add(new JobName(AppLocal.APP_NAME + " - Document", null));
                aset.add(media);

                DocPrintJob printjob = ps.createPrintJob();
                Doc doc = new SimpleDoc(new PrintableBasicTicket(m_ticketcurrent, imageable_x, imageable_y, imageable_width, imageable_height), DocFlavor.SERVICE_FORMATTED.PRINTABLE, null);

                printjob.print(doc, aset);
            }
View Full Code Here

            // restore any the printer attributes from a previous session, if needed
            _restorePrinterAttr();

            if (_printerJob.printDialog(_printerAttr)) {
                // remember the printer name
                PrintService ps = _printerJob.getPrintService();
                if (ps == null)
                    return;
                Preferences.set(prefKey, ps.getName());

                // save the printer attributes for future sessions
                _savePrinterAttr();

                // print the table
View Full Code Here

                    Debug.logWarning(ue, "Invalid URI for printer [" + printerName + "]", module);
                }
            }
            //PrintService[] services = PrintServiceLookup.lookupPrintServices(psInFormat, psaset); // TODO: selecting the printer by URI seems to not work
            PrintService[] services = PrintServiceLookup.lookupPrintServices(psInFormat, null);
            PrintService printer = null;
            if (services.length > 0) {
                if (UtilValidate.isNotEmpty(printerName)) {
                    String sPrinterName = null;
                    for (int i = 0; i < services.length; i++) {
                        PrintServiceAttribute attr = services[i].getAttribute(PrinterName.class);
                        sPrinterName = ((PrinterName)attr).getValue();
                        if (sPrinterName.toLowerCase().indexOf(printerName.toLowerCase()) >= 0) {
                            printer = services[i];
                            Debug.logInfo("Printer with name [" + sPrinterName +"] selected", module);
                            break;
                        }
                    }
                }
                if (UtilValidate.isEmpty(printer)) {
                    printer = services[0];
                }
            }
            if (UtilValidate.isNotEmpty(printer)) {
                PrintRequestAttributeSet praset = new HashPrintRequestAttributeSet();
                praset.add(new Copies(1));
                DocPrintJob job = printer.createPrintJob();
                job.print(myDoc, praset);
            } else {
                String errMsg = "No printer found with name: " + printerName;
                Debug.logError(errMsg, module);
                return ServiceUtil.returnError(errMsg);
View Full Code Here

    boolean result = false;
    if ( jobName != null ) {
      report.getReportConfiguration().setConfigProperty( PrintUtil.PRINTER_JOB_NAME_KEY, String.valueOf( jobName ) );
    }

    PrintService printer = null;
    PrintService[] services = PrintServiceLookup.lookupPrintServices( DocFlavor.SERVICE_FORMATTED.PAGEABLE, null );
    for ( final PrintService service : services ) {
      if ( service.getName().equals( printerName ) ) {
        printer = service;
      }
View Full Code Here

    private DocPrintJob assignPrintJob(PrintService printService) {
        return printService.createPrintJob();
    }
   
    private PrintService assignPrintService() throws PrintException {
        PrintService printService;
       
        if ((config.getHostname().equalsIgnoreCase("localhost"))
            && (config.getPrintername().equalsIgnoreCase("/default"))) {
            printService = PrintServiceLookup.lookupDefaultPrintService();           
        } else {
View Full Code Here

                        if (debugPrinterChange)
                            System.out.println("Thread invoked.");
                        PrintService[] ps = PrintServiceLookup.lookupPrintServices(null,null);
                        if (debugPrinterChange)
                            System.out.println("Found print services.");
                        PrintService p=null;
                        for (PrintService p1 : ps) {
                            if (debugPrinterChange)
                                System.out.println("checking " + p1.getName());
                            if (p1.getName().equals(printerName.getSelectedItem())) {
                                p = p1;
                                if (debugPrinterChange)
                                    System.out.println("Match!");
                            }
                        }

                        if (p!=null) {
                            if (debugPrinterChange)
                                System.out.println("Getting available resolutions...");
                            resolution.setModel(new javax.swing.DefaultComboBoxModel(getAvailableResolutions(p)));
                            if (debugPrinterChange)
                                System.out.println("Getting default resolution...");
                            int resInd = getDefaultResolutionIndex();
                            if (resolution.getModel().getSize() > resInd)
                                resolution.setSelectedIndex(resInd);
                            resolution.setEnabled(true);
                            paperDefinitions.setPrintService(p);
                            if (debugPrinterChange)
                                System.out.println("Getting available paper sizes...");
                            pageSize.setModel(new javax.swing.DefaultComboBoxModel(getAvailablePaperSizes()));
                            if (debugPrinterChange)
                                System.out.println("Getting default pagesize...");
                            int pageInd = paperDefinitions.getDefaultPageIndex();
                            if (pageSize.getModel().getSize() > pageInd)
                                pageSize.setSelectedIndex(pageInd);
                            pageSize.setEnabled(true);
                            okButton.setEnabled(true);
                            if (debugPrinterChange)
                                System.out.println("Reenabled GUI");
                        }

                        if (debugPrinterChange)
                            System.out.println("Updating margins");
                        updateMargins();

                    }
                };
                if (debugPrinterChange)
                    System.out.println("Invoking update thread...");
                SwingUtilities.invokeLater(t);
            }
        });
        Thread t = new Thread() {

      public void run() {
                PrintService[] ps = PrintServiceLookup.lookupPrintServices(null,null);
                PrintService p=null;
                for (PrintService p1 : ps) {
                    if (p1.getName().equals(printerName.getSelectedItem()))
                        p = p1;
                }
View Full Code Here

        return names;
    }

    public PrinterResolution getResolution() {
        PrintService[] ps = PrintServiceLookup.lookupPrintServices(null,null);
        PrintService p=null;
        for (PrintService p1 : ps) {
            if (p1.getName().equals(printerName.getSelectedItem()))
                p = p1;
        }

        PrinterResolution[] resolutions = ((PrinterResolution[])p.getSupportedAttributeValues(PrinterResolution.class, DocFlavor.SERVICE_FORMATTED.PAGEABLE, null));

        if (resolutions == null)
            return null;

        return resolutions[resolution.getSelectedIndex()];
View Full Code Here

    }

    private int getDefaultResolutionIndex() {
        //get print service
        PrintService[] ps = PrintServiceLookup.lookupPrintServices(null,null);
        PrintService p=null;
        for (PrintService p1 : ps) {
            if (p1.getName().equals(printerName.getSelectedItem()))
                p = p1;
        }

        //get available resolutions
        PrinterResolution[] resolutions = (PrinterResolution[])p.getSupportedAttributeValues(PrinterResolution.class, DocFlavor.SERVICE_FORMATTED.PAGEABLE, null);

        if (resolutions == null)
            return 0;

        if (defaultResolution == -1)
View Full Code Here

  public static String getDefaultPrinterQueueName()
  {
    final Logger logger = Logger.getLogger(JPrint.class);
    String queuename = new String();
    PrintService printService = getDefaultPrinterService();

    if (printService != null)
    {
      queuename = getPrinterNamebyService(printService);
    }
View Full Code Here

TOP

Related Classes of javax.print.PrintService

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.