Package javax.print

Examples of javax.print.DocPrintJob


        public void printJobNoMoreEvents(PrintJobEvent arg0) {
        }

        public void printJobRequiresAttention(PrintJobEvent event) {
            DocPrintJob printJob = event.getPrintJob();
            String printerName = printJob.getPrintService().getName();
            System.out.println("[PrintManager] print job requires attention on: " + printerName);
        }
View Full Code Here


        // exibe um dialogo de configuracoes de impressao
        PrintService service =  ServiceUI.printDialog(null, 320, 240,
              printerServices, printer, docFlavor, printerAttributes);

        if (service != null) {
          DocPrintJob printJob = service.createPrintJob();
          printJob.print(textDocument, printerAttributes);
        }     
      } else {
       
        // Cria um job de impress�o
        DocPrintJob printJob = printer.createPrintJob();
       
        // Adiciona uma propriedade de impress�o: imprimir 2 c�pias
        printerAttributes.add(new Copies(2));
       
        // Imprime o documento sem exibir uma tela de dialogo
        printJob.print(textDocument, printerAttributes);
      }   
     
    } catch (FileNotFoundException ex) {
      System.out.println("Arquivo teste.txt n�o encontrado!");
    } catch (PrintException ex2) {
View Full Code Here

                }
            }
            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

        //aset.add(MediaSize.A4);
        aset.add(Sides.ONE_SIDED);
       
        PrintService[] services = PrintServiceLookup.lookupPrintServices(docFlavor, aset);
        if (services.length > 0) {
          DocPrintJob job = services[0].createPrintJob();
            try {
              job.print(myDoc, aset);
            } catch (PrintException pe) {
                String errMsg = "Unable to print PDF from XSL-FO: " + pe.toString();
                Debug.logError(pe, errMsg, module);
                return ServiceUtil.returnError(errMsg);
            }
View Full Code Here

     */
    public void printFO(File fo)
            throws IOException, FOPException, TransformerException, PrintException {

        //Set up DocPrintJob instance
        DocPrintJob printJob = createDocPrintJob();

        //Set up a custom user agent so we can supply our own renderer instance
        FOUserAgent userAgent = fopFactory.newFOUserAgent();

        PageableRenderer renderer = new PageableRenderer(userAgent);
        userAgent.setRendererOverride(renderer);

        // Construct FOP with desired output format
        Fop fop = fopFactory.newFop(userAgent);

        // Setup JAXP using identity transformer
        TransformerFactory factory = TransformerFactory.newInstance();
        Transformer transformer = factory.newTransformer(); // identity transformer

        // Setup input stream
        Source src = new StreamSource(fo);

        // Resulting SAX events (the generated FO) must be piped through to FOP
        Result res = new SAXResult(fop.getDefaultHandler());

        // Start XSLT transformation and FOP processing
        transformer.transform(src, res);

        Doc doc = new SimpleDoc(renderer, DocFlavor.SERVICE_FORMATTED.PAGEABLE, null);
        printJob.print(doc, null);
    }
View Full Code Here

                }
               
                final Component printIt = new PrintPrintable.MyComponent();
                DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
                PrintService printService = PrintServiceLookup.lookupDefaultPrintService();
                DocPrintJob job = printService.createPrintJob();
                PrintJobListener pjlistener = new PrintJobAdapter() {
                    public void printDataTransferCompleted(PrintJobEvent e) {
                        System.out.println("Good Bye");                       
                    }
                };
                job.addPrintJobListener(pjlistener);
                PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();

                DocAttributeSet das = new HashDocAttributeSet();
                Doc doc = new SimpleDoc(printIt, flavor, das);
                try {  
                        job.print(doc, pras);
                    } catch (PrintException pe) {
                        pe.printStackTrace();
                    }
            dispose();
        }
View Full Code Here

                }                          
           
                final Component printIt = new PrintPrintable.MyComponent();
                DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
                PrintService printService = PrintServiceLookup.lookupDefaultPrintService();
                DocPrintJob job = printService.createPrintJob();
                PrintJobListener pjlistener = new PrintJobAdapter() {
                    public void printDataTransferCompleted(PrintJobEvent e) {
                        System.out.println("Good Bye");
                       
                    }
                };
                job.addPrintJobListener(pjlistener);
                PrintRequestAttributeSet pras =
                new HashPrintRequestAttributeSet();

                DocAttributeSet das = new HashDocAttributeSet();
                Doc doc = new SimpleDoc(printIt, flavor, das);
                try {  
                        job.print(doc, pras);
                    } catch (PrintException pe) {
                        pe.printStackTrace();
                    }       
            dispose();
        }else{
View Full Code Here

//Tipo: bytes; Subtipo: autodetectado
        DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;

        Doc doc = new SimpleDoc(bytes, flavor, null);
//Creamos un trabajo de impresión
        DocPrintJob job = null;
        if (services.length > 0) {
            for (int i = 0; i < services.length; i++) {
               
                if (services[i].getName().equals("cocina")) {//aqui escribimos/elegimos la impresora por la que queremos imprimir
                    //manejar error en caso de que no esté conectada
View Full Code Here

//Tipo: bytes; Subtipo: autodetectado
        DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;

        Doc doc = new SimpleDoc(bytes, flavor, null);
//Creamos un trabajo de impresión
        DocPrintJob job = null;
        if (services.length > 0) {
//            for (int i = 0; i < services.length; i++) {
//                if (services[i].getName().equals("caja")) {//aqui escribimos/elegimos la impresora por la que queremos imprimir
//                    job = services[i].createPrintJob();// System.out.println(i+": "+services[i].getName());
//                }
//            }
            for (PrintService service : services) {
                if (service.getName().equals("caja")) {
                    //aqui escribimos/elegimos la impresora por la que queremos imprimir
                    job = service.createPrintJob(); // System.out.println(i+": "+services[i].getName());
                }
            }
        }

//Imprimimos dentro de un try obligatoriamente
        try {
            job.print(doc, null);
        } catch (PrintException ex) {
            System.out.println(ex);
        }

    }
View Full Code Here

//lo maneja la impresora(mas bien ticketera :p)
        byte[] bytes = contentTicket.getBytes(); //Especificamos el tipo de dato a imprimir
//Tipo: bytes; Subtipo: autodetectado
        DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
        Doc doc = new SimpleDoc(bytes, flavor, null); //Creamos un trabajo de impresión
        DocPrintJob job = null;
        if (services.length > 0) {
            for (int i = 0; i < services.length; i++) {
                if (services[i].getName().equals("GP-5890X Series")) {
//aqui escribimos/elegimos la impresora por la que queremos imprimir
                    job = services[i].createPrintJob();
                    System.out.println(i + ": " + services[i].getName());
                }
            }
        }
//Imprimimos dentro de un try obligatoriamente
        try {
            job.print(doc, null);
        } catch (PrintException ex) {
            System.out.println(ex);
        }
    }
View Full Code Here

TOP

Related Classes of javax.print.DocPrintJob

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.