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

Free Support Forum - aspose.com

AppendDocument without continuous section brakes

Hi,

We use Aspose.Words 6.0.1.

We use the function AppendDocument in our application now the document it creates contains a continous section brake for each document we attached with the AppendDocument function.

Is it possible to combine the two documents without inserting a continous section break? This because the section breaks cause problems with the headers and footers.

Thanx in advance.

Patrick

Hi Patrick,

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

Thanks for your inquiry. I think you can just SectionStart of the first section of the document before appending it to another document. Please see the following code:

Document masterDoc = new Document(@"master.doc");

Document SubDoc = new Document(@"sub.doc");

SubDoc.FirstSection.PageSetup.SectionStart = SectionStart.NewPage;

masterDoc.AppendDocument(SubDoc, ImportFormatMode.UseDestinationStyles);

masterDoc.Save(@"Out.doc");

Hope this helps. Please let me know if you need more assistance, I will be glad to help you.

Best regards.

Hi Alexey,

Unfortunately that didn't solve my problem. The section breaks (regardless the type) are causing problems with the headers/footers.

Oke I found a bit of code to remove all continous section breaks. Now I'm only left with Section breakes of the type NewPage.

Is there any way to replace the section breakes of the Type NewPage with hard PageBreaks (ControlChar.PageBreakChar)?

This is the code I use to remove the section breakes:

public void RemoveContinuousSectionBreak(ref Document docPrequal)
{
ArrayList list = new ArrayList();
Section firstSection = docPrequal.FirstSection;
foreach (Section section in docPrequal.Sections)
{
if (section.PageSetup.SectionStart == SectionStart.Continuous && section != firstSection)
{
list.Add(section);
firstSection.AppendContent(section);
}
else if (section.PageSetup.SectionStart == SectionStart.NewPage && section != firstSection)
{
// HERE THE CODE IS NEEDED TO REPLACE SectionStart.NewPage with ControlChar.PageBreakChar
}
else
{
firstSection = section;
}
}

foreach (Section section in list)
{
docPrequal.RemoveChild(section);
}
}

Thanks

Hi

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

Thanks for your inquiry. I modified your code:

public void RemoveContinuousSectionBreak(ref Document docPrequal)

{

// Create a paragraph with page break.

// We will insert thsi paragraph ad the end of section and then append content of the next section ot the current.

Paragraph breakParagraph = new Paragraph(docPrequal);

breakParagraph.AppendChild(new Run(docPrequal, ControlChar.PageBreak));

breakParagraph.ParagraphBreakFont.Size = 1;

breakParagraph.ParagraphFormat.SpaceAfter = 0;

breakParagraph.ParagraphFormat.SpaceBefore = 0;

ArrayList list = new ArrayList();

Section firstSection = docPrequal.FirstSection;

foreach (Section section in docPrequal.Sections)

{

if (section.PageSetup.SectionStart == SectionStart.Continuous && section != firstSection)

{

list.Add(section);

firstSection.AppendContent(section);

}

else if (section.PageSetup.SectionStart == SectionStart.NewPage && section != firstSection)

{

// Append paragraph with page break.

firstSection.Body.AppendChild(breakParagraph.Clone(true));

list.Add(section);

firstSection.AppendContent(section);

}

else

{

firstSection = section;

}

}

foreach (Section section in list)

{

docPrequal.RemoveChild(section);

}

}

Hope this helps.

Best regards.

Hi Alexey,

Thanks this worked like a charm!

Patrick