10
$\begingroup$

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?

$\endgroup$
1

3 Answers 3

16
$\begingroup$

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]

export

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.

$\endgroup$
3
$\begingroup$

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:

enter image description here

$\endgroup$
1
$\begingroup$

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

print

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...)

$\endgroup$
1
  • $\begingroup$ 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. $\endgroup$
    – David Park
    Commented Jan 28, 2013 at 20:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.