Add section between 2 pages

Hi,
I have a docx document that contains 3 pages. I want to add a section break between the page 2 and 3. I know how to do a split between each pages using your PageFinder Class, but I dont’t know if I can add a break after a specific page. I’m using Aspose Word 9.8 (net2.0).
Thanks for your help!
Steeve

Hi Steeve,

Thanks for your inquiry.

I think the easiest way would be to simply call SplitNodesAcrossPages with the parameter set to true. This will split all pages into separate sections. Depending on what you are trying to achieve you can then set the section page to start on a new page or insert a blank section after.

Please let us know if this is suitable for you.

Thanks,

Hi,
I try something (see below) and I would like to know if it exists a better solution:
I use the fonction SplitNodesAcrossPages (from the PageFinder class) to create section at the beginning of each page. After that, I use the following code to keep only 4 sections in my document:

for (int j = doc.Sections.Count - 2; j>= 3; j--)
{
    // Copy the content of the current section to the beginning of the last section.
    doc.LastSection.PrependContent(doc.Sections[j]);
    // Remove the copied section.
    doc.Sections[j].Remove();
}

Is it the best solution??
Thanks
Steeve

Hi Steeve,

Thanks for this additional information.

That technique seems fine to me, although I’m not entirely sure of what you are trying to achieve. It seems you are inserting a section break and then simply combining the sections again. If you are looking to have the content of each page contained within one section then you may want to use this code below.

for (int page = 1; page <doc.PageCount; page++)
{
    ArrayList sections = finder.RetrieveAllNodesOnPages(page, page, NodeType.Section);
    Section firstSection = (Section) sections[0];
    foreach(Section section in sections)
    {
        if (section != firstSection)
        {
            firstSection.AppendContent(section);
            section.Remove();

        }
    }
}

If we can help with anything else, please feel free to ask.

Thanks.