Hello,
Thanks for your inquiry.
Please try the following code to make the font of the merged document consistent with the basic document.
- Code: Select all
Document bs = new Document("base.docx");
Document dy = new Document("dynamic.docx");
TextRange bstextRange = (TextRange)bs.Sections[0].Paragraphs[0].ChildObjects[0];
Font bsfont = bstextRange.CharacterFormat.Font;
float bssize = bstextRange.CharacterFormat.FontSize;
Color bscolor = bstextRange.CharacterFormat.TextColor;
foreach (Section sec in dy.Sections)
{
foreach(Paragraph paragraph in sec.Paragraphs)
{
foreach(object obj in paragraph.ChildObjects)
{
DocumentObject documentObject = (DocumentObject)obj;
if (documentObject.DocumentObjectType == DocumentObjectType.TextRange)
{
TextRange dytextRange = (TextRange)documentObject;
dytextRange.CharacterFormat.Font= bsfont;
dytextRange.CharacterFormat.FontSize = bssize;
dytextRange.CharacterFormat.TextColor = bscolor;
}
}
}
bs.Sections.Add(sec.Clone());
}
bs.SaveToFile("result.docx");
If this does not meet your needs well, please provide us with your two input files and your desired output file, and then we will investigate further. You could send them to us (
support@e-iceblue.com) via email. Thanks in advance.
Sincerely,
Brian
E-iceblue support team