Unexpected formating using AppendDocument and KeepSourceFormatting

When I try to append the attached document (DocContent.aspx) to the other attached document (DocStart.aspx) using ImportFormatMode.KeepSourceFormating DocContent.aspx, which is the source document in this case, loses part of its header styling. Specifically the spacing between headings and sections is lost. This seems like incorrect behaviour to me.

Document docStart = new Document("DocStart.docx");
Document docContent = new Document("DocContent.docx");

ImportFormatMode mode = ImportFormatMode.KeepSourceFormatting;
docStart.AppendDocument(docContent, mode);

docStart.Save("DocResult.docx");

DocContent.docx (43.4 KB)

DocResult.docx (219.0 KB)

DocStart.docx (41.5 KB)

@M.Heinz The problem is caused by ParagraphFormat.NoSpaceBetweenParagraphsOfSameStyle option which is set in the heading paragraph in the source document. When using ImportFormatMode.KeepSourceFormatting both heading and content paragraphs have Normal style. So spacing is not added anymore.

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-27658

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.

@M.Heinz We have completed analysis of the issue and concluded it is not a bug. Aspose.Words behavior mimics MS Word behavior. If you would like to keep original documents formatting, you can try using Merger class and MergeFormatMode.KeepSourceLayout to merge the documents.

Document docStart = new Document(@"C:\Temp\DocStart.docx");
Document docContent = new Document(@"C:\Temp\DocContent.docx");

Document result = Merger.Merge(new Document[] { docStart, docContent }, MergeFormatMode.KeepSourceLayout);

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

Hi @alexey.noskov,
thanks for this hint; we’ll attempt to change our code to this standard and see if this works for us.

Kind regards.

1 Like

Hi,
up until now we have only used AppendDocument in our application. Is there something special to consider when changing to Merger.Merge?

@M.Heinz Internally, Merger.Merge also uses Document.AppendDocument method. But it also introduces MergeFormatMode.KeepSourceLayout mode that allows to keep original documents formatting upon merging.