# PDF export of polygons: How to get rid of polygon boundary lines?

I have the following polygon:

generated using this code (extracted from my previous question):

data = Table[{x, (x - 5)^2 + 3}, {x, 0, 10}];
p1 = ListLinePlot[data, Filling -> {1 -> {15, {Blue, None}}}];
p1 = Normal@p1 /.
Polygon[x_] :>
Polygon[x,
VertexColors -> (Blend[{RGBColor[0, 0, 1, .5],
RGBColor[0, 0, 1, 0]}, #] & /@ Rescale[x[[All, 2]]])];
polygon = First[Cases[Normal@p1, _Polygon, Infinity]];
Graphics[{EdgeForm[None], polygon}, AspectRatio -> 1]


The image above was generated via Export["test.png",%]. However, if I export to pdf instead, I see the boundaries of the polygons. This is a screenshot of the pdf:

How can I get rid of these blue lines?

This post seems related, but the solution there was to raster the polygon. That would make sense for thousands of polygons, but in this case it's only 7 of them so I suspect it should be possible to get a true vector format pdf out of this.

• On my Mac I export as an eps and then open in Preview to convert to pdf. The lines do not show. – Bob Hanlon Jan 30 '17 at 18:09
• I don't have a Mac, but on Linux the eps version has the lines as well. – Felix Jan 30 '17 at 18:15
• I confirm the bug on Mathematica 11.0. I also tried the SetOptions[\$FrontEnd, PrintingStyleEnvironment -> "Working"] method without success. – Johu Feb 1 '17 at 7:25

For me, AbsoluteThickness[-1] does the trick in

Graphics[{EdgeForm[{White, AbsoluteThickness[-1]}], polygon}, AspectRatio -> 1]


In the final PDF there are slight white lines visible. Those are artifacts of the displaying process (alpha blending) and won't be visible in the final print. Note that the white lines have constant thickness no matter how deep you zoom in.

## Update

I downloaded the PDF you provided in the comments and on my OSX here it looks like this

• Thanks for the solution that works with transparency. I can't test the printing for lack of a printer. Is this alpha blending a general pdf issue or related to Mathematica? I have to say, though, that my lines are not white but still blue (only in constant thickness, as you say), showing like this both in Okular and in Acrobat Reader, see here for the pdf: filetea.me/n3w3CCJt2R5RTSPGKEg6gaVHg – Felix Feb 1 '17 at 15:51
• @Felix I'm on OSX (now, I was on Linux earlier) and your PDF doesn't have the blue lines here. As I said, if the polygons do not overlap, what you experience is rendering artifacts of the PDF viewer. See my update in the answer. – halirutan Feb 1 '17 at 15:58
• That's very strange. Also on OSX it shows blue lines for me when using Acrobat Reader. However, with Preview it's white lines. – Felix Feb 1 '17 at 16:07
• @Felix Yep, in Acrobat CC 2017 it shows blue lines for me as well. In the built-in Preview program it shows white lines. – halirutan Feb 1 '17 at 16:09

The issue is related to the opacity of the VertexColors. You can easily avoid it in this case by blending into white and not opaque.

data = Table[{x, (x - 5)^2 + 3}, {x, 0, 10}];
p1 = ListLinePlot[data, Filling -> {1 -> {15, {Blue, None}}}]
p1 = Normal@p1 /.
Polygon[x_] :>
Polygon[x,
VertexColors -> (Blend[{RGBColor[0, 0, 1],
RGBColor[1, 1, 1]}, #] & /@ Rescale[x[[All, 2]]])];
polygon = First[Cases[Normal@p1, _Polygon, Infinity]];
plt = Graphics[{EdgeForm[None], polygon}, AspectRatio -> 1]


(No hidden lines)

In case you inist having opacity, there are various methods suggested to work around the bug:

• Very good answer. Indeed, the lines completely disappear. Note that the colors are different than in my question because the first color should be Blend[{RGBColor[0, 0, 1], RGBColor[1, 1, 1]}, 0.5] and not RGBColor[0,0,1]. It works perfect for my case, but sometimes you want the transparency option, hence I give the bounty to this one an accept halirutan's. – Felix Feb 1 '17 at 15:42
• I guess you did not consider rasterization an option? – Johu Feb 1 '17 at 19:26
• Only if everything else fails. I thought there should be a way to export polygons as vector graphics without defects. – Felix Feb 1 '17 at 19:28

Looks like a bug. One way around it is to export to png, re-import and re-export:

Export["test.png", %]
Export["test.pdf", Import["test.png"]]


Works on my Mac + 11.0.1.0.

• But that's the same as rastering. – Felix Feb 1 '17 at 15:54