Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Mon Mar 29, 2021 1:47 pm

Hi Team,

When i am trying to merge the dynamic word document with base word document the font size and other settings are going from the dynamically merged document. can you please help me to provide the method to use the same font for base template please ?

Thanks
Pathfinder team

Manikandan.ma
 
Posts: 11
Joined: Wed Jun 10, 2020 10:13 am

Tue Mar 30, 2021 10:40 am

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
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Fri Apr 09, 2021 10:52 am

Hello,

Greetings from E-iceblue!
Did the code we provided work for you? Any feedback will be greatly appreciated.

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Return to Spire.Doc