Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

It's the end of the semester and I have a prof who wants me to turn in a printout of the nb files ive worked on. I have 33 separate files, and I was wondering if there was any easy way I could combine all of these files in batch to another nb or a document format to print out (pdf/rtf/doc/html anything really). Nothing fancy needs to happen here, basically i just need to make this into a printable file and preserve any plots i've made, and I wanted to have it all in a single file so that it's all contained to just that file. The data in these files is very simple, mainly just evaluating a problem using mathematica instead of by hand. There are no dependencies between any of the files to each other or any external libraries.

share|improve this question
You could merge NBs in Mathematica programly (please refer to this tutorial), or print them out separately and merge the PDFs by using some external tools. – Silvia Jun 12 '13 at 9:09
The smart Prof should have made this the final assignment for you...! (Or - perhaps he did...) – cormullion Jun 12 '13 at 9:11

Here's an idea to get you started. I would prefer to export each notebook to a separate PDF file, then combine them.

notebookfiles = FileNames["/Users/me/test-dir/*.nb"]
openednotebooks = NotebookOpen[StringJoin[Directory[], "/", #],
    Visible -> False] & /@ notebookfiles
MapThread[NotebookPrint[#1, StringJoin[#2, ".pdf"]] &,
 {openednotebooks, notebookfiles}]
NotebookClose[#] & /@ openednotebooks

Then combine the PDF files using operating system tools. For example, on OS X, you open the first PDF file in Preview, drag and drop the other PDF files into the thumbnails drawer, then re-order and export the resulting assembly to a new file.

As with all such batch operations, testing is recommended before you commit yourself...

share|improve this answer

This code should do the work:

directory="Your Notebooks directory";

outputNB = 
  CreateDocument[{}, ShowPageBreaks -> True, 
   WindowTitle -> "Your submision"];

  nb = NotebookOpen[ToFileName[directory, fname]];
  SelectionMove[nb, All, Notebook];
  NotebookWrite[outputNB, NotebookRead /@ SelectedCells[nb]];
  SelectionMove[outputNB, After, Notebook];
  SelectionMove[outputNB, Previous, Cell];
  SetOptions[NotebookSelection[outputNB], PageBreakBelow -> True];
  , {fname, fnames}
share|improve this answer

Your Answer


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.