Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Batch save mode?

4 views
Skip to first unread message

Erik Max Francis

unread,
Nov 21, 2009, 3:36:31 AM11/21/09
to
I'm going to be away from my copy of Mathematica for a while and may
potentially want to show the work I've been doing for some friends. I
have several dozen notebooks and don't really want to save them all
manually; is there an easy way to get Mathematica to batch load
notebooks and save them as PDF?

Thanks.

--
Erik Max Francis && m...@alcyone.com && http://www.alcyone.com/max/
San Jose, CA, USA && 37 18 N 121 57 W && AIM/Y!M/Skype erikmaxfrancis
What is now prov'd was once only imagin'd.
-- William Blake

David Reiss

unread,
Nov 22, 2009, 6:08:45 AM11/22/09
to
The only hitch concerning the function that I just posted to do this
is that if the notebooks have any dynamic content---and if you have
not authorized Mathematica to open dynamic content from the directory
without verification--then you will have to respond to the permissions
popup each time such a notebook opens.


--David


On Nov 21, 3:36 am, Erik Max Francis <m...@alcyone.com> wrote:
> I'm going to be away from my copy of Mathematica for a while and may
> potentially want to show the work I've been doing for some friends. I
> have several dozen notebooks and don't really want to save them all
> manually; is there an easy way to get Mathematica to batch load
> notebooks and save them as PDF?
>
> Thanks.
>
> --

> Erik Max Francis && m...@alcyone.com &&http://www.alcyone.com/max/

David Annetts

unread,
Nov 22, 2009, 6:09:52 AM11/22/09
to
Hi Erik,

> I'm going to be away from my copy of Mathematica for a while
> and may potentially want to show the work I've been doing for
> some friends. I have several dozen notebooks and don't
> really want to save them all manually; is there an easy way
> to get Mathematica to batch load notebooks and save them as PDF?

There is FileNames[], StringReplace[], NotebookOpen[], Export[] &
SetDirectory[] ....

In a fresh notebook, have you tried something like

SetDirectory["directory where my notebooks live"];
ifile = FileNames["*.nb"];
ofile = StringReplace[#, {"nb"->"PDF"}]& /@ ifile;
(
inb = NotebookOpen[ifile[[#]]];
Export[ofile[[#]], inb]
)& /@ Range@Length@ifile;

YMMV depending on exactly what you want to do before saving the notebooks.

Regards,

Dave.


David Reiss

unread,
Nov 22, 2009, 6:15:41 AM11/22/09
to
Give this a try:

It opens up all the notebooks in the source directory and saves them
as pdfs in the target directory. the two directories can be the same.

David
http://scientificarts.com/worklife

ClearAll[SaveAsPDFs];

SaveAsPDFs[sourcedir_String, targetdir_String] :=

Module[{notebooks, nbs, pdfNames, pdfFiles, data, pdfs},

notebooks = FileNames[{"*.nb"}, {sourcedir}];

pdfNames = # <> ".pdf" & /@ (FileBaseName /@ notebooks);

pdfFiles = ToFileName[targetdir, #] & /@ pdfNames;

nbs = NotebookOpen /@ notebooks;

(
SelectionMove[#, All, Notebook];
FrontEndExecute[FrontEndToken[#, "SelectionOpenAllGroups"]]
) & /@ nbs;

data = Transpose[{pdfFiles, nbs}];

pdfs = Export[#[[1]], #[[2]], "PDF"] & /@ data;

NotebookClose /@ nbs;

pdfs

]


On Nov 21, 3:36 am, Erik Max Francis <m...@alcyone.com> wrote:

> I'm going to be away from my copy of Mathematica for a while and may
> potentially want to show the work I've been doing for some friends. I
> have several dozen notebooks and don't really want to save them all
> manually; is there an easy way to get Mathematica to batch load
> notebooks and save them as PDF?
>
> Thanks.
>
> --

> Erik Max Francis && m...@alcyone.com &&http://www.alcyone.com/max/

Erik Max Francis

unread,
Nov 25, 2009, 2:32:35 AM11/25/09
to
David Reiss wrote:
> Give this a try:
>
> It opens up all the notebooks in the source directory and saves them
> as pdfs in the target directory. the two directories can be the same.

Thanks to both Davids for their replies :-).

--
Erik Max Francis && m...@alcyone.com && http://www.alcyone.com/max/


San Jose, CA, USA && 37 18 N 121 57 W && AIM/Y!M/Skype erikmaxfrancis

Nine worlds I remember.
-- Icelandic Edda of Snorri Sturluson

0 new messages