I am developing an integrated Android application with a web service TomCat and laboratory (Eclipse Java EE) she arrived at a satisfactory level, performing queries, impressions on the default printer, all quiet, but as I get the service for Tomcat he does not perform printing it is as if there is no printer connected to the server.
The code below is used to perform printing when I am providing the service directly from Eclipse.
try{
InputStream prin = new ByteArrayInputStream(textoimp.getBytes());
INPUT_STREAM docFlavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
SimpleDoc documentoTexto = new SimpleDoc(prin, docFlavor, null);
PrintService impressora = PrintServiceLookup.lookupDefaultPrintService(); // pega a impressora padrao
PrintRequestAttributeSet printerAttributes = new HashPrintRequestAttributeSet();
printerAttributes.add(new JobName("Impressao", null));
printerAttributes.add(OrientationRequested.PORTRAIT);
printerAttributes.add(MediaSizeName.ISO_A4); // informa o tipo de folha
DocPrintJob printJob = ((PrintService) impressora).createPrintJob(); //the error occurs here , the printer is null
try{
printJob.print(documentoTexto, (PrintRequestAttributeSet)printerAttributes);//try to print
}
catch(PrintException e){
e.printStackTrace();
JOptionPane.showMessageDialog(null, "Não foi possível realizar a impressão !!", "Erro", JOptionPane.ERROR_MESSAGE);
}
prin.close();
}
catch(Exception e){
e.printStackTrace();
return false;
}
But when the service is running within the Tomcat it does not work, can anyone help me?
答案 0 :(得分:0)
Arjan回答说,Tijms,我已经回答了一个问题而我没有看到,我感谢这位朋友。 在答案的链接下面: