King HomeTech – iPhone Division 
Support for all your computer needs!

Printing to a networked Printer from your iPhone!

Eric J King
ejking89@yahoo.com

 

 

 

 

 

In the Terminal:                                                                                      Get the printable (.doc) version of this

PRINT=Path_to_File_to_Print

cat $PRINT | /var/root/bin/a.out | nc -w 1 Printer_IP PORT

 

OR

 

cat Path_to_File_to_Print | /var/root/bin/a.out | nc -w 1 Printer_IP PORT

 

 

****************************************************************************************

Example: (This prints to my Networked HP Officejet 7410 at 192.168.1.105 at the default port of 9100)

PRINT=/var/root/PrintMe.txt

cat $PRINT | /var/root/bin/a.out | nc -w 1 192.168.1.105 9100

 

OR

 

cat /var/root/PrintMe.txt | /var/root/bin/a.out | nc -w 1 192.168.1.105 9100

 

 

****************************************************************************************

Explanation:

cat $PRINT                           Outputs the file in $PRINT to the Pipe

/var/root/bin/a.out                 A compiled version of lponlcr.c ("c++ lponlcr.c" in the toolchain)

                                                The following is the source code for lponlcr.c (from http://aplawrence.com/Bofcusm/1810.html)

                                                                  #include <stdio.h>

                                                                  main()

                                                                  {                            

                                                                          register int c;

                                                                          while ((c=getchar()) != EOF) {

                                                                                  if (c == '\n')

                                                                                          putchar('\r');

                                                                                  putchar(c);

                                                                          }

                                                                  }

 

nc –w 1 Printer_IP PORT     NetCat Utility:

                                                            -w 1                 Ends the connection to printer after sending data (1 second after end of data)

                                                            Printer_IP      IP Address of the Networked Printer

                                                            PORT             Port Number by which the printer accepts RAW Printing

 

 

 

 

****************************************************************************************

Links:

 

lponlcr.c          -           Adds a carriage return for every line feed in a file – Without this, it will print in “stair-steps”

                                                Without lponlcr                                                                                  With lponlcr

                                                This is line 1 of the document                                                           This is line 1 of the document

                                                                                                This is line 2 of the document           This is line 2 of the document

                                                                                                                                                                This is line 3 of the document

 

a.out                -           Simply lponlcr.c already compiled for the iphone – in this tutorial, I put it in /var/root/bin on my iPhone