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. The Common Unix Printing System (or CUPS), which is more common on modern Linux distributions and also found on Mac OS X, supports LPD as well as the Internet Printing Protocol (IPP). Commercial solutions are available that also use Berkeley printing protocol components, where more robust functionality and performance is necessary than is available from LPR/LPD (or CUPS) alone (such as might be required in large corporate environments).
You can also use Ax.net.CUPS
as a more modern protocol.
1 Create a LPR client
You can create an LPRClient by simply poiting to the IP address of lpd daemon. Then ask for the queue status.
var lpr = new Ax.net.LPRClient("192.168.100.21"); console.log(lpr.getQueueState());
Printer Status: Online
Notice we have not specified a queue as many lpd daemons have a single queue.
By default a queue name "default" will be used. If need it can be changed by using
setQueue(String name)
on lpr client.
We also have not specified a user name casue most lpd daemons don't require it.
By default, lpr client will use "anonymous". If needed, it can be changed by using
setUser(String user)
on lpr client.
2 Send a text (job) to printer
To send a text to printer simply get que queue and send it using print. Priter will respond with a job identifier (the number of job in the printer queue).
var lpr = new Ax.net.LPRClient("192.168.100.21"); var job = lpr.print("Hello World\nBye."); console.log(job);
881
3 Remove a job from printer
In the case the printer holds a job in the queue for printing, you can send a cancel request using it's job id. Command will return a boolean according if job has been cancelled.
var lpr = new Ax.net.LPRClient("192.168.100.21"); var job = lpr.print("Hello World\nBye."); var succed = lpr.removeJob(job);
4 Label printer example
The following example sends a EPL sequence to a TPL2844 label printer.
Eltron Programming Language (EPL and EPL2) is a printer control language used to produce printed paper labels for various Eltron (now Zebra) model printers.
var cmd =` N A0,20,0,3,1,1,N,"SKI SPORTS" X0,160,2,200,240 A300,20,0,3,1,1,N,"NEWLAND" A300,80,0,3,1,1,N,"GORRO ELBRUS" A300,120,0,3,1,1,N,"BEIG" A300,180,0,3,1,1,N,"TALLA: U" LO300,200,90,1 A70,170,0,3,1,1,N,"PVP" A10,200,0,3,1,1,N,"49.00 Euro" B0,50,0,1,2,7,70,B,"1234567" P1 `; var lpr = new Ax.net.LPRClient("192.168.100.21"); console.log(lpr.getQueueState()); var job = lpr.print(cmd); console.log("PRINT JOB:" + job);
The following example sends a ZPLII sequence to a Zebra GK420t label printer.
Reference manual: https://www.servopack.de/support/zebra/ZPLII-Prog.pdf
ZPL online viewer: http://labelary.com/viewer.html
var cmd =`^XA ^PW500 ^FX Top section with company logo, name and address. ^CF0,60 ^FO50,50^GB100,100,100^FS ^FO75,75^FR^GB100,100,100^FS ^FO88,88^GB50,50,50^FS ^FO220,50^FDIntershipping, Inc.^FS ^CF0,30 ^FO220,115^FD1000 Shipping Lane^FS ^FO220,155^FDShelbyville TN 38102^FS ^FO220,195^FDUnited States (USA)^FS ^FO50,250^GB700,1,3^FS ^XZ`; var lpr = new Ax.net.LPRClient("192.168.100.21"); console.log(lpr.getQueueState()); var job = lpr.print(cmd); console.log("PRINT JOB:" + job); var cmd =`^XA ^PW500 ^FO100,50^BY3 ^B1N,N,150,Y,N ^FD123456^FS ^XZ`; var lpr = new Ax.net.LPRClient("192.168.100.21"); console.log(lpr.getQueueState()); var job = lpr.print(cmd); console.log("PRINT JOB:" + job);