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.

Sat Dec 21, 2019 1:19 pm

Hello All,

I've an Arabic text which contains some english links or words. Is there a way that I can have the english text have one font and arabic text in another font? All my text is in single paragraph.


Here is some sample text: the english alphabets might be emails/links/just some english text. I want my english text to be of size 10 and Arabic text to be size 14. Please let me know if this is acheivable.


تنشيط أعمال اجلمعية العامة: تقرير اللجنة السادسة (445/74/A - (البند 12

I've provided my paragraph style as this:


style.IsCustomStyle = true;

style.ParagraphFormat.ClearFormatting();

style.CharacterFormat.FontName = "Traditional Arabic";
style.CharacterFormat.FontSize = 10;
style.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;


style.ParagraphFormat.IsBidi = true;
style.CharacterFormat.Bidi = true;

style.CharacterFormat.FontSizeBidi = 14;

santuvssantu
 
Posts: 98
Joined: Fri Feb 12, 2016 5:21 pm

Mon Dec 23, 2019 3:37 am

Hi,

Thanks for your inquiry,
Note the paragraph style will apply for whole paragraph. As for your case, you need to set different character format for TextRange. Below is code for your kind reference:
Code: Select all
            Paragraph Para = section.AddParagraph();
            TextRange textRange1 = Para.AppendText("البند");
            textRange1.CharacterFormat.FontName = "your font";
            textRange1.CharacterFormat.Bidi = true;
            textRange1.CharacterFormat.FontSizeBidi = 14;

            TextRange textRange2 = Para.AppendText("English text");
            textRange2.CharacterFormat.FontSize = 10;
            textRange2.CharacterFormat.FontName = "your font";


Sincerely,
Betsy
E-iceblue support team
Last edited by Betsy.jiang on Mon Dec 23, 2019 8:49 am, edited 1 time in total.
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Mon Dec 23, 2019 4:59 am

Thanks Betsy,
Unfortunately my text is dynamic and I don't know where I'll get my English text. It's from a database column.

The column might contain email addresses/Names in English along with Arabic text.

santuvssantu
 
Posts: 98
Joined: Fri Feb 12, 2016 5:21 pm

Mon Dec 23, 2019 7:42 am

Hi,

Thanks for your response.
I am afraid setting different format for TextRange is only way to solve your issue.
You want to set different style in a single paragraph. In MS Word, you need to select corresponding text/TextRange to set the different format. If you select a paragraph and set the style, the style of the whole paragraph will be set. Our Spire.Doc follows the rules of the MS Word. Maybe you could find the email addresses/Names(TextRange tr = doc.FindString("string", true, true).GetAsOneRange()) then set the format for the TextRange. Hope you could understand.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Mon Dec 23, 2019 7:58 am

Thanks Betsy, I understand.
One more question in this, what is the difference between FontsizeBidi and FontSize when I'm applying Bidi to true.?

santuvssantu
 
Posts: 98
Joined: Fri Feb 12, 2016 5:21 pm

Mon Dec 23, 2019 8:53 am

Hi,

When you set Bidi as true, please use FontSizeBidi to set the font size for the textRange.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Tue Dec 24, 2019 8:19 pm

word_font.zip


Hi Betsy,
I'm wondering if we can set the attached font settings with Spire, Could you please check it and help?


Thanks,
Santhoshi.

santuvssantu
 
Posts: 98
Joined: Fri Feb 12, 2016 5:21 pm

Wed Dec 25, 2019 2:28 am

Hi,

Thanks for your inquiry.
Please refer to following font settings:
Code: Select all
            TextRange textRange1 = Para.AppendText("البند");
            textRange1.CharacterFormat.FontSize = 10;
            //use this code to set font for RTF text
            textRange1.CharacterFormat.FontNameBidi = "Traditional Arabic";
            textRange1.CharacterFormat.Bidi = true;
            textRange1.CharacterFormat.FontSizeBidi = 14;

If this doesn't meet your requirement, please provide the desired Word file for further investigation.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Wed Dec 25, 2019 6:57 am

Hi Betsy,
Apologies for not making myself clear.

In word, when I select a paragraph, I can give Asian text font and Complex script font for the same paragraph. Does spire provide anything for this

santuvssantu
 
Posts: 98
Joined: Fri Feb 12, 2016 5:21 pm

Wed Dec 25, 2019 7:38 am

Hi Santhoshi,

When using Bidi property, the property FontNameBidi is for setting Complex script font, the property FontName is for setting Asian text font.
Code: Select all
            Document doc = new Document();
            Section section = doc.AddSection();

            ParagraphStyle style = new ParagraphStyle(doc);
            style.Name = "mystyle";
            style.CharacterFormat.Bidi = true;
            style.ParagraphFormat.IsBidi = true;
            //Asian text font
            style.CharacterFormat.FontName = "Times new Roman";
            style.CharacterFormat.FontSize = 10;
            //Complex script font
            style.CharacterFormat.FontNameBidi = "Traditional Arabic";

            style.CharacterFormat.FontSizeBidi = 14;
            doc.Styles.Add(style);

           Paragraph Para = section.AddParagraph();
       
            Para.AppendText(" البند 12334 test");
            Para.ApplyStyle("mystyle");

            doc.SaveToFile("20017.docx", FileFormat.Docx);

Attached is my result Word file. Hope I understand correctly.
If you still have the issue, please provide a sample expected Word file(you could create it via MS Word) for further investigation.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Wed Dec 25, 2019 8:01 am

Perfect, thanks alot.

santuvssantu
 
Posts: 98
Joined: Fri Feb 12, 2016 5:21 pm

Wed Dec 25, 2019 8:18 am

Hi Santhoshi,

Thanks for your feedback.
Please feel free to contact us if there is any question.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Return to Spire.Doc