5
$\begingroup$

Bug introduced in 12 or earlier and persisting through 13.0.0 [CASE:4899765]


The following code generates a plot that has a faint outline around the top, left, and right boundaries of the filling. In Mathematica (13.0.0.0, Mac) itself, the outline is not present. It only appears when exporting.

How can I remove this outline?

Export[
    "test.pdf",
    Plot[
        Sin[x],
        {x, 0, 2 Pi},
        Filling -> Top
    ]
]

The outline also appears when exporting Graphics of Polygons and similar shapes.

screenshot of the PDF

$\endgroup$

2 Answers 2

6
$\begingroup$

How about getting rid of the Opacity in the filling?:

Plot[Sin[x], {x, 0, 2 Pi}, Filling -> Top, 
 FillingStyle -> Blend[{White, ColorData[97][1]}, 0.2]]
Export[FileNameJoin[{$TemporaryDirectory, "test.pdf"}], %];
First@Import[%]
$\endgroup$
1
  • $\begingroup$ A solution that respects the Opacity would be nice to have, but this works for my current use case. Thank you! $\endgroup$
    – A.Z.
    Jan 25 at 18:41
2
$\begingroup$

I reproduce the problem with versions 13.0.0 and 12.3.1 on Windows 10 x64, but not with version 8.0.4 on the same machine.

The issue happens when we Export to PDF a Graphics object containing a Rectangle or Polygon primitive with Opacity directive. A minimal example:

gr = Graphics[{Opacity[0.5], Rectangle[]}];
Export["test.pdf", gr] // SystemOpen

In the exported file opened by Adobe Acrobat Reader the rectangle has an unwanted outline:

screenshot

To explore the problem deeper, I define an auxiliary function that exports supplied expression to PDF, and then immediately imports the results as vector graphics:

vectorExportImportPDF[expr_] :=
  First@ImportString[ExportString[expr, "PDF", "AllowRasterization" -> False],
    If[$VersionNumber >= 12.2, {"PDF", "PageGraphics"}, {"PDF", "Pages"}],
    "TextOutlines" -> False];

Apply it to the above Graphics:

vectorExportImportPDF[gr] // ResourceFunction["ShortInputForm"]

screenshot

We see that imported graphics contains an explicit outline defined via JoinedCurve. We can see the outline alone if we remove the FilledCurve object:

vectorExportImportPDF[gr] /. _FilledCurve -> {}

screenshot

Apparently, it is a bug. Reported to the support as [CASE:4899765].


A solution that respects the Opacity would be nice to have

A workaround is to Export a FilledCurve, but not Rectangle or Polygon primitive:

gr2 = vectorExportImportPDF[gr] /. _JoinedCurve -> {};

vectorExportImportPDF[gr2] // ShortInputForm

screenshot

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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