我正试着用我的android手机作为打印机。我正在使用ServerSocket接收要打印的文档。如果我通过提供IP地址和端口并选择泛型Postscript打印机将我的手机添加为IP打印机,我就能够正确地接收ps格式的文件。我不想把我的手机作为打印机作为IP打印机。所以现在我使用NsdManager将我的设备注册为打印机。它被自动识别为Bonjour打印机,我可以成功地添加为打印机。但是现在每次我通过计算机打印文档时,我都会在套接字的输入流中得到这些数据。
POST / HTTP/1.1 Content-Length: 673 Content-Type: application/ipp Host:
Android-2.local:9200 User-Agent: CUPS/2.1.0 (Darwin 15.2.0; x86_64)
IPP/2.0 Expect: 100-continue Gattributes-charsetutf-8Hattributes-
natural-languageen-usEprinter-uriipp://Android-
2.local.:9200/Drequested-attributescompression-supportedDcopies-
supportedDcups-versionDdocument-format-supportedD marker-colorsDmarker-
high-levelsD marker-levelsDmarker-low-levelsDmarker-messageDmarker-
namesDmarker-typesDmedia-col-supportedD$multiple-document-handling-
supportedDoperations-supportedDprint-color-mode-supportedD printer-
alertDprinter-alert-descriptionDprinter-is-accepting-jobsD printer-
mandatory-job-attributesD printer-stateDprinter-state-messageDprinter-
state-reasons
我阅读了IPP文档,并且我发送了100个继续在响应中,以及所有需要的params,如下所示
clientSocket.setTcpNoDelay(true);
BufferedOutputStream out = new BufferedOutputStream(clientSocket.getOutputStream());
out.write("HTTP/1.1 100\r\n".getBytes("UTF-8"));
out.write("\r\n".getBytes("UTF-8"));
out.write("compression-supported: \"none\"\r\n".getBytes("UTF-8"));
out.write("printer-is-accepting-jobs: \"true\"\r\n".getBytes("UTF-8"));
.....
....
out.flush();
之后,如果我试图读取文档的输入流,它会给出null,在我的计算机上,我会收到“打印:连接到打印机”的消息,但是如果要关闭套接字的输出流,就会在我的计算机上得到“无法获得打印机状态”的消息。请帮帮我。是否有任何方式,我只是收到文件,而不是这个帖子的要求或方式发送一个正确的回应,并得到文件?我已经坚持了很长时间了。任何帮助都是非常感谢的。
发布于 2016-06-16 06:19:37
我终于能够实现它了。下面是使用Node.js的网络打印机的一个极好的实现。它解释了IPP https://github.com/watson/ipp-printer的细节。
另外,这个视频也是很好的演示https://www.youtube.com/watch?v=58Ti8w1yX2w。
我正在使用https://github.com/NanoHttpd/nanohttpd处理我的安卓手机上的打印请求。
发布于 2016-06-07 17:29:57
您的计算机/CUPS(我猜是带有El Capitain的Mac)正在尝试通过IPP打印,但是您的手机打印设备没有实现IPP。很明显,这行不通。
解决方案1:
用正确的设置在杯子中添加打印机。对于网络打印机,CUPS提供:
选择取决于您已经实现或计划在应用程序中支持的procotol。IPP不是你的选择除了..。
解决方案2:
在您的“Print App”中实现IPP。那会很艰难的!
有很多事情要实施..。请参阅https://www.pwg.org/ipp/
解决方案3:
通过Bonjour印刷1.2正确地宣布您的服务
_pdl-datastream._tcp
应该是正确的服务类型。(另见第7.6章,旗舰命名)
https://stackoverflow.com/questions/37673894
复制相似问题