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 have a list, myList, of let's say 20 (different) objects

myList = Table["object", {20}]

I know would like to export every single element of myList to its own PDF page in a 20-paged PDF document; i.e., myList[[1]] comes on page 1, ..., myList[[20]] comes on page 20.

Is this possible in Mathematica? I have heard of the Export function, of course, but have not seen any way of combining 20 exports in one single document.

share|improve this question
    
I'd do this in LaTeX: Export["myList.txt", myList // TeXForm] and then \input{mylist.txt} in a minimal latex document where you can ask latex to control page breaks etc. –  gpap Sep 6 '13 at 15:10
    
@gpap: Interesting option as well. Can you please elaborate what the options are in LaTeX? One would use the Verbatim or how is possible to change all "{" and "}" of myList to page breaks? –  Gabriel Sep 6 '13 at 15:19
    
TexForm does that. I would use longtable.sty or force bage breaks within latex but seeing as you know exactly where the page breaks need to be Table[Export["page" <> ToString@i <> ".txt", TeXForm@myList[[i]]], {i, Length@myList}] will export page1.txt, ..., page20.txt. Then you can add these on your tex document using \input{page1.txt}...\input{page20.txt}. Writing this 20 times may be a bit cumbersome but you can actually make mathematica produce the needed code StringJoin @@ Table["\\" <> "input{page" <> ToString@i <> ".txt}\n" <> "\\" <> "newpage", {i, Length@myList}] –  gpap Sep 6 '13 at 16:39

2 Answers 2

up vote 3 down vote accepted

Vitally has the same idea, but I thought it would be a hassle to do it manually like that, so let MMA insert the page breaks:

myList = Array["object", {20}];
Table[CellPrint[{i, 
   Cell["", "PageBreak", PageBreakBelow -> True]}], {i, myList}]

Edit: In response to the comment,

Here we create a new notebook and set the page headers to none. Then we Paste your objects and NotebookWrite page breaks. Finally, we Export the notebook and clean up.

myList = Array["object", {20}];
report = CreateDocument[Null, 
   PageHeaders -> {{None, None, None}, {None, None, None}}];
Do[
   Paste[report, i];
   NotebookWrite[report,Cell["", "PageBreak", PageBreakBelow -> True]];
, {i, myList}]
Export["myList.pdf", report];
NotebookClose[report];
Clear[report];
share|improve this answer
    
Thanks both Vitaly and Timothy. The problem with this approach, is that when "Printing as PDF", the name of the document is at the top of each page, and I prefer a way without this. Also, would there be a "Export["nameOfDocument.pdf,%]" way of doing this? Thanks again! –  Gabriel Sep 6 '13 at 15:14
    
Thank you for the update, Timothy. One question, though: why the use of Paste? Why doesn't "NotebookWrite[ report, Cell[ i ]]" work? Thanks for all help! –  Gabriel Sep 7 '13 at 5:09
    
Why is it, when I change the Do[ ] part in your code above by Do[ ( NotebookWrite[report, { Cell[i], Cell[Paste[report, Column@myList[[i]]]], Cell["dd", "PageBreak", PageBreakBelow -> True] }]; ) , {i, Length[myList]}] that Mathematica output "Null" on every page? Thank you for all help! –  Gabriel Sep 7 '13 at 5:44
    
We get a clue by looking at the order of printed cells in the new notebook. The contents of Paste are printed first which means that Paste is executed first. Then Paste returns Null (i.e. the contents of Cell[Paste[...]] become Cell[Null]). Then the NotebookWrite writes the Cell[Null]. As for why Paste instead of NotebookWrite... I don't know, the documentation says Paste does some evaluation on its contents, but NotebookWrite says it is essentially the same as Paste. –  Timothy Wofford Sep 7 '13 at 9:43

For a few objects on the page a manual approach is

Top Menu >> Insert >> Page Break

And then to make sure (on Mac):

Top Menu >> File >> Print >> PDF >> Open PDF in Preview

enter image description here

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.