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.

Wed Oct 26, 2016 2:25 pm

Hi,

We are trying to change all fonts in a document to Arial. Document is imported from HTML. The operation doesn't work instead it always ends up with the font style from the HTML document. We are now trying to loop all paragraphs and replace all fonts but it doesn't work.

Code: Select all
            ParagraphStyle s1 = new ParagraphStyle(document);
            s1.Name = "TestStyle";
            s1.CharacterFormat.FontName = "Arial";
            document.AddParagraphStyle(s1.Name);

            //Set for whole document
            SectionCollection sections = document.Sections;
            foreach (Section section in sections)
            {
                Paragraph p1 = section.Paragraphs[0];
                p1.ApplyStyle(s1.Name);
            }

dgconfidator
 
Posts: 1
Joined: Wed Sep 14, 2016 8:08 am

Thu Oct 27, 2016 6:22 am

Dear dgconfidator,

Thanks for your inquiry. Please notice that the AddParagraphStyle method is to create new paragraph style for the document not to add the style you set into the document. And here are two methods respectively to change the document font for your reference.
Code: Select all
            //solution1
            ParagraphStyle s1;
            s1=document.AddParagraphStyle("textStyle");
            s1.CharacterFormat.FontName = "Arial";

Code: Select all
            //solution2
            ParagraphStyle s1 = new ParagraphStyle(document);
            s1.Name = "TestStyle";
            s1.CharacterFormat.FontName = "Arial";
            document.Styles.Add(s1);

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1182
Joined: Tue Sep 27, 2016 1:06 am

Fri Oct 28, 2016 9:55 am

Hi dgconfidator,

How is your issue now? Do you use the codes that I provided for you? Could you please give us some feedback at your convenience?

Thanks,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1182
Joined: Tue Sep 27, 2016 1:06 am

Return to Spire.Doc