Impressão em Java

0 respostas
torres17

Olá Pessoal.

Estou tentando realizar uma impressão através de uma applet Java, consigo enviar para a impressora o texto para impressão, só que não estou conseguindo fazer a impressora ejetar a fita.

Basicamente estou usando o seguinte código:

public static void imprime(String toPrint, String printerName) throws PrintException {   
       PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();   
       aset.add(OrientationRequested.PORTRAIT);   
       aset.add(new JobName("Impressao", null));   
  
       PrintService printer = null;   
       for (PrintService p : PrinterJob.lookupPrintServices()) {   
           if (p.getName().equalsIgnoreCase(printerName)) {   
               printer = p;   
               break;   
           }   
       }   
  
       DocPrintJob docPrint = printer.createPrintJob();   
       InputStream stream = new ByteArrayInputStream(toPrint.getBytes());   
       DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;   
       Doc doc = new SimpleDoc(stream, flavor, null);   
       docPrint.print(doc, aset);   
   }

Se puderem me ajudar ficaria muito grato.

Criado 11 de outubro de 2009
Respostas 0
Participantes 1