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

Free Support Forum - aspose.com

Remove Empty Page

Hi,

What is the easiest way to remove the empty page in the attached document? It is also the only page in it’s section.

Is there a way to remove it with out looping, as we may have to clean a potentially large document.

Thanks Bruce

Hi

Thanks for your request. Word document is flow document and does not contain any information about its layout into lines and pages. Therefore, technically there is no “Page” concept in Word document.

But I think in your case you can just set SectionStart.Continuous for all sections in your document, please see the following code:

Document doc = new Document("C:\\Temp\\Top+Page.docx");

foreach (Section section in doc.Sections)

section.PageSetup.SectionStart = SectionStart.Continuous;

doc.Save("C:\\Temp\\out.docx");

Hope this helps.

Best regards,

Hi,

This solution does not work as our sections need to start on new pages. In the case of the attached document we have 3 sections, each one needs to start on a new page. Sometimes we have a section that has no content in which case we need it removed.

forgetting “pages” can I just remove empty sections?

Hi Bruce,

Thanks for your request. Yes, of course, you can remove empty sections using Aspose.Words. Please see the following code:

//Open document

Document doc = new Document(@"Test087\in.doc");

//Search for empty sections

ArrayList sectList = new ArrayList();

foreach(Section sect in doc.Sections)

{

if(sect.Body.FirstParagraph.IsEndOfSection &&string.IsNullOrEmpty(sect.Body.FirstParagraph.ToTxt().Trim()))

{

sectList.Add(sect);

}

}

//remove empty sections

foreach (Section sect in sectList)

{

sect.Remove();

}

//Save output document

doc.Save(@"Test087\out.doc");