Importing a node with NodeImporter using the ImportFormatMode.KeepSourceFormatting causes wrong text font names and font sizes.
Sample code:
var destDocNames = new List<string> { "destination_fontSize.docx", "destination_fontName.docx" };
using (FileStream fileStreamSource = File.OpenRead(Server.MapPath("/File") + "\\source.docx"))
{
var docSource = new Document(fileStreamSource);
var section = docSource.Sections[0];
foreach (var name in destDocNames)
{
using (FileStream fileStreamDest = File.OpenRead(Server.MapPath("/File") + "\\" + name))
{
var docDest = new Document(fileStreamDest);
var nodeImporter = new NodeImporter(docSource, docDest, ImportFormatMode.KeepSourceFormatting, new ImportFormatOptions { KeepSourceNumbering = true });
var importedSection = (Section)nodeImporter.ImportNode(section, true);
var docDestLastSection = docDest.LastSection;
var importedSectionNodes = importedSection.Body.ChildNodes.ToArray();
foreach (var childNode in importedSectionNodes)
{
docDestLastSection.Body.ChildNodes.Add(childNode);
}
docDest.Save(Server.MapPath("/File") + "\\output_" + name);
};
}
};
For the “output_destination_fontSize.docx” document:
Expected: the “Text3” has a font size of 11, just like the “destination_fontSize.docx”.
Actual: the “Text3” has a font size of 10
For the “output_destination_fontName.docx” document:
Expected: the “Text2”, “Text3” and “Text4” all have Calibri font, just like “destination_fontName.docx”
Actual: the “Text2”, “Text3” and “Text4” all have Times New Roman font.
Changing the ImportFormatMode to UseDestinationStyles or KeepDifferentStyles does not reproduce these issues, but we need to use the KeepSourceFormatting option.
I have attached the WebApp reproducing these issue.
WebApp.zip (38.2 KB)