In order to save computation results, I want to programmatically create some MMA notebooks and export them as PDF files.
It works fine for text:
MakeNotebook[] :=
Module[{nb, nbobj}, nb = NotebookCreate[];
NotebookWrite[nb,Cell["A Dynamically Created Notebook", "Title"]];
NotebookWrite[nb, Cell["The date is " <> DateString[], "Text"]];
nbobj = NotebookGet[nb];
NotebookClose[nb];
nbobj]
nb = MakeNotebook[];
Export["~/Temp/test.pdf", nb]
But I had some problems for graphics:
MakeNotebook[] :=
Module[{nb, nbobj}, nb = NotebookCreate[];
NotebookWrite[nb,Cell["A Dynamically Created Notebook", "Title"]];
NotebookWrite[nb, Plot[Sin[x], {x, -2, 2}]]; (* <- not OK *)
NotebookWrite[nb, Cell["The date is " <> DateString[], "Text"]];
nbobj = NotebookGet[nb];
NotebookClose[nb];
nbobj]
does not work as you get Graphics[{{{{}, {}, Annotation[{...
in your PDF instead of your plot.
So my question is: how to include graphics?