Firefox lpr workaround

For some reason unknown to mankind, Firefox doesn’t allow you to print via lpr any more.

It used to be that if you had lpr enabled on the line gtk-print-backends= in your ~/.config/gtk-3.0/settings.ini, you would be able to print directly to lpr.

But recently (I’m using Firefox 60 at the moment) this doesn’t work.

After this workaround I only kept “file” in my settings.ini.

[Settings]
gtk-print-backends=file

Workaround

My workaround was to create a simple script that watches a folder, if it finds a PDF, print it using lpr and then remove the file.

Then a simple systemd user script to get it running in the background.

The “printy” script

Most beautiful bash script ever.

#!/usr/bin/env bash

PRINTDIR="/tmp/printy"

mkdir -p "$PRINTDIR"

while true; do 
  sleep 2

  for file in "$PRINTDIR"/*.pdf; do
    if [ -f "$file" ]; then
      cat "$file" | lpr -l && rm "$file"
    fi
  done
done

Change PRINTDIR to where you’ll print PDF:s to from Firefox.

systemd unit script

[Unit]
Description=Fucked up Firefox printing workaround script

[Service]
ExecStart=/home/ogg/bin/printy
Restart=always
RestartSec=2

[Install]
WantedBy=default.target

Save file in ~/.config/systemd/user/printy.service.

To keep the script running after you login/logout and reboot. Enable “lingering” in systemd.

As root, run: systemctl enable-linger ogg

Then enable and start the script:

systemctl --user enable printy

and

systemctl --user start printy

Conclusion

If you do the above, whenever you need to print anything from Firefox, use “Print to file” and place the PDF in /tmp/printy (if you use my script above).