I know that I exported Graphs to PDFs before but it doesn't seem to work any more. I tried

K5 = GraphData[{"Complete", 5}]
Export["K5.PDF", K5]

And I get a PDF with a grey rectangle in it. Even exporting to TIFF doesn't seem to work. When I right click the Graph object I can do a "Convert to Graphics". Then exporting this converted Graph to PDF works.

Why doesn't it work directly? If it's not possible ... How can I convert a Graph to Graphics programatically before calling a export to PDF?

I'm using Mathematica 9.0.0 on Windows 7 x64

UPDATE: Problem solved by Szabolcs I checked if dynamic evaluation was checked and it was. However when I restarted Mathematica it did work as expected. I realize with hindsight that this morning going through some help files a warning was issued about dynamic evaluation. I didn't really pay attention to it but probably it got disabled automatically but did not show that change in the evaluation menu option. Also Show[] is nice to know that it effectively converts the Graph to a non dynamic graphics object!

  • $\begingroup$ Which version of Mathematica are you using, and on which operating system? $\endgroup$ – Szabolcs Feb 28 '13 at 15:17
  • $\begingroup$ Try upgrading to 9.0.1 and see if that fixes the problem. $\endgroup$ – Szabolcs Feb 28 '13 at 15:40
  • $\begingroup$ @Szabolcs I updates the question. Thx for the help. Something to keep in mind about this dynamic evaluation! $\endgroup$ – Lou Feb 28 '13 at 15:54

I cannot reproduce this behaviour (it does export correctly here, Mathematica 9.0.1, OS X). But the grey box typically appears when dynamic updating is disabled (check Evaluation -> Dynamic Updating Enabled). Note that graphs are dynamic objects and if you uncheck this menu item, they'll display as grey boxes inside the notebook.

Now why it would happen that inside the notebook you do see the graph, but when you export it turns into a grey rectangle, I do not know. But if you wrap the graph in Show, it'll be converted into a non-dynamic Graphics object, and you should be able to export it (until you figure out why the direct way doesn't work):

Export["K5.pdf", Show[K5]]
| improve this answer | |

I did not get the same behavior either. An alternative to Export would be right click the output cell, and then Save selection as. You may save it as a pdf file or many other formats. The pdf file is different from the exported one. (BTW, when you have overlapping regions with different colors, the exported pdf file don't have the corret behavior, but the saved one do.)

In this way, you get a file with a graph including the text Out[ ]=.To get rid of this, you may paste the resluting graph into a new cell, and then do the above steps.

| improve this answer | |
  • $\begingroup$ Thx I tried doing that (with the right click export as pdf) but that didn't work either. That's why I posted the question. This right click is not an option since I need hundreds of graphs exported and I'm to lazy ;) $\endgroup$ – Lou Feb 28 '13 at 15:57
ToExpression@ToBoxes@K5 // Head
(* Graphics *)
| improve this answer | |
  • $\begingroup$ Show is an easier way to achieve the same, but this should simply not be necessary anyway. $\endgroup$ – Szabolcs Feb 28 '13 at 15:15
  • $\begingroup$ @Szabolcs Yea. Exports fine for me too without converting to Graphics first. $\endgroup$ – ssch Feb 28 '13 at 15:24

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.