Alex Rivera | Logout

Create page break using OpenXml

Asked 2010-05-08T19:20:28.893
39

I use OpenXml to create Word document with simple text and some tables under this text. How can I force Paragraph with this text to show always on new page? Maybe this paragraph should be some Header but I'm not sure how to do this.

Thanks

Edit
Report

1 Answer

16

The PageBreakBefore property accomplishes this. It will insert a page break before your paragraph if Word didn't insert one automatically.

if (myParagraph.ParagraphProperties== null) 
{ 
    myParagraph.ParagraphProperties = new ParagraphProperties();
}

myParagraph.ParagraphProperties.PageBreakBefore = new PageBreakBefore();

I believe it looks something like this in Open XML:

  <w:p>
    <w:pPr>
      ...
      <w:pageBreakBefore/>   
      ...
    </w:pPr>
    ...    
  </w:p>
answered 2011-09-29T23:25:14.037

Your Answer