Update: Problem persists in version 10.2 on Mac OS X 10.9.5
As in previous versions, Mathematica 9 on Mac OS X (10.7.5 here) still has a problem with pasted PDF
graphics that were copied from external applications such as Preview.app
or Skim.app
(I usually use the latter).
To see the problem (this is only supposed to work on Mac), try the following:
Export["t.pdf", "Hello"];
SystemOpen["t.pdf"]
In the PDF
viewer, activate the select
tool, select all or part of the image and copy it to the clipboard (this is automatically copied in PDF
format).
Now in Mathematica, type the line
Export["t1.pdf", ];
and insert the copied PDF
directly in the slot for the second argument by performing a paste
from the clipboard.
Evaluate the cell and then look at the result:
First@Import["t1.pdf"]
The result is empty. One can also observe that the pasted PDF
in the above example looks like it's been rasterized and is being displayed at the wrong resolution. It actually isn't rasterized, but the display looks ugly and the export of such pasted PDF
simply doesn't work. To fix this, I had written the following palette some time ago:
CreatePalette[Column[{Button["Convert PDF on clipboard",
Module[{pdf, out = "/tmp/MathematicaOutput.pdf",
prog = "from AppKit import *\nboard=NSPasteboard.generalPasteboard()\nresult = board.dataForType_(NSPDFPboardType)\nif result:\n\tresult.writeToFile_atomically_('**FILENAME**',1)\n\" | /usr/bin/python"},
Run["printf \"" <>
StringReplace[prog, {"**FILENAME**" -> out}]];
CopyToClipboard[If[FileExistsQ[out], pdf = Import[out, "PDF"];
(*DeleteFile[out]*);
pdf[[1]], "No PDF"]];
], Appearance -> "Palette"],
"Click before pasting externally generated PDF"}],
WindowTitle -> "Convert External PDF"];
After evaluating this, a palette is created that you have to click right after copying a PDF
from an external application. If you then do the paste
operation again in the following line:
Export["t2.pdf", ];
First@Import["t2.pdf"]
$\mathtt{Hell}$
The result is the expected PDF
. There is another issue related to cropping of the PDF
. The above results are obtained using Skim
, but when using Preview
the crop box is lost and the original bounding box is used.
My question is: Is there a simpler way to get pasted PDF
from external applications on Mac to display properly in the notebook and then export correctly?
PDF
on other systems, then my guess would be that pastedPDF
s should also be visible there. But I've never checked to make sure... $\endgroup$