Jens Nöckel's Homepage

Computer notes home

Pasting externally generated PDF into Mathematica version 8

In Mac OS X, the general system clipboard ("PasteBoard") can shuttle PDF (portable document format) content back and forth between applications. That's very convenient when you're producing and consuming high-quality drawings or mathematical formulas, since PDF can serve as a resolution-independent (vector) format.

There are some common problems with PDF, too — often related to closed-source software that doesn't quite manage to implement the PDF standard or play well with the rest of the operating system (I won't go into problems related to synchronizing X11 and system clipboards here, which for example affects Inkscape):

The problem

In Mathematica version 8, copying a PDF clipping from an external application (like Preview.app) into a Notebook seems to work reasonably well at first sight. However, there is a fatal flaw (and I've reported it to Wolfram):

To see the issue, type Export["text.pdf","This is a test PDF"]; and open the resulting file in Preview.app. Choose the "Select" tool, , and do ⌘-C to copy. Back in Mathematica, start a new cell and type Export["test2.pdf",  ] and paste (⌘-V) the clipboard content into the blank space of this export statement. The resulting new file, test2.pdf, will appear empty in Preview!

So pasted PDF cannot be exported back to a PDF file. This appears to go wrong for all pasted data of this format that I have tried.

A "solution"

As a work-around, I've made a Palette that you can install in Mathematica. Here is a step-by-step walk-through of the installation process (of interest also if you want to install your own palettes):

The palette is now available as one of the menu items whenever you start Mathematica. Remember, you'll only need this when pasting PDF from sources other than Mathematica itself — copy and paste operations within the FrontEnd pose no problem.

The way this conversion button works is to create a temporary file from the Pasteboard content and use Mathematica's Import function to read it in as PDF. Fortunately, that actually doesn't have the bug that the paste process displays. So if you don't want to use my palette, just save your PDFs and Import them. Clearly, this is not as convenient as the copy-paste method; all I did was to make this detour a one-click step.

Pitfalls

Unfortunately, Import isn't bug-free either when it comes to importing PDF. It seems do do fine re-importing files that were previously exported from Mathematica, but fails with externally produced documents because it can't handle the fonts. Therefore, if you still have problems pasting PDF into your Notebook, you should consider downloading FontBegone. Follow the usage instructions on the linked page. For example, having copied a formula from a document in Preview, click the FontBegone icon first. Then click the Mathematica palette button we just installed. Now you're ready to paste the converted snippet into a Notebook.


noeckel@uoregon.edu
Last modified: Sat Dec 22 16:33:25 PST 2012