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 Aug 15, 2022 8:15 am

Hi e-iceblue team,

FreeSpire.Doc" Version="10.7.0"

I tried to use MS font built with my Dockerfile in Linux Container.

I've already installed the fonts I need. ("fc-list :lang=zh" it would indeed show my font list.)

However, I set my font like this.

Code: Select all
foreach (var Pobj in paragraph.ChildObjects)
            {
                if (Pobj is TextRange)
                {
                    TextRange textRange = Pobj as TextRange;
                    //set the font
                    textRange.CharacterFormat.FontNameFarEast = "文鼎標楷注音"; // <--- my font
                    //set the font size
                    textRange.CharacterFormat.FontSize = 50;
                }
            }


What happened to this font ????


What should I do next ?
Thanks,
Jeff

jeffchen
 
Posts: 4
Joined: Mon Aug 15, 2022 8:08 am

Mon Aug 15, 2022 10:19 am

Hi Jeff,

感谢您的咨询。

首先确定字体名字是否一致,您可以在windows中尝试打开和装这个字体文件,此时可以看到字体名称。您在代码中设置的FontName需要与这个字体名一致。
其次,设置字体名的话,您应该直接使用如下代码
Code: Select all
range.CharacterFormat.FontName = "宋体";


如果仍然无效,请您尝试直接为Spire.Doc指定此字体文件的路径。参考代码:
Code: Select all
doc.PrivateFontList.Add(new PrivateFontPath("宋体","/root/test/simsun.ttf"));
Sincerely,
Andy
E-iceblue support team
User avatar

Andy.Zhou
 
Posts: 483
Joined: Mon Mar 29, 2021 3:03 am

Mon Aug 15, 2022 10:31 am

Hi Andy

I've added
Code: Select all
document.PrivateFontList.Add(new PrivateFontPath(@"文鼎標楷注音", @"/usr/share/fonts/truetype/ms/kai08mz_1.ttf"));


BUT it's still NOT working.

Jeff

jeffchen
 
Posts: 4
Joined: Mon Aug 15, 2022 8:08 am

Tue Aug 16, 2022 6:24 am

Hi Jeff,

感謝您的回復。

有兩個疑問想跟您確認下。
1. 在您的docker容器中,是否能正常顯示繁體中文字符?
2. 當您將產生的Docx文檔取回Windows系統中查看時,對應的段落文本的字形是否是該字體(文鼎標楷注音)實際的字形呢?

我想上一次我對您的問題有所誤解。因為單純生成Docx文檔的話,是並不需要實際安裝這些字體的。只需要寫入對應的字體名稱到Docx的配置中即可。實際需要使用字體的時機是您使用類似於微軟Word這類查看工具時。換句話說,只有當您查看文檔時,才需要當前系統中安裝有對應的字體。否則的話,微軟Word會在系統中找尋其他可替代的字體來顯示對應段落的文本。這也就是我為什麼想跟您確認以上兩點的原因。我猜測在docker容器中,Spire.Doc確實按照您填入的字體名稱(文鼎標楷注音)配置了Docx文檔的相應文本,但可能由於Docker中並不支持繁體中文字符的編碼,導致實際寫入到Docx文件時,“文鼎標楷注音”這幾個字變成了您截圖中的亂碼。因此請您確認以上兩點,看能否自行解決問題。
如果您無法解決問題,您可以將此字體文件以及您目前生成的Docx文件一併發送給我們,我將調查是否與我的猜想一致。您可以將它們打包發送到support@e-iceblue.com或者就在這裡上傳。提前感謝您的協助。
Sincerely,
Andy
E-iceblue support team
User avatar

Andy.Zhou
 
Posts: 483
Joined: Mon Mar 29, 2021 3:03 am

Wed Aug 17, 2022 1:40 am

Hi Andy

1. Yes (ENV LANG C.UTF-8 in my Dockerfile)
2. No

I've already sent my project to support@e-iceblue.com

Thanks !!
Jeff

jeffchen
 
Posts: 4
Joined: Mon Aug 15, 2022 8:08 am

Wed Aug 17, 2022 10:22 am

Hi Jeff,

Thanks for your sharing.

I checked your project and fonts and found that the font name you are using is not the same as the real one. As shown in the screenshot below, the real name of the font is "Bpmf Zihi KaiStd Regular". Please try to modify the font name in the code and test again.
screenshot.png
Sincerely,
Andy
E-iceblue support team
User avatar

Andy.Zhou
 
Posts: 483
Joined: Mon Mar 29, 2021 3:03 am

Thu Aug 18, 2022 1:24 am

Hi Andy

1. The image you showed was opened on your host machine or in container ?
I changed my code as you said, and it is still not working.
2. Is it successful to see my expected result on your container ?


Thanks,
Jeff

jeffchen
 
Posts: 4
Joined: Mon Aug 15, 2022 8:08 am

Wed Sep 21, 2022 10:10 am

Hello Jeff,

We are so sorry for the late reply. This is Abel from E-iceblue support team.
1. The image you showed was opened on your host machine or in container ?
The image was opened in my host machine (win-10 64-bit).
2. Is it successful to see my expected result on your container ?
I used the following code (“code1” and “code2”) to test your scenario in linux system (CentOS release 7.9.2009)
When I set font name to “文鼎標楷注音” in “code1”, the font name is correctly shown but the font(文鼎標楷注音) isn’t applied to the content of result document(result1.doc).
when I used the MS Office365 to open the result document in my host machine.

In addition, when I set font real name to “Bpmf GenRyu Min R” in “code2”, the font name is correctly shown and the font is successful applied to the content of result document (result2.doc)
Ps:
(1) I used MS Office365 to open the result document in my host machine.
(2) I have attached the result document.

code1:
Code: Select all
Document doc = new Document();
Section sec = doc.AddSection();
Paragraph par = sec.AddParagraph();


doc.PrivateFontList.Add(new PrivateFontPath(@"文鼎標楷注音", @"BpmfGenRyuMin-R.ttf"));
doc.EmbedFontsInFile = true;
CharacterFormat format = new CharacterFormat(doc);
format.FontName = @"文鼎標楷注音";
format.FontSize = 50;
format.Bold = true;

//Paragraph par1 = textBox.Body.AddParagraph();
par.AppendText("哈哈哈").ApplyCharacterFormat(format);
doc.SaveToFile(@"result.doc", FileFormat.Doc);

code2:
Code: Select all
Document doc = new Document();
Section sec = doc.AddSection();
Paragraph par = sec.AddParagraph();


doc.PrivateFontList.Add(new PrivateFontPath(@"Bpmf GenRyu Min R", @"BpmfGenRyuMin-R.ttf"));
doc.EmbedFontsInFile = true;
CharacterFormat format = new CharacterFormat(doc);
format.FontName = @"Bpmf GenRyu Min R";
format.FontSize = 50;
format.Bold = true;

//Paragraph par1 = textBox.Body.AddParagraph();
par.AppendText("哈哈哈").ApplyCharacterFormat(format);
doc.SaveToFile(@"result.doc", FileFormat.Doc);


Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 980
Joined: Tue Mar 08, 2022 2:02 am

Return to Spire.Doc