Add a Printer in i3


Printing in Linux can be challenging. My experience was less than straightforward. Here is the winding path of things I learned, experimented with and troubleshot. Eventually, I did get a PDF to print.

CUPS

What is CUPS? It stands/stood for Common UNIX Printing System. It converts the print job into a language that the printer can understand so that the ink splatters on the page in just the right way as to create a Mona Lisa replica.

It's probably already running on your computer. Check:

❯ systemctl | rg cups
  cups.path              loaded active running   CUPS Scheduler
  cups-browsed.service   loaded active running   Make remote CUPS printers available locally
  cups.service           loaded active running   CUPS Scheduler
  cups.socket            loaded active running   CUPS Scheduler

Yep, 'tis.

Once you have CUPS running locally, you should be able to print from your computer.

List Available Printers

To see what printers you already have installed, run the cli to show all cups-enabled printers:

lpstat -p

(There are other cool commands, like lpstat -R to see pending print jobs.)

Or see similar info in a web gui:

xdg-open localhost:631

Find Device Drivers

To manually install a printer, you'll need to find drivers for your printer model. Mine's an "HP OfficeJet Pro 8610", so I queried:

lpinfo -m | rg 8610

And found:

drv:///hpcups.drv/hp-officejet_pro_8610.ppd HP Officejet Pro 8610, hpcups 3.21.12

(Apparently lpinfo is deprecated. What replaces it?)

The .ppd file returned will list all the capabilities of the printer in a standard way.

Choose Network Protocol

My printer is available over wifi. I can connect to it with any number of printing protocols. To see these protocols (described as "devices" by lpinfo), run:

lpinfo -v

I'm not sure which is best. lpd, Line Printer Daemon, and ipp, Internet Printing Protocol sound half-familiar to me. I don't know which one is best. I finally got all this working with ipp.

Manually Install Printer

To install a printer manually, use lpadmin:

lpadmin -p hp8610-jtmade1 -v ipp://192.168.40.9 -m drv:///hpcups.drv/hp-officejet_pro_8620.ppd -E

You'll need to have

  • -p - printer name
  • ipp - printing protocol
  • 192.168.40.9 - IP address of printer
  • drv://... - driver for your printer
  • -E - enable the printer (must be last)

You may get a warning:

lpadmin: Printer drivers are deprecated and will stop working in a future version of CUPS.

As far as I can tell, it works anyway.

You should now be ready to print. You can use any 'ol application print dialog. Or you can use the cli, lp:

lp myfilename.pdf

This will print to the default printer. Or by printer name:

lp -d hp8610-jtmade1 myfilename.pdf

Set Printing Options From Terminal

To configure printing options, you'll need to query which options are available to your printer:

lpoptions -p hp8610-jtmade1 -l

That will return something like:

PageSize/Media Size: Card3x5 L L.FB Photo3x5 Photo10x15 Hagaki Hagaki.FB Card4x6 Photo4x6 Photo4x6.FB Photo10x15.FB A6 A6.FB Photo5x7 Photo13x18 Photo5x7.FB Photo13x18.FB Photo2L Photo2L.FB Oufuku Card5x8 Statement A5 A5.FB 6x8 JB5 JB5.FB JB5.Duplex Executive Executive.Duplex 8x10 8x10.FB *Letter Letter.FB Letter.Duplex CardLetter A4 A4.FB A4.Duplex CardA4 8.5x13 Legal EnvA2 EnvCard EnvC6 EnvChou4 EnvMonarch EnvDL Env10 EnvChou3 EnvC5 Custom.WIDTHxHEIGHT
Duplex/Double-Sided Printing: DuplexNoTumble DuplexTumble *None
InputSlot/Media Source: *Auto Tray1 Tray2
ColorModel/Output Mode: *RGB CMYGray KGray
MediaType/Media Type: *Plain Glossy TransparencyFilm
OutputMode/Print Quality: *Normal Draft Best Photo
OptionDuplex/Duplexer Installed: *False True

To print in black/white, double-sided, reverse-order:

lp -o Duplex=DuplexNoTumble -o ColorModel=CMYGray -o outputorder=reverse myfilename.pdf

See more lp instructions in the CUPS web gui.

Well, that feels good. Maybe a bit exhausting. What a journey!

Still have problems? Read on, brother! Maybe there's a fix for you here still...

Problem: Installed Printer Won't Print

Apparently the cups-browsed package will auto-install printers on the network. Well, that happened to me. I had a nicely-identified printer in my list of printers. The problem was that it wouldn't accept print jobs. On the print job, I would get the error message:

"No suitable destination host found by cups-browsed."

Removed cups-browsed:

sudo apt purge --autoremove cups-browsed

Reboot. Install a printer manually (below).

Problem: Stuck on "Connecting to Printer"

I entered the correct IP. The printer is added, registered with CUPS. Still, it would not send the job and print. Maybe you need to loosen up the permissions on who can print.

sudo vim /etc/cups/cupsd.conf

And modify, commenting out (with #) the sections for AuthType and Require:

  # All administration operations require an administrator to authenticate...
  <Limit CUPS-Add-Modify-Printer CUPS-Delete-Printer CUPS-Add-Modify-Class CUPS-Delete-Class CUPS-Set-Default CUPS-Get-Devices>
    #AuthType Default
    #Require user @SYSTEM
    Order deny,allow
  </Limit>

  # All printer operations require a printer operator to authenticate...
  <Limit Pause-Printer Resume-Printer Enable-Printer Disable-Printer Pause-Printer-After-Current-Job Hold-New-Jobs Release-Held-New-Jobs Deactivate-Printer Activate-Printer Restart-Printer Shutdown-Printer Startup-Printer Promote-Job Schedule-Job-After Cancel-Jobs CUPS-Accept-Jobs CUPS-Reject-Jobs>
    #AuthType Default
    #Require user @SYSTEM
    Order deny,allow
  </Limit>

Then restart the cups server:

sudo service cups restart

Problem: Print Job Never Prints a PDF

Even after setting up the printer correctly, it's possible that the print job will be sent without error, it looks like it's processing it, but it never spits out paper and ink.

I got this when running lp:

Error: 'Unsupported document-format "application/pdf"'

The printer doesn't know how to receive a file of that type via CUPS only. There is a package separate from CUPS that needs to be added:

sudo apt install cups-filters

Try again, and it just starts printing! It knows how to receive this file type.

Problem: Remove a Printer

If you've had to try several times, adding multiple printers, you might want to clean that up. List the printers (lpstat -p), and remove by name:

lpadmin -x hp8610-jtmade1

Alternative: Desktop Printer Manager

If you have a desktop environment also installed on your system, you may already have some printer system app that can be used to manage printers. Fire up dmenu, and try:

system-config-printer

Find/add/delete should be available there.

To print a file from the terminal, use lpr:

lpr my-file.txt

It'll send to the default printer. There are options to select other destinations. Works great for simple print jobs.

Resources