# Removing clipping masks from exported PDFs

I usually export graphics from Mathematica as PDFs which I tweak with Adobe Illustrator. When most plots are exported from Mathematica as PDFs they contain a large number of mostly useless clipping masks.

See:

Plot[Sin[x], {x, -Pi, Pi}]


https://dl.dropbox.com/u/3730003/pi.pdf

All the clipping masks can be removed from this PDF with no effect on the look of the plot.

Is there a way to have the PDF exported without clipping masks or somehow remove them automatically after export, ideally with Mathematica?

Note: in some cases (see below) the clipping masks are needed but I don't need a smart solution, if I can get it of all the clipping masks, useless and useful thats fine.

Plot[Sin[x], {x, -2 Pi, 2 Pi}, PlotRange -> {{-Pi, Pi}, All}]

-
Do you see the masks when opening the doc with other programs? –  belisarius Jul 23 '12 at 19:16
@belisarius It's a feature of the PDFs, it should be visible in any decent vector editor that supports PDF. –  Szabolcs Jul 23 '12 at 19:23
I would try re-processing the PDFs with various programs (xpdf? ghostscript?) and see if that reomoves the masks. I know the problem well, but I haven't tried to come up with an automated solution yet. –  Szabolcs Jul 23 '12 at 19:24
@Szabolcs define "decent" :) –  belisarius Jul 23 '12 at 19:38
Once upon a time I fixed some EPS bounding box issues by stringbased postprocessing of Mathematica output. Are the masks easily identified in a PDF? –  Yves Klett Jul 23 '12 at 19:56

If you are willing to export to eps first and then convert to pdf, try if this works for you. I think it does for me. It is a pretty dirty hack though, so there might be side effects I haven't noticed.

p=Plot[Sin[x], {x, -Pi, Pi}];
Export["plot.eps",StringReplace[ExportString[p,"EPS"],"clip np"->""],"Text"]


Also, it might not work for all plots.

Edit

Actually there is a pretty obvious side effect in form of a colored border around the actual curve. I think with a little more tinkering one might be able to get rid of that too.

-