gpt4 book ai didi

java - 通过tomcat在默认打印机上打印

转载 作者:行者123 更新时间:2023-11-28 23:30:21 24 4
gpt4 key购买 nike

我正在开发一个集成了 Android 应用程序的 web 服务 TomCat 和实验室(Eclipse Java EE)她达到了令人满意的水平,在默认打印机上执行查询,印象,一切都很安静,但当我获得 Tomcat 服务时,他不执行打印就好像没有打印机连接到服务器。

当我直接从 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;

}

但是当该服务在 Tomcat 中运行时它不起作用,谁能帮助我?

最佳答案

Arjan 回答说 Tijms,有一个关于 SO 的问题回答了,我没有看到,我感谢这位 friend 。在答案的链接下方:

Printing is not working in tomcat, when i start server with services.msc(From client side we could not print )

关于java - 通过tomcat在默认打印机上打印,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31140107/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com