Message Boards Message Boards

How Can I Insert a Page Break Programmatically?

Posted 9 years ago

Hi Everyone,

I have a small script that computes some results and then spits out a section cell, a subsection cell followed by an output table, and another subsection cell followed by a second output table. What statements to I need to include in my script to insert a page break before each subsection? Regards, Gregory

POSTED BY: Gregory Lypny
4 Replies

Will the following help by inserting a PageBreak Cell as one would manual with insert menu:

nb = CreateDocument[];
    NotebookWrite[nb, Cell["A Heading", "Section"]];
 NotebookWrite[nb, 
     Cell["", "PageBreak", PageBreakBelow -> True]];
    NotebookWrite[nb, Cell["New content", "Subsection"]];
    NotebookWrite[nb, 
      Cell[BoxData[
        TagBox[GridBox[{{"\<\"Column 1\"\>", "\<\"Column 2\"\>"}, {"True",
             "False"}}, AutoDelete -> False, 
          GridBoxBackground -> {"Columns" -> {{None}}, 
            "Rows" -> {RGBColor[0.88, 1, 0.88], RGBColor[1, 0.85, 0.85]}},
           GridBoxFrame -> {"Columns" -> {{True}}, "Rows" -> {{True}}}, 
          GridBoxItemSize -> {"Columns" -> {{Automatic}}, 
            "Rows" -> {{Automatic}}}], "Grid"]], "Output", 
       ImageSize -> {224, 38}, ImageMargins -> {{0, 0}, {0, 0}}, 
       ImageRegion -> {{0, 1}, {0, 1}}, CellLabel -> ""]];
    NotebookWrite[nb, Cell["", "PageBreak", PageBreakBelow -> True]];
    NotebookWrite[nb, Cell["New content", "Subsection"]];
    NotebookWrite[nb, 
      Cell[BoxData[
        TagBox[GridBox[{{"\<\"Column 1\"\>", "\<\"Column 2\"\>"}, {"True",
             "False"}}, AutoDelete -> False, 
          GridBoxBackground -> {"Columns" -> {{None}}, 
            "Rows" -> {RGBColor[0.88, 1, 0.88], RGBColor[1, 0.85, 0.85]}},
           GridBoxFrame -> {"Columns" -> {{True}}, "Rows" -> {{True}}}, 
          GridBoxItemSize -> {"Columns" -> {{Automatic}}, 
            "Rows" -> {{Automatic}}}], "Grid"]], "Output", 
       ImageSize -> {224, 38}, ImageMargins -> {{0, 0}, {0, 0}}, 
       ImageRegion -> {{0, 1}, {0, 1}}, CellLabel -> ""]];

Manual Page Break

POSTED BY: Hans Michel

Please see PageBreakBelow and PageBreakAbove.

POSTED BY: Vitaliy Kaurov
Posted 9 years ago

Hello Vitally,

Thank you for responding. The examples for PageBreakBelow and PageBreakAbove appear to set the page breaks for all cells of a given type for an entire newly-created notebook. I just want to set breaks for two particular cells.

POSTED BY: Gregory Lypny
Posted 9 years ago

Hi Hans,

Thanks for the tip. Works like a charm! I also later discovered that

CellPrint[Cell["", "PageBreak"]]

works too when you want the breaks inserted into the same notebook in which you are working.

Regards,

Gregory

POSTED BY: Gregory Lypny
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract