When I try to export a Grid object with a White background, I get a gray border around 3 of the 4 sides in the resulting pdf:

grid4pdf = Grid[{{"a", "b", "c"}, {"d", "e", "f"}, {"g", "h", "i"}}, Background -> White]
Export["thepdfhasborders.pdf", grid4pdf]

I get this as the output pdf:

(the light gray is the Adobe Acrobat Reader background). Any idea why the dark gray border shows up in the pdf, and how I can get rid of it? I typically use the ReverseColor.nb stylesheet, but this behavior persists even in a Default.nb stylesheet notebook.

Thanks in advance!

  • $\begingroup$ No problems on 12.3.1 on windows 10. Screen shot of the PDF generated. !Mathematica graphics $\endgroup$
    – Nasser
    Aug 21, 2021 at 3:29
  • 1
    $\begingroup$ I seem to remember this coming up before….Not sure it was on this site though $\endgroup$
    – Michael E2
    Aug 21, 2021 at 19:38

1 Answer 1


Please read up the end: there are white borders with the default stylesheet, and I consider that as a bug in Export!

I don't get the gray borders with Mathematica 12.3.1 on Windows 10 x64:

grid4pdf = 
 Grid[{{"a", "b", "c"}, {"d", "e", "f"}, {"g", "h", "i"}}, 
  Background -> White]
Export["thepdfhasborders.pdf", grid4pdf] // SystemOpen


But there is something interesting that I noticed in the FrontEnd when I selected the Grid object in the output by the mouse. Notice how the FrontEnd draws the blue border around 3 of the 4 sides of the selection:


Since it is the FrontEnd who generates the exported PDF file, I suspect it may be related to the issue you observe. The following experiment supports this:

grid4pdf = 
  Grid[{{"█", "█", "█"}, {"█", "█", "█"}, {"█", "█", "█"}}, 
   Background -> Red];
Image[image = Rasterize[grid4pdf, Background -> Yellow], 
 Magnification -> 6]


Notice the yellow borders around 3 of the 4 sides in the rasterized version of the grid. In the PDF with the default stylesheet we get white borders:

Export["thepdfhasborders.pdf", grid4pdf] // SystemOpen


Since you mention that you use a custom stylesheet, I suspect that the gray color of the borders may be related to the Background setting in that stylesheet. If you have set your stylesheet as the default one by changing the global DefaultStyleDefinitions option, you can temporarily return it back using the method from this answer:

CurrentValue[$FrontEndSession, DefaultStyleDefinitions] = "Default.nb"
Export["thepdfhasborders.pdf", grid4pdf] // SystemOpen

Or you can try the method from this answer.

Another method is to export a Cell expression with explicit Background option:

  Cell[BoxData[ToBoxes[grid4pdf]], "Output", 
   Background -> White]] // SystemOpen

P.S. I consider the addition of the borders as a bug in Export since even explicit addition of the options CellFrameMargins -> 0, CellFrame -> False, ShowCellBracket -> False doesn't remove the borders. Please report it to the support.

  • $\begingroup$ Thank you so much Alexey! Changing the FrontEnd options via your first code snippet was an effective workaround for me. I've also reported to support as per your suggestion. Thanks again!! $\endgroup$
    – Jaffe42
    Aug 23, 2021 at 14:23
  • $\begingroup$ @Jaffe42 Glad to help. Thank you for reporting! $\endgroup$ Aug 23, 2021 at 17:21

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.