Captain Spaulding
Posts: 1
Joined: Tue Apr 28, 2015 12:56 pm

Using LPRNG as a print server

Tue Apr 28, 2015 1:56 pm

If you don't get along with using CUPS as a print server on the pi, I recommend using LPRNG instead - it's lightweight, reliable, and works perfectly with printer drivers installed on client machines (well, at least with all Ubuntu, Windows and Android clients that I've tried). Here's how to get it working with any printer of any type that you've attached to a USB port on the pi. I'm also assuming you already have samba installed (there are lots of threads on that in this forum) and that you know how to use a text editor with sudo, as you'll need to edit a couple of files with root privileges.

1. Install lprng in the usual way with

Code: Select all

sudo apt-get install lprng
2. Sudo edit the /etc/printcap file to include just the following lines:

Code: Select all

Anyprinter|localprinter:\ 
        :lp=/dev/usb/lp0:\
        :sd=/var/spool/lpd/Anyprinter:\
        :mx#0:\
        :sh:
Save the file and exit the editor. This printcap file is all you need to install Anyprinter as a raw printer, with no drivers, on the pi. The printer drivers will need to be installed on the client, and all data will be sent transparently to the pi. (You can and should of course substitute the name of your printer for Anyprinter.)

3. If you want to connect only via samba shares, you should go on to the next step and you can miss this part out. But if you want to connect directly to a USB printer (for instance, by creating a local lpd port in Windows) there are two changes you need to make to the current rather odd default configuration for lprng:

Sudo edit the file /etc/lprng/lpd.conf and add the line

Code: Select all

lpd_listen_port = 515
and then sudo edit the file /etc/lprng/lpd.perms and comment out the line

Code: Select all

REJECT NOT SERVER
by adding ## at the beginning.

The first of these changes makes lprng listen on the default port 515 for any incoming printer jobs, and the second one allows incoming print jobs from connected clients.

4. Now restart lprng with

Code: Select all

sudo service lprng restart
.
5. That's all you need to do in order to install any USB printer as an lpr device on the pi and connect to it directly using lpr/lpd protocols.

However, it's much more convenient if we just make sure that any clients connecting to the pi over samba can see the printer as a samba share.

6. You'll need to sudo edit the /etc/samba/smb.conf file. At the end of the [global] section at the top of smb.conf, insert the following lines:

Code: Select all

    load printers =  yes
    printing = lprng
    printcap name = /etc/printcap
    print command =  	  /usr/bin/lpr  -P%p -r %s
    lpq command   =  	  /usr/bin/lpq  -P%p
    lprm command  =  	  /usr/bin/lprm -P%p %j
    lppause command =     /usr/sbin/lpc hold %p %j
    lpresume command =    /usr/sbin/lpc release %p %j
    queuepause command =  /usr/sbin/lpc stop %p
    queueresume command = /usr/sbin/lpc start %p
The first three lines tells samba to use printcap to identify printers and to use lprng for print services. The other lines tell samba how to print using lprng.

7. Next. at the end of smb.conf, add the following lines:

Code: Select all

[printers]
    comment - All Printers
    browseable = no
    path = /var/spool/samba
    printable = yes
    guest ok = no
    read only = yes
    create mask = 0700
This tells samba where to spool printer data, to let all clients access printers, and to treat all printers the same.

8. Before you save smb.conf and leave your editor, make sure you comment out any lines or sections left that might conflict with what you've just added (for instance, if you'd previously been using CUPS). You comment out lines by placing the # character at the start. Once you've done that, save the smb.conf file and exit the editor.

9. Restart samba with

Code: Select all

smbcontrol all reload-config
sudo service smbd restart
Your clients should now all be able to see Anyprinter as a network printer, and all you need to do is to make sure that you've installed the correct drivers on the client to print perfectly.

10. Note: If you have more than one USB printer attached to the pi, just add it to the end of the /etc/printcap file like this:

Code: Select all

Anotherprinter|localprinter:\ 
        :lp=/dev/usb/lp1:\
        :sd=/var/spool/lpd/Anotherprinter:\
        :mx#0:\
        :sh:
You can see that the second printer (Anotherprinter) will be using the /dev/usb/lp1 port and the /var/spool/lpd/Anotherprinter print queue, whereas the first printer (Anyprinter) used the /dev/usb/lp0 port and the /var/spool/lpd/Anyprinter print queue.

aspirin
Posts: 5
Joined: Wed Jul 04, 2012 7:55 am

Re: Using LPRNG as a print server

Wed Apr 13, 2016 10:26 pm

This post maybe a year old but has been a real help. I have been messing about with CUPS but as my printer didn't have a Linux driver it was always going to be a challenge to someone of my ability.

RichCott
Posts: 2
Joined: Thu Jan 26, 2017 3:06 pm

Re: Using LPRNG as a print server

Thu Jan 26, 2017 3:26 pm

Hi,
I'm new to this (Pi at least)... I had problems with using cups and samba as a print server and have just tried this lprng mechanism... but sadly not yet successfully.
I'm using two usb printers networked from the pi and both appear accessible on my windows 10 machine 1st go... which is a big step up from CUPS... but printing to either from windows fails... and I can't diagnose ... I can see files being created in the /spool directories (and they stay there) but no output from printers. How is each printer associated with the correct usb port?

My pi is working well with a usb hard drive as a file server.

Any words of advice and guidance much appreciated (?? I'm using Jesse... did any directories move?)

Thanks, Richard

RichCott
Posts: 2
Joined: Thu Jan 26, 2017 3:06 pm

Re: Using LPRNG as a print server

Sun Jan 29, 2017 3:21 pm

Update... provided I use a single printer lprng works fine but when I add a second printer and pi is rebooted or unplugged etc. then which printer is LP0 and LP1 can change... is there a way of more explicitely setting individual usb ports to be lp0 or lp1.

Thanks Richard

User avatar
scruss
Posts: 4855
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON

Re: Using LPRNG as a print server

Sun Jan 29, 2017 4:41 pm

Yes, there is - but it's going to be difficult if the two printers are the same. Your system may already be creating different device links in /dev/usb/by-id

You'll need to know the USB IDs of your printers (lsusb will tell you), and optionally if the devices return a serial number (searching through dmesg output might help; not all printers do, though). Then you'd have to come up with a suitable udev rule to put in /etc/udev/rules.d/, like the example in this comment:

Code: Select all

SUBSYSTEMS=="usb", ATTRS{idVendor}=="04a9", ATTRS{idProduct}=="266a", ATTRS{serial}=="0000A1551Krc", SYMLINK+="usb/lbp3000"
What this rule does: every time the USB device with Vendor ID 04a9, Product ID 266a and serial number 0000A1551Krc is attached, udev creates a device node for it called /dev/usb/lbp3000. Your IDs will be different.

I remember lprng from my earlier Linux days. While it works well if you have a printer supported by GhostScript, modern driver support seems a bit lacking: I bet my no-name USB receipt printers wouldn't work with it. Most of the printer questions here are about connecting printers that only have x86 Linux drivers, or no Linux drivers at all. Also, lprng doesn't use the same "everything is a PDF" approach that CUPS uses. While CUPS is bloated and a bit confusing, it did eliminate the variability (and potential security issues) in moving large chunks of executable PostScript code around systems. It might've been cool relying on PostScript twenty years ago in a carefully staffed corporate Unix environment (it was! I did!), the Raspberry Pi is a consumer device and the user or this forum is the only support available.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.
Pronouns: he/him

boghison
Posts: 2
Joined: Sun Dec 07, 2014 3:48 pm

Re: Using LPRNG as a print server

Mon Jan 08, 2018 12:53 pm

Hi!

I tried to use these steps for my Canon LBP2900. Unfortunately, when I try to print something, checkpc -f says "lp0 - device or resource busy". However, the only process using lp0 is lpd. What could be the cause of this?

flight750
Posts: 3
Joined: Mon Apr 29, 2019 7:38 pm

Re: Using LPRNG as a print server

Mon Apr 29, 2019 8:13 pm

Hey All,

I struggled for a while trying to get this to work with a Samsung ML-2545 printer (really low cost mono 20ppm workhorse that just keeps coming back for more...) from Windows 10, using the Samsung Universal Print Driver 3. I setup the Raspberry Pi per the instructions above, but couldn't get it to work. Here's what I finally found needed to be addressed to make it work:

1) Windows 10 "home" (at least) does not have the LPR "port" drivers installed, which are needed to use this, even though there are mis-leading indications in some of it's dialog panels that it does... (Doh!) so you need to add them:

control panel --> Programs and Features --> Turn Windows Features on or off --> under "Print and Document services", make sure both LPD and LPR services are checked --> click OK. Create a new port using your Pi info, and setup the printer using the newly available "LPR port" you created.

2) Since the drivers for the Samsung ML-2545 are not available for the Raspberry Pi, the printer was configured as a Generic printer; it wasn't recognized as that device by Windows either. When I looked at the printer properties, I found that "Printer Model (under "Device Options" tab) was also set to Generic mono printer. I selected the printer model "ML-2540" and then it all worked!

I hope this helps someone in a similar situation! :)
Roger

abhideep
Posts: 1
Joined: Mon Oct 26, 2020 6:56 am

Re: Using LPRNG as a print server

Mon Oct 26, 2020 7:02 am

Captain Spaulding wrote:
Tue Apr 28, 2015 1:56 pm
If you don't get along with using CUPS as a print server on the pi, I recommend using LPRNG instead - it's lightweight, reliable, and works perfectly with printer drivers installed on client machines (well, at least with all Ubuntu, Windows and Android clients that I've tried). Here's how to get it working with any printer of any type that you've attached to a USB port on the pi. I'm also assuming you already have samba installed (there are lots of threads on that in this forum) and that you know how to use a text editor with sudo, as you'll need to edit a couple of files with root privileges.

1. Install lprng in the usual way with

Code: Select all

sudo apt-get install lprng
2. Sudo edit the /etc/printcap file to include just the following lines:

Code: Select all

Anyprinter|localprinter:\ 
        :lp=/dev/usb/lp0:\
        :sd=/var/spool/lpd/Anyprinter:\
        :mx#0:\
        :sh:
Save the file and exit the editor. This printcap file is all you need to install Anyprinter as a raw printer, with no drivers, on the pi. The printer drivers will need to be installed on the client, and all data will be sent transparently to the pi. (You can and should of course substitute the name of your printer for Anyprinter.)

3. If you want to connect only via samba shares, you should go on to the next step and you can miss this part out. But if you want to connect directly to a USB printer (for instance, by creating a local lpd port in Windows) there are two changes you need to make to the current rather odd default configuration for lprng:

Sudo edit the file /etc/lprng/lpd.conf and add the line

Code: Select all

lpd_listen_port = 515
and then sudo edit the file /etc/lprng/lpd.perms and comment out the line

Code: Select all

REJECT NOT SERVER
by adding ## at the beginning.

The first of these changes makes lprng listen on the default port 515 for any incoming printer jobs, and the second one allows incoming print jobs from connected clients.

4. Now restart lprng with

Code: Select all

sudo service lprng restart
.
5. That's all you need to do in order to install any USB printer as an lpr device on the pi and connect to it directly using lpr/lpd protocols.

However, it's much more convenient if we just make sure that any clients connecting to the pi over samba can see the printer as a samba share.

6. You'll need to sudo edit the /etc/samba/smb.conf file. At the end of the [global] section at the top of smb.conf, insert the following lines:

Code: Select all

    load printers =  yes
    printing = lprng
    printcap name = /etc/printcap
    print command =  	  /usr/bin/lpr  -P%p -r %s
    lpq command   =  	  /usr/bin/lpq  -P%p
    lprm command  =  	  /usr/bin/lprm -P%p %j
    lppause command =     /usr/sbin/lpc hold %p %j
    lpresume command =    /usr/sbin/lpc release %p %j
    queuepause command =  /usr/sbin/lpc stop %p
    queueresume command = /usr/sbin/lpc start %p
The first three lines tells samba to use printcap to identify printers and to use lprng for print services. The other lines tell samba how to print using lprng.

7. Next. at the end of smb.conf, add the following lines:

Code: Select all

[printers]
    comment - All Printers
    browseable = no
    path = /var/spool/samba
    printable = yes
    guest ok = no
    read only = yes
    create mask = 0700
This tells samba where to spool printer data, to let all clients access printers, and to treat all printers the same.

8. Before you save smb.conf and leave your editor, make sure you comment out any lines or sections left that might conflict with what you've just added (for instance, if you'd previously been using CUPS). You comment out lines by placing the # character at the start. Once you've done that, save the smb.conf file and exit the editor.

9. Restart samba with

Code: Select all

smbcontrol all reload-config
sudo service smbd restart
Your clients should now all be able to see Anyprinter as a network printer, and all you need to do is to make sure that you've installed the correct drivers on the client to print perfectly.

10. Note: If you have more than one USB printer attached to the pi, just add it to the end of the /etc/printcap file like this:

Code: Select all

Anotherprinter|localprinter:\ 
        :lp=/dev/usb/lp1:\
        :sd=/var/spool/lpd/Anotherprinter:\
        :mx#0:\
        :sh:
You can see that the second printer (Anotherprinter) will be using the /dev/usb/lp1 port and the /var/spool/lpd/Anotherprinter print queue, whereas the first printer (Anyprinter) used the /dev/usb/lp0 port and the /var/spool/lpd/Anyprinter print queue.

Thanks for the help. Its work for me. Now I am able to send the print information to Raspberry PI using Lprng. But a small problem is facing that after giving the instruction, the print job is not triggered, i need to restart the raspberry pi to trigger the print job. Is their any configuration need to made to pick up the jobs from queue or corn job need to configure.
Please advice.

User avatar
scruss
Posts: 4855
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON

Re: Using LPRNG as a print server

Mon Oct 26, 2020 3:19 pm

This is a very old thread and lprng is far behind any capabilities that CUPS, the supported print system, has. The instructions from 2015 upthread are unlikely to work now.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.
Pronouns: he/him

neogeek
Posts: 1
Joined: Sat Dec 19, 2020 1:12 am

Re: Using LPRNG as a print server

Sat Dec 19, 2020 1:15 am

While this is an old thread it still works great. Literally just reinstalled it on a new pi with no problems on my printers.

I do know that certain printers are tricky. I have mine working 100% without a problem from the above instructions for an HP1320 and a Dymo 4XL.

Return to “Beginners”