# Export Grid object to pdf without border?

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.

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

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]
BorderDimensions[image]


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"
FrontEndTokenExecute["ToggleShowExpression"]
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:

Export["thepdfhasborders.pdf",
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.

• 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!! Aug 23, 2021 at 14:23
• @Jaffe42 Glad to help. Thank you for reporting! Aug 23, 2021 at 17:21