# Avoiding grid lines inside filled area in RegionPlot exported as PDF

Basically the same question as here, but now with regions which have opacity.

RegionPlot[x^2 + y^2 < 1, {x, -1, 1}, {y, -1, 1},
PlotStyle -> Opacity[0.5, Black]];
Export["tmp/region.pdf", %]


How do I remove the black lines when exporting to pdf?

To get nice looking PDF export in this case is not easy. Export is really doing something wrong here. The best option I think would be to do the following:

regionplot =
RegionPlot[x^2 + y^2 < 1, {x, -1, 1}, {y, -1, 1},
PlotStyle -> Opacity[0.5, Black]];

Export["region.pdf",
Show[regionplot,
Prolog -> {Opacity[0], Texture[{{{0, 0, 0, 0}}}],
VertexTextureCoordinates -> {{0, 0}, {1, 0}, {1, 1}},
Polygon[{{0, 0}, {.1, 0}, {.1, .1}}]}]
]


Here, I've tricked Mathematica into rasterizing the opaque parts of the plot by using Show to combine the RegionPlot with a single invisible textured polygon that triggers the rasterization upon Export. To insert this trick, I used a Prolog option, but instead you could also use Epilog. If you do this often, it would be convenient to define something like

rasterTrick[plot_] :=
Show[plot,
Prolog -> {Opacity[0], Texture[{{{0, 0, 0, 0}}}],
VertexTextureCoordinates -> {{0, 0}, {1, 0}, {1, 1}},
Polygon[{{0, 0}, {.1, 0}, {.1, .1}}]}]

Export["region.pdf", regionplot // rasterTrick]


The above is the exported PDF.

This is borrowed from my earlier answer here, except that SetOptions in this case doesn't work properly as a way to make this trick stick with every RegionPlot.

The Adobe PDF generators that are built into various products appear to often be inferior to the results obtained "Printing" with Adobe Acrobat Professional. Using that method, instead of Export, I obtain:

If you print directly to PDF (on Mac, you select image, Print Graphic..., then Save as PDF...), you get good results:

So it looks like you can work round the bug in Export.

(This is probably the equivalent of another answer, but doesn't involve giving any money to Adobe...)

• My HP Windows came with PDFComplete accessed from Print. But this was only a trial license that has expired. Using File, SaveSelection As.. gives the bad version. – David Park Jan 28 '13 at 20:54