Printing as PDF to the Mac clipboard

If you use macOS, I have a little script that you might find useful. I use this at least a couple times every workday.

The Mac has great PDF workflow functionality. I will often be editing a document and want to send it out via email (or chat) to others who just need to review it and not edit it. I have no idea if they have the application I am using, so I want it to send it in PDF format so that they can reliably open it. What I usually want to do is to “print” the document as a PDF and then attach that to the email. I used to do this a lot and would then have to clean up and delete the PDF files as I did not need them. Not to mention, there were lots of intermediate clicks and mouse movements to save and then open the intermediate file. What I really wanted to do was to print as PDF directly to the clipboard. Then I just paste into the email or other destination application. That saves a few steps and clicks and mouse movements.

I wasn’t sure how to do this, so I asked on Stack Overflow and received a very useful answer. I put together a script based on that answer and have been using it for over seven years.

I have put the source code up on GitHub. Feel free to make any improvements and send me a pull request.

You can download an easy to install version.

To make this even better, I have added a keyboard shortcut bound to ⌘-P to execute this script. So printing the current document to the clipboard takes nothing more than pressing ⌘-P twice. Then I can Alt-Tab over to the destination application and press ⌘-V, no mouse movement or clicking needed. To do this, go to System Preferences→Keyboard→App Shortcuts, and add a shortcut with the exact name “Print as PDF to clipboard”.