Impressao via USB

0 respostas
V
Boa tarde galera... Meu problema é o seguinte. Nao consigo imprimir arquivos .txt atravez do servico de impressao do java em impressoras deskjet conectadas via USB. Vai aqui meu codigo de exemplo que nao funciona.:
import javax.print.*;
import javax.print.attribute.*;
import java.io.*;
 
public class Printing {
  public static void main(String args[]) throws Exception {
    String filename = ("meuarquivo.txt"); 
    PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
    DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;    
    PrintService printService[] = PrintServiceLookup.lookupPrintServices(flavor, pras);
    PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();
    PrintService service = ServiceUI.printDialog(null, 200, 200,
      printService, defaultService, flavor, pras);
    if (service != null) {
      DocPrintJob job = service.createPrintJob();
      FileInputStream fis = new FileInputStream(filename);
      DocAttributeSet das = new HashDocAttributeSet();
      Doc doc = new SimpleDoc(fis, flavor, das);
      job.print(doc, pras);
      Thread.sleep(5000);
    }
    System.exit(0);
  }
}
Maaaaaaaaaas... eu fiz testes utilizando o exporter do jasperreports e ele imprime o .PDF normalmente.
PrinterJob job = PrinterJob.getPrinterJob();
 job.setPrintService(services[k]); 
                                               
 PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet(); 
 PrintServiceAttributeSet printServiceAttributeSet = new HashPrintServiceAttributeSet(); 
 printServiceAttributeSet.add(new PrinterName(services[k].getName(), null));      
                       
 //JRPrintServiceExporter exporter = new JRPrintServiceExporter(); 
 JRExporter exporter = new JRPrintServiceExporter(); 

 printRequestAttributeSet.add(new Copies(1)); 

exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE,services[k]);
                       exporter.setParameter(JRPrintServiceExporterParameter.INPUT_FILE_NAME,nomeArquivoPDF); 
                       exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE_ATTRIBUTE_SET, services[k].getAttributes());
                       exporter.setParameter(JRPrintServiceExporterParameter.PRINT_REQUEST_ATTRIBUTE_SET, printRequestAttributeSet); 
                       //exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE_ATTRIBUTE_SET, printServiceAttributeSet); 
                       exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PAGE_DIALOG, Boolean.FALSE);
                       exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG, Boolean.FALSE);
                        
 exporter.exportReport();

Alguem ai saberia me dizer o porque eu consigo imprimir um PDF com o exporter do jasperrports e nao consigo imprimir um simples arquivo.txt nessa impressora.????
DESDE JA AGRADECO A AJUDA.. QUALQUER DICA É BEM VINDA...

Criado 16 de julho de 2007
Respostas 0
Participantes 1