使用IPP(Internet打印协议)或LPR(线打印机遥控器)在Android中打印文件



我的要求是在不使用任何基于云的服务的情况下从Android设备打印文件。

我已经能够使用" RAW"打印协议即可在port 9100 的IP地址中实现它。这是代码段:

 client = new Socket(ip,port); //Port is 9100
 byte[] mybytearray = new byte[(int) file.length()]; //create a byte array to file
 fileInputStream = new FileInputStream(file);
 bufferedInputStream = new BufferedInputStream(fileInputStream);
 bufferedInputStream.read(mybytearray, 0, mybytearray.length); //read the file
 outputStream = client.getOutputStream();
 outputStream.write(mybytearray, 0, mybytearray.length); //write file to the output stream byte by byte
 outputStream.flush();
 bufferedInputStream.close();
 outputStream.close();

" RAW"打印协议的问题是无法从打印机中获得状态。

所以,我最近阅读了有关 ipp ldr 的使用,我们可以从打印机中获得状态。

我试图找到一种使用Android实施它们的方法,但没有成功。我已经经历了这个答案,但在找到我的解决方案方面没有成功。

如果有人可以指导我如何在Android中实施IPP或LDR。

预先感谢!

ipp的一般用法:

  1. 一旦提交了打印作业,打印机返回工作ID
  2. 使用Get-Job-Attributes-合作以获取当前的工作状态
  3. 等到属性工作状态等于9(含义为"已完成")

您应该检查其他最终工作状态:中止或取消

用于原型制作,您可以使用IPPTool(用于桌面使用的本地):

# ipptool -t -d job=482 ipp://192.168.2.113/ipp job.ipp
{
OPERATION Get-Job-Attributes
GROUP operation-attributes-tag
  ATTR charset attributes-charset utf-8
  ATTR language attributes-natural-language en
  ATTR uri printer-uri $uri
  ATTR integer job-id $job
}

更新5/2020

我发布了IPP协议的Kotlin实现。

https://github.com/gmuth/ipp-client-kotlin

提交后,您可以等待打印作业终止:job.waitForTermination()

最新更新