Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use IPP(Internet Printing Protocol) or LPR(Line printer Remote) to print file in android

My requirement is to print a file from an android device without using any cloud based service.

I have been able to achieve it using "Raw" print protocol i.e by simply sending the file to printer's IP address at Port 9100. Here is the code snippet for that:

 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();

The problem with "Raw" printing protocol is that there is no way to get the status back from the printer.

So, I recently read about IPP and LDR using which we can get the status back from printer.

I have tried to find a way to implement them using android but had no success. I have already went through this answer but had no success in finding my solution.

It will be really helpful if someone can guide me on how to implement IPP or LDR in android.

Thanks in advance!

like image 411
Exception Avatar asked May 08 '15 04:05

Exception


People also ask

How do I enable IPP printing?

In the administrator mode, select [Network] - [IPP Setting], then configure the following settings. Select [ON] to use the IPP printing function. [ON] is specified by default. Select [ON] to use the IPP printing function.

What is LPR setting on printer?

The Line Printer Daemon protocol/Line Printer Remote protocol (or LPD, LPR) is a network printing protocol for submitting print jobs to a remote printer. The original implementation of LPD was in the Berkeley printing system in the BSD UNIX operating system; the LPRng project also supports that protocol.

What is IPP print settings?

IPP printing uses the Internet Printing Protocol (IPP) and prints information via the network. IPP that is extended HTTP is used to forward printing data, enabling you to print data on a printer on a distance location via the Internet.


1 Answers

General usage of IPP:

  1. Once a print job has been submitted the printer returns a job-id
  2. Use the Get-Job-Attributes-Operation in order to get the current job-state
  3. Wait until the attribute job-state equals to 9 (means 'completed')

There are other final job-states you should check for: aborted or canceled

For prototyping you could use the ipptool (native for desktop usage):

# 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
}

Update 5/2020

I have published a kotlin implementation of the ipp protocol.

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

Once submitted you can wait for the print job to terminate: job.waitForTermination()

like image 113
IPP Nerd Avatar answered Oct 05 '22 07:10

IPP Nerd