# Upon PDF export, edgeless rectangles do not tile perfectly, and corners may be cut. Is this a bug?

Note: this problem is no longer present in version 10.

Exporting the following as a PDF file

Graphics[{
{Red, Rectangle[{0, 0}, {1, 1}]},
{Green, Rectangle[{1, 0}, {2, 1}]}
}]


does not produce perfectly tiled rectangles, and some of the corners are cut too, as shown here:

and here:

Is this a bug?

I solve the problem by giving them some tiny edges:

Graphics[{
EdgeForm[{Red, Thickness[Tiny]}],
{Red, Rectangle[{0, 0}, {1, 1}]},
EdgeForm[{Green, Thickness[Tiny]}],
{Green, Rectangle[{1, 0}, {2, 1}]}
}]


The rectangles are slightly larger, and their sizes are slightly different; practically this isn't a problem. But is there a more elegant solution?

-
I believe that, yes, it is a bug--in the Mac OS Preview app, which employs a rather confusing interpolation algorithm to what is displayed. As I don't have a Mac, I can't confirm that this is definitely a duplicate of that question, but the PDF output (from version 8) is certainly correct for me on Windows when using SumatraPDF, Adobe Reader, and Acrobat Pro. – Oleksandr R. Apr 25 '13 at 18:02
The problem is still there in my Adobe Reader 10.1.6: see here. – Taiki Apr 25 '13 at 18:54
Hmm, I see. This problem seems to have appeared in version 9 or 9.0.1. Okay, looks like Mathematica's bug, then--especially considering its absence in previous versions. – Oleksandr R. Apr 25 '13 at 19:07
A workround is to export as EPS, then open EPS in Preview - seems to convert without that problem... – cormullion Apr 25 '13 at 19:16
Deleting the green square in Illustrator still leaves a slightly larger green frame: imgur.com/x0BNyO6 It would probably be good if you could report this to support@wolfram.com – Szabolcs Apr 25 '13 at 21:33

Unfortunately some effects, such as transparency, are not supported in EPS, so that workaround is not always usable. I found a different workaround with different tradeoffs:

• instead of Rectangle use Polygon
• specify the colours using the VertexColors option of Polygon

The polygons will be correct size and will not overlap when exported to PDF. However, they will be broken up into triangles, and depending on the PDF viewer the seams may be subtly visible, especially if the polygons are transparent.

Examples:

t1 = Normal@
Graphics[GraphicsComplex[
Tuples[Range[5], 2], {Opacity[0.5],
Polygon[#,
VertexColors -> ConstantArray[RandomReal[1, 3], 4]] & /@ Join @@ Table[{1, 2, 5 + 2, 5 + 1} + i + j, {i, 0, 3}, {j, 0, 3*5, 5}]}]]

t2 = Normal@
Graphics[GraphicsComplex[
Tuples[Range[5],
2], {Opacity[0.5], {RGBColor @@ RandomReal[1, 3], Polygon[#]} & /@
Join @@ Table[{1, 2, 5 + 2, 5 + 1} + i + j, {i, 0, 3}, {j, 0, 3*5, 5}]}]]


t1 will export as precisely sized rectangles while t2 will export as overlapping rectangles.

Zoomed in:

-

As an alternative answer, you could try the function rasterTrick in my answer here. The output of Export["file.pdf",graphics//rasterTrick] looks fine to me using version 9.0.1 on OS X (where graphics is the original example in your question) – Jens Jul 2 '14 at 22:39