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);
}
}
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...