Printing: CUPS

CUPS is an open source printing system maintained by Apple and is probably the simplest one for Unix-like systems.
With CUPS, adding and sharing printers over the network becomes a very easy task.
Download the packages with the necessary programs and drivers.
(I only have HP printers here, but also install
gutenprint,foomatic-db,foomatic-db-engine,foomatic-db-nonfree,foomatic-filters,splixandufr2as you need them)julio@julio-acer ~ $ sudo pacman -S cups ghostscript gsfonts hpoj hplip cups-pdfIf your printer is not listed, download its PPD file from http://www.openprinting.org/printers to
/usr/share/cups/model/.Add CUPS (
cupsd) to the daemons in/etc/rc.confDAEMONS=(syslog-ng @network netfs crond alsa httpd mysqld dbus @ntpd sshd cupsd samba @subsonic oidentd)Start the daemon and open the web interface: http://localhost:631/
Log in
- user: root
- password: the same as your system password
Under Administration, go to “Find New Printer”. It should list the connected printers; just pick them from the list.
The
cups-pdfpackage we installed earlier lets you use a virtual printer to generate PDFs.To configure it, select:
- Device: “CUPS-PDF (Virtual PDF Printer)”
- Make/Manufacturer: Generic
- Model/Driver: Generic Cups-PDF Printer
To reach the print server remotely, edit the file
/etc/cups/cupsd.confand replaceListen localhost:631withport 631.To allow printing over the network, all you have to do is edit samba’s configuration file.
Printing from the command line
Use
lpstatto check the available printers:julio@julio-acer ~> lpstat -p -d printer CUPS-PDF is idle. enabled since Thu 19 Jan 2012 05:47:16 PM BRST printer HP_1310 is idle. enabled since Thu 19 Jan 2012 05:50:40 PM BRST no system default destinationSet a default printer
julio@julio-acer ~> lpoptions -d HP_psc_1310_series 1 auth-info-required=none copies=1 device-uri=hp:/usb/psc_1310_series?serial=BR5763H068O2 finishings=3 job-hold-until=no-hold job-priority=50 job-sheets=none,none marker-change-time=0 number-up=1 printer-commands=AutoConfigure,Clean,PrintSelfTestPage printer-info='HP psc 1310 series' printer-is-accepting-jobs=true printer-is-shared=false printer-location='quarto do julio' printer-make-and-model='HP PSC 1310 Series hpijs, 3.11.10' printer-state=3 printer-state-change-time=1326936293 printer-state-reasons=none printer-type=10522636 printer-uri-supported=ipp://localhost:631/printers/HP_psc_1310_seriesjulio@julio-acer ~> lpstat -d system default destination: HP_psc_1310_seriesWe can print a text file with the lp command.
julio@julio-acer ~> lp teste.txt request id is HP_1310-1 (1 file(s))The print above came out fine, but the text was a bit large and had no margin. We can set the paper type, the margins and other options from the command line:
julio@julio-acer ~> lp -d HP_1310 -o media=a4 -o cpi=12 -o lpi=8 -o page-left=72 -o page-top=72 teste.txt request id is HP_1310-20 (1 file(s))
Check the manual for more options.
Printing from VIM
After a few years using VIM as my default text editor, I have come to see that you can do almost anything through it — printing text among them. Even code with syntax highlighting. Unlike GVim, which has a ‘Print’ entry in the File menu, printing from VIM can only be done with commands, and they are worth memorizing:
Open a text file in VIM and use the following command to print it on the default printer:
:hardcopyThe printout came out with margins and with the file name and page number in the header.
We can also use another printer, such as the CUPS-PDF one we configured earlier
:set printdevice=CUPS-PDF :set printoptions=paper:A4,syntax:y,wrap:y,number:y :hardcopy
By default CUPS-PDF saves the files in /var/spool/cups-pdf/julio. To change that, edit the
following line in the file /etc/cups/cups-pdf.conf: Out /home/${USER}
Note: If you are going to print source code, switch the colorscheme to the default first.
Links

I’m a Brazilian-German computer engineer based in Germany, passionate about tech, science, photography, and languages.
I’ve been programming for about two decades already, exploring everything from mobile apps and web development to machine learning. These days I focus on cloud SRE and data engineering.
I volunteer in the open source and Python communities, helping organize PyCon DE and PyData Berlin, serving on the PSF D&I Work Group, mentoring, and contributing code and translations.
On my blog, I share Linux tips, setup guides, and personal notes I’ve written for future reference. I hope others find them helpful as well. The content is available in multiple languages.
Browse my gallery for some of my photography.
Away from the keyboard, you’ll find me at concerts, playing clarinet, cycling, scuba diving, or exploring new places, cultures, and cuisines.
Always happy to connect! 🙂