Since there is clearly a bug in Import
with the PDF
format, there can only be workarounds and compromise solutions. By exporting as in your own answer, you will retain the setting of PlotRangeClipping
because at no point is it necessary to re-import the exported PDF
to Mathematica. However, this way you almost certainly will run into missing font problems when importing the PDF
(or EPS
) into other graphics programs. For example, Adobe Illustrator and likewise Inkscape will be unable to display your graphic with the correct fonts in general.
I tried this with Inkscape and your exported file test.pdf
, and it doesn't work properly.
So you could resort to finger-painting as in Mr.Wizard's answer where the clipped parts are hidden behind added rectangles, so that the result of outlinedExport
look correct.
Or you could retreat to another approach which I invented long ago, relying on an external program to convert fonts to outlines. That's what I used to do before Mathematica even had the ability to produce outlined fonts at all. The external dependence is ghostscript.
If you want to go that route, here is an updated version of that procedure:
gsExport[exportName_, ob_, opts : OptionsPattern[]] := Module[
{device,
printOption = First@Options[$FrontEnd, PrintingStyleEnvironment],
out = FileNameJoin[{$TemporaryDirectory,
"MathematicaOutput" <> StringJoin[Map[ToString, DateList[]]] <>
".pdf"}]
},
SetOptions[$FrontEnd, PrintingStyleEnvironment -> "Working"];
Export[
out,
ob,
"PDF",
FilterRules[{opts}, Options[Export]]
];
SetOptions[$FrontEnd, printOption];
device =
If[ToLowerCase[FileExtension[exportName]] == "eps", "epswrite",
"pdfwrite", "pdfwrite"];
Run["gs -sDEVICE=" <> device <> " -dNOCACHE -sOutputFile=" <>
exportName <> " -q -dbatch -dNOPAUSE " <> out <> " -c quit"];
DeleteFile[out]
]
It takes the export file name and the graphics object (ob
) as the first two arguments, and also accepts additional options appropriate for PDF
export. By default it exports to PDF
with the provided name (exportName
), but if you specify an en extension .eps
you will get encapsulated postscript instead. The fonts are replaced y outlines by executing gs
via Run
. This assumes that gs
is installed and in your system's executable PATH
.
I thought this approach was obsolete by now, but apparently there are still enough bugs in Mathematica that open-source solutions must come to the rescue once again.
Update:
The above solution continues to work with gs
version 9.16, but according to this answer on StackOverflow (and thanks to Szabolcs for pointing it out) there is a new option that you could use in the future, if you encounter problems: replace -dNOCACHE
by -dNoOutputFonts
.