There is a first document that ends with Section Break (Next Page) - AddedPageBreakIssueFirstSection.docx.
I am appending another document (that has one section and dummy content) on it - AddedPageBreakIssueSecondSection.docx .
After saving it, result document -03597d3f-3f79-473a-8c7f-25f72e85e849.docx has 2 Section Break (Next Page) that is not expected.
If I change in AddedPageBreakIssueFirstSection.docx Section Break (Next Page) to Section Break (Continuous) it is same wrong behavior. I tried all 3 ImportFormatModes. It is the same.
Code snippet :
public static void CreatedDocWithSectionBreak()
{
Aspose.Words.Document document = new Aspose.Words.Document("AddedPageBreakIssueFirstSection.docx");
Aspose.Words.Document secondSection = new Aspose.Words.Document("AddedPageBreakIssueSecondSection.docx");
document.AppendDocument(secondSection, ImportFormatMode.KeepSourceFormatting);
string documentPath = Guid.NewGuid() + ".docx";
document.Save(documentPath);
}
Hi Rastko,
Thanks for your inquiry. This is expected behavior. You can remove empty Section using the following code:
Aspose.Words.Document document = new Aspose.Words.Document(MyDir + "AddedPageBreakIssueFirstSection.docx");
Aspose.Words.Document secondSection = new Aspose.Words.Document(MyDir + "AddedPageBreakIssueSecondSection.docx");
document.AppendDocument(secondSection, ImportFormatMode.KeepSourceFormatting);
foreach (Section sec in document.Sections)
{
if (sec.ToString(SaveFormat.Text).Trim() == string.Empty)
{
sec.Remove();
}
}
document.Save(MyDir + @"16.6.0.docx");
Best regards,
Thank you Awais for your answer.
As it looks strange for me to add one additional break, how I can simulate this use case in Word ?
Thanks,
Rastko
Hi,
this works only in case if first document has Section Break (Next Page) at the end. Than after appending there are 2 Section Break (Next Page) . If you remove one as you suggested everything is as expected. From other hand if first document ends with Section Break (Continuous) than that does not works. After appending there will be Continuous and than Next Page section break. Your logic will remove Continuous section break and Next Page remains. I expect to have Continuous in final document only.
Thanks,
Hi Rastko,
Thanks for your inquiry. You can check the value whether it is NewPage or Continuous using the following code and then apply your logic depending on this value:
SectionStart obj = document.LastSection.PageSetup.SectionStart;
Best regards,
Thank you Awais for suggestions