How Can I Insert a Page Break Programmatically?

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

Please see PageBreakBelow and PageBreakAbove.

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.

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 -> ""]];

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