How to set up a shared PDF printer on your local network
I've recently ended up setting up a PDF printer on my local network in an effort to transfer some pictures out of a ridiculous i-device (I tell you, Apple'e iOS is the worst for being a walled garden). Since the process for doing so wasn't entirely obvious, I'm documenting it in this blog post to remind myself for later. If you find it useful, please let me know in the comments below!
Firstly, you'll need a machine running Linux. Any distribution will do, but I'll be using an
apt-based distribution, so you may need to alter some of the commands here to suit your system.
Firstly, we need install the cups (which stands for the Common Unix Printing Service) PDF printer driver. It comes with a lot of junk if you're not careful, so here I use
--no-install-recommends to avoid installing any unnecessary packages.
sudo apt install printer-driver-cups-pdf --no-install-recommends
If you've got a firewall running (which you really should - see this post of mine for more information on that), then you'll need to open the port 631 for TCP traffic to allow people to print. If you're using
ufw, then this should do the trick:
sudo ufw allow cups
If not, then you may need to specify the port number explicitly:
sudo ufw allow 631/tcp
With the printer installed, we next need to open it to the world. Before that though, we should make some changes to the configuration file, which is located at
/etc/cups-pdf.conf. Firstly, I wanted to put the resulting PDFs into my file server's shared folder. This is achieved by editing the
AnonDirName settings. They should already be present in the configuration file - it's just a matter of changing their values:
Out /absolute/path/to/output/dir AnonDirName /absolute/path/to/output/dir
I also wanted to customise the user account and permissions that it saves the pdfs with. I did this through the
AnonUMask settings - which should also be present by default:
AnonUser username AnonUMask 0007
The umask is basically an inverted permission octal. I found a good calculator calculator online to do it for me :P (Don't forget the preceding
0 - it's important!)
Finally, I experienced an issue whereby cups kept overwriting the same file again and again because the iPad wasn't smart enough to send the photos to print with their actual filenames - instead opting to send them all as
Photo.pdf. Thankfully though,
cups-pdf has the
Label option (also specified by default) that ensures that output filenames don't clash. Setting it to
1 instead of
0 solved the problem for me:
Note that some of these properties may be prefixed with a hash (
#). You'll need to remove this in order for it to take effect.
With the new PDF printer configured, it's time to open it up to our local network. Here's how to do that:
sudo cupsctl --share-printers sudo lpadmin -p pdf -o printer-is-shared=true
Note that if you want to open it up to more than your local subnet you'll need to do some additional configuration - such as configuring authentication, for instance. Such things are beyond the scope of this blog post, but if there's the demand (comment below!) I can certainly investigate writing something up.
Found this useful? Got a better / different solution? Comment below!