brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: cupsfilter turns a text file into a PDF from the Mac terminal

Terminal
~/tips/tip-macos-cupsfilter-pdf

cupsfilter notes.txt > notes.pdf

Converts a plain text file to a PDF from the terminal, using the Mac's print system.

Every Mac runs CUPS, the printing system, and it has a front-end that lets you use its converters without printing anything. That front-end is cupsfilter, and I like it for the moment you need a quick PDF of a log or a config file to send to someone.

By default cupsfilter converts the input to PDF and writes it to standard output, so you redirect it into a file:

cupsfilter notes.txt > notes.pdf

It guesses the input type from the file name and contents. With -m you can ask for a different output type, and -t sets the document title. If you’re curious which filters CUPS chains together for a file, --list-filters prints them without converting anything:

cupsfilter --list-filters notes.txt

I’d reach for it when someone wants a document, not a text file, and opening an editor just to hit Export as PDF feels like too much. It also fits nicely in a script that collects a few logs and turns each one into a PDF.

My caveat: forget the > and your terminal fills up with raw PDF bytes, which is ugly but harmless. More important, the man page warns that filters run as your own user and security session, not the way the print system runs them, so the output can differ from what a real print job would give. The layout is plain too. For anything with styling, export from the app that made the document.

Further reading: cupsfilter man page (CUPS), cupsfilter for macOS (SS64)

More Terminal tips ioreg -rn AppleSmartBattery | grep CycleCount Terminal can save your windows and tabs as a window group Export a Terminal profile to a .terminal file and import it on another Mac mc hidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000039,"HIDKeyboardModifierMappingDst":0x700000029}]}' All Terminal tips (116) All topics

Link