# Export large text on multiple pages to PDF

I have a large set of text that I would like to export as pdf on multiple pages and with page margins – e.g. typical A4 page. When I export the text, a single pdf file without any page margins is created. How do I get multiple pages with page margins? The text itself is a column, maybe imagine a long list of business cards.

I should have provided and example. Here it is – assume I want to export this text on probably 2-3 pages:

font = FontFamily -> "Times";
ex = TextGrid[{{Style["Hello", FontFamily -> font, Bold]}, {Style[
"World (the one with humans on it. Solar System in the Milky \
Way and the so far only known Universe, although it might actually be \
a Multiverse)", FontFamily -> font]}, {Style["Just Testing",
Darker@Gray, FontFamily -> font]}}, Alignment -> Left];
Table[ex, 20];
Column@%


The text, of course, is not 20 times the same, but pulled from a database and different in each paragraph.

• – george2079 Oct 24 '16 at 16:10

borrowing the code from: https://mathematica.stackexchange.com/a/31783/2079 with:

text = ExampleData[{"Text", "DeclarationOfIndependence"}];
myList = Column /@
Partition[
StringJoin /@ Partition[Characters[text], 80, 80, {1, 1}, " "],
60, 60, {1, 1}, ""];


Edit, the Grid example:

font = FontFamily -> "Times";
ex = Grid[{{Style["Hello", FontFamily -> font, Bold]}, {Style[
"World (the one with humans on it. Solar System in the Milky \
Way and the so far only known Universe, although it might actually be \
a Multiverse)", FontFamily -> font]}, {Style["Just Testing",
Darker@Gray, FontFamily -> font]}}, Alignment -> Left,Frame->All];
myList = Table[ex, {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];
GraphicsRow[Import["mylist.pdf"][[1 ;; 3]], ImageSize -> 500,
Frame -> All]


each page looks like this:

I'm not sure what controls the word wrap here, or why we got got a reverse indent.

• I should have made an example – now added above. I can't get this to work with your solution. I thought there might be some simple export option such as ".doc" (Export["exp.doc",text]), but it seems there isn't. – Mockup Dungeon Oct 24 '16 at 19:19
• I don't have TextGrid (new in 10.3), but did you try simply myList=Table[ex,{n}] ? – george2079 Oct 24 '16 at 19:46
• You could also use just Grid, no difference, except for the correct line breaks. I'm not sure what you mean, as I want to export the list and don't see how this can be done with your suggestion. I'd like to have the result on simply regular pages, like you get in any word processor program. – Mockup Dungeon Oct 24 '16 at 20:50
• added the Grid example. The hard part of this will be to figure how much text goes on each page. – george2079 Oct 24 '16 at 21:51
• Thanks for this. While playing around a little more, I found that I can produce this result, then right click on the output cell, select Save Selection, save as pdf – and get all nicely on pages. So, Mathematica seems to be capable of doing it. Now if it were possible to write code to save the output Cell as a pdf that should possibly easily solve this. I just don't know how to save an output cell as pdf. Do you maybe? – Mockup Dungeon Oct 25 '16 at 14:38