Hi,
We have a word document with section breaks. All we need to do is replace all the section break with page break. Can you please assist?
Thank you.
Hi,
We have a word document with section breaks. All we need to do is replace all the section break with page break. Can you please assist?
Thank you.
Hi,
Can you please respond?
Hi Komal,
Document doc = new Document(MyDir + "in.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
while (doc.FirstSection.NextSibling != null)
{
//Get second section
Section nextSect = (Section)doc.FirstSection.NextSibling;
//Move DocumentBuilder cursor to the end of first section
builder.MoveTo(doc.FirstSection.Body.LastParagraph);
//if SectionStart of second section is NewPage, EvenPage or OddPage
//we should replace such break with page break
//If SectionStart is Continouse then just appent content of next section to first section
//If SectionStart is NewColumn then replace it with Column break
if (nextSect.PageSetup.SectionStart.Equals(SectionStart.NewColumn))
builder.InsertBreak(BreakType.ColumnBreak);
else if (nextSect.PageSetup.SectionStart.Equals(SectionStart.Continuous))
{
//do nothing
}
else
builder.InsertBreak(BreakType.PageBreak);
//Append content of second section to first section
doc.FirstSection.AppendContent(nextSect);
//Remove next section
nextSect.Remove();
}
//Save document
doc.Save(MyDir + "out.docx");
Thanks. I'll try this but looks like I missed this on my initial post.
Our Document has page break added in all the places except ONE place. Only one place in the document will have a section break. We need to find that place and replace the section break with page break.
I am not sure whether the above code will work for this. However I'll try once.
Alos why do we need to add BreakType.ColumnBreak? our doument does not need that. All we need is replace that ONE section break to page break.
Hi Komal,