Imprimir un documento txt o pdf

baduela
13 de Agosto del 2005
Hola intento imprimir un fichero txt o pdf directamente a la impresora, pero me da el error invalid flavor, si imprimo un fichero gif me funciona, he probado con todos los tipos de flavor pero nada, Aqui os pongo el fuente para ver si me podeis decir lo que tengo mal.

// Input the file
FileInputStream textstream;
try {
textstream = new FileInputStream("c:\fichero.pdf");
// Set the document type
DocFlavor myFormat = DocFlavor.INPUT_STREAM.POSTSCRIPT;
// Create a Doc
Doc myDoc = new SimpleDoc(textstream, myFormat, null);
// Build a set of attributes
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
// discover the printers that can print the format according to the
// instructions in the attribute set
PrintService service = PrintServiceLookup.lookupDefaultPrintService();


// Create a print job from one of the print services
// System.out.println("error 3"+services.length);
if (service!=null) {
DocPrintJob job = service.createPrintJob();
try {
job.print(myDoc, aset);
} catch (PrintException pe) {

System.out.println("error 5"+pe.getLocalizedMessage());
}
}

} catch (FileNotFoundException ffne) {
}