A financial institution sent me a form to printout, sign, scan and send back. Normally I would have done this through my mac. macOS’s Preview is a one-stop-shop for all things pdf and is very powerful. I shuffle pages, combine pdfs, fill out forms, add text and other annotations and add signatures all in Preview. This time I decided to do this in Unix.

Printing and scanning

Linux now supports AirPrint (driverless printing) and my printer is not too ancient, so I was delighted when the printer just appeared in my printers list. To be honest, I was a little disappointed the customary blood sacrifice was not needed. I was delighted when it turned out that despite all this slickness, the printer did not, in actuality, print my document. It just sat there in the print queue. I enjoyed a nice jolt of nostalgia as I searched the internet for a solution which led me to a Brother driver utility which installed the correct drivers that allowed me to print.

Full marks go to the Brother engineers for this easy to use linux driver installation tool and clear documentation.

So now I could do my favorite Linux thing: print from the command line.

lp -o page-ranges=4 form.pdf

(I only needed to print out the signature page of the form. Why not annotate the signature electronically in the PDF itself you ask? Well, there was this big note on the form telling me not to do it, so I didn’t risk it.)

Scanning went very smoothly: I used Simple Scanner (sudo apt install simple-scan) which does the job, no mess, no fuss. It found my printer/scanner without any issues.

Annotations: okular

okular is maybe 30% Preview. It let me add annotations to the pdf (e.g. fill in a text field) which is great but it did not allow me to do any page manipulations: On Preview I would have deleted the unnneeded pages from the form and then drag-and-dropped the signature page into the original document. Fortunately Linux has qpdf.

Page manipulations: qpdf

qpdf reminds me of imagemagick: both programs in the best *inux command line program spirit. qpdf let me select the pages I needed, combine it with my scanned signature page and create a new pdf with that.

qpdf --empty --pages form.pdf 2,3 signature-page.pdf -- final-signed-form.pdf

PDF size reduction

The form they sent over was 17 MB in size, but their portal only allowed files 5MB or less. My barebones qpdf incantation created a 17 MB size file (same as the input). qpdf has some options that claim to reduce file size but they did not work for me.

Fortunately, from a hint here ghostscript, which I hadn’t touched in 16 years came to the rescue.

gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile=form-shrunken.pdf original-form.pdf

This incantation reduced the file size from 17 MB to 205 kB.

Mission accomplished and almost completely from the command line. I love my Linux laptop.