We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Replacing Section Breaks with Page Breaks


I have a document that is created by merging several documents and the resulting merged file is comprized of several sections which Section Breaks separates them. However, I need my resulting document to be made of only one section and instead of the Section Breaks have Page Breaks. So, I need to open the merged document in Aspose.Word and replace all Section Breaks with Page Breaks and save it back to server again. Could you please let me know how this can be done?


Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. Please try using the following code:

'Open document and create DocumentBuilder

Dim doc As Document = New Document("C:\Temp\in.doc")

Dim builder As DocumentBuilder = New DocumentBuilder(doc)

'Start loop and replace all section breaks with page breaks

While (Not doc.FirstSection.NextSibling Is Nothing)

'Get second section

Dim nextSect As Section = CType(doc.FirstSection.NextSibling, Section)

'Move DocumentBuilder cursor to the end of first section


'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)) Then


ElseIf (nextSect.PageSetup.SectionStart.Equals(SectionStart.Continuous)) Then

'Do nothing



End If

'Append content of second section to first section


'Remove next section


End While

'Save document


Hope this helps.

Best regards.

Thank you very much Alexey, your solution worked great. Thanks.