Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I would like to export a Grid object to a .pdf document (preferably as part of a notebook). Here's an example:

data = Notebook[
   {Cell[
     BoxData[
      ToBoxes[
       Grid[
        {
         {11, 22},
         {33, 44}
         },
        Frame -> All,
        FrameStyle -> Directive[Thickness[.1], Orange]
        ](* end of Grid *)
       ]
      ]
     ](* end of Cell *)
    }];

Export[NotebookDirectory[] <> "grid.pdf", data];
SystemOpen[NotebookDirectory[] <> "grid.pdf"];

However, setting thickness of a grid in FrameStyle has little to do with the outcoming table (only the upper line is ok).

I've encountered a similar problem concerning Dividers here:

How to fix a PDF line rendering problem in V9

They say it's a bug appearing in MMA9 only (MMA8 is free of this problem. Sadly, it's not the version I get to use). Possible solution would be to export a Notebook to .eps first, and then convert it to .pdf, which works for simple examples, however there are two reasons I can't use it.

First - as I try to export my Notebook to .eps, Mathematica crashes and quits to Windows (i use XP 32bit SP3). Secondly - I'd very much appreciate, if using programs other than MMA could be avoided.

Is there another way of exporting a Notebook to .pdf? Or meybe there's some unknown global option which can prevent aliasing? I will be grateful for any help.

PS The thickness is broken only in .pdf - the notebook looks ok.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Rasterizing is a possibility:

data = Notebook[{Cell[
     BoxData[ToBoxes[
       Rasterize[
        Grid[{{11, 22}, {33, 44}}, Frame -> All, 
         FrameStyle -> Directive[AbsoluteThickness[1], Orange]], 
        ImageResolution -> 400](*end of Grid*)]]](*end of Cell*)}];

Export[FileNameJoin[{$TemporaryDirectory, "grid.pdf"}], data];
    SystemOpen[FileNameJoin[{$TemporaryDirectory, "grid.pdf"}]];

Of course, you don't get scalable graphics this way. It might be a pain if there are several Grids that need rasterizing. Here it is blown up several times:

Import[FileNameJoin[{$TemporaryDirectory, "grid.pdf"}], "Images"]

Mathematica graphics

Edit: Here's an automatic way to convert any Grid that contains a thickness directive. It works in V9.0.1, but the box structure may change in future. (The problem seems to be fixed in V10, in any case.)

rasterizeThickness = 
  box : TagBox[_, "Grid"] /; ! FreeQ[box, Thickness | AbsoluteThickness] :> 
   ToBoxes[Rasterize[ToExpression[box, StandardForm], ImageResolution -> 400]];

Export[FileNameJoin[{$TemporaryDirectory, "grid.pdf"}], data /. rasterizeThickness];
    SystemOpen[FileNameJoin[{$TemporaryDirectory, "grid.pdf"}]];
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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