Getting ahold of Breaks


Is there a way to get ahold of a break that already exists in a paragraph? Let me explain what I need to do so you can understand what I mean by 'get ahold'.

I have a document that has Page Breaks and Section Breaks in it. However during the dynamic generation of the final output document sometimes there will be a page break, followed by whitespace and then a section break new page. I've figured out how to find these situations my question is. How (if I can) do I get ahold of the page break and change it to a section break new page? Or how do I (if I can) change the section break new page into a section break countinous?

Let me know if I'm not making myself clear.




There is no simple way of doing what you want. Try the following code. It is a bit complicated but seems to work correctly in my test. If you have problems with this code or questions on how it works please don't hesitate to ask.

Document doc = new Document(filename);

DocumentBuilder builder = new DocumentBuilder(doc);

foreach(Run run in doc.GetChildNodes(NodeType.Run, true)) {

string[] ss = run.Text.Split('\x000c', '\f');

if(ss.Length==1) { //no pagebreaks found in this run


else if(ss.Length==2) { // one page break found in the run

run.Text = ss[0];

if(ss[1]=="") { //page break is in the end of the run

// move builder position to the end of parent paragraph


// insert section break

// use BreakType.SectionBreakContinuous if necessary



else {

Run subrun = (Run)run.Clone(false);

subrun.Text = ss[1];






else {

// if there can be more than one pagebreak in the run

// then we need to write handling procedure here

// it is complex so I shall not write it yet

// unless it is really necessary




If you want to change existing section break to section break continuous, use Section.PageSetup.SectionStart property.


Awesome! Thanks for the quick example... I'll be able to do the rest from here!

Again thanks,