@NIKHIL.AGGARWAL30.OPTUM.COM Actually there are several problems upon merging the document. The main is that table in the Attachment4.docx
is broken upon import.
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): WORDSNET-24929
You can obtain Paid Support services if you need support on a priority basis, along with the direct access to our Paid Support management team.
The second issue, your documents were created using different version of MS Word and as a result have different set of compatibility options. When you concatenate the documents compatibility options of the main document are applied and the content is reflowed appropriately. This might lead to difference in layout of the appended documents.
The third issue is that some of your documents does not have headers/footers, but they are inherited form the previously appended documents. You can avoid this using HeadersFooters.LinkToPrevious
method. But in this case an empty headers/footers are added to the section that also might push the content down. You can reset size of empty paragraphs in headers/footers to avoid this:
string[] docs = new string[] {
@"C:\Temp\Attachment1.docx",
@"C:\Temp\Attachment2.docx",
@"C:\Temp\Attachment3.docx",
@"C:\Temp\Attachment4.docx",
@"C:\Temp\Attachment5.docx"
};
Document result = null;
foreach (string path in docs)
{
Document doc = new Document(path);
doc.FirstSection.PageSetup.SectionStart = SectionStart.NewPage;
doc.FirstSection.HeadersFooters.LinkToPrevious(false);
if (result == null)
result = doc;
else
result.AppendDocument(doc, ImportFormatMode.KeepSourceFormatting);
}
// Reset size of empty headers/footers.
NodeCollection headersFooters = result.GetChildNodes(NodeType.HeaderFooter, true);
foreach (HeaderFooter hf in headersFooters)
{
if (string.IsNullOrEmpty(hf.ToString(SaveFormat.Text).Trim()))
hf.FirstParagraph.ParagraphBreakFont.Size = 0;
}
result.Save(@"C:\Temp\out.docx");