1
While running, the error below is displayed when sending a string
printer-friendly.
sun.print.PrintJobFlavorException: invalid flavor
at sun.print.Win32PrintJob.print(Unknown Source)
Complete code
PrintService[] printServices = PrintServiceLookup.lookupPrintServices(DocFlavor.SERVICE_FORMATTED.PRINTABLE, null);
PrintService printService = printServices[5];
System.out.println(printService.getName());
DocFlavor docFlavor = DocFlavor.STRING.TEXT_PLAIN;
StringBuilder value = new StringBuilder();
value.append("\n\n");
value.append("\n\tRelação dos Usuários:");
List<Usuario> usuarios = TapiocariaFacade.listarUsuario();
int y = 70;
for(Usuario usuario : usuarios) {
value.append("\n\tNome: " + usuario.getSenha());
value.append("\n\tEndereço: " + usuario.getId());
value.append("\n\tEmail: " + usuario.getEmail());
}
System.out.println(value.toString());
Doc doc = new SimpleDoc(value.toString(), docFlavor, null);
DocPrintJob docPrintJob = printService.createPrintJob();
try {
docPrintJob.print(doc, null);
} catch (PrintException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Welcome to Stack Overflow! Even if this link is a good suggestion, this reply will not be valid if one day the link ceases to work. So, because it’s important for the community to have content right here, you’d better respond with more complete answers. Can you elaborate more your answer? A summary of the content of the link would help a lot! Learn more on this item in our Community FAQ: Answers that only contain links are good?
– Jorge B.
Ismael good morning, thanks for answering but come on, first the printer at position 5 it exists because by the sysout appears your name, I will change the Flavor to see. Later I put the result.
– EA.Jsp.Android
Ismael, it worked out like this:
DocFlavor docFlavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
and creating a text file:FileInputStream fis = new FileInputStream("D:/fff.txt");
Only that in my case I didn’t always want to create a txt but to pass a direct string, some idea?– EA.Jsp.Android