Description
I want to convert pptx
to pdf
, but I found a Chinese font is missing.
Env
- Windows 10
- .NET 4.7
- Aspose.Slides 23.6 for .NET
Code 1
Note: I had installed the Chinese font in OS.
Aspose.Slides.FontsLoader.ClearCache();
Aspose.Slides.FontsLoader.LoadExternalFonts(new string[] {@"C:\Windows\Fonts", @"C:\Users\Administrator\AppData\Local\Microsoft\Windows\Fonts\"});
var doc = new Aspose.Slides.Presentation(@"C:\Users\Administrator\Desktop\test\1.pptx");
doc.Save(@"C:\Users\Administrator\Desktop\test\out.pdf", Aspose.Slides.Export.SaveFormat.Pdf);
Before:
image.jpg (320.4 KB)
After:
image.jpg (157.1 KB)
Code 2
Maybe I can embed all fonts before save, it’s working, but I think it is not a good way.
var s = System.IO.File.ReadAllBytes(@"C:\Users\Administrator\AppData\Local\Microsoft\Windows\Fonts\字魂55号-龙吟手书.ttf");
var doc = new Aspose.Slides.Presentation(@"C:\Users\Administrator\Desktop\test\1.pptx");
doc.FontsManager.AddEmbeddedFont(s, Aspose.Slides.Export.EmbedFontCharacters.OnlyUsed);
doc.Save(@"C:\Users\Administrator\Desktop\test\out.pdf", Aspose.Slides.Export.SaveFormat.Pdf);
Before:
image.jpg (320.4 KB)
After (It’s right):
image.jpg (147.3 KB)
Files
@xucongli1989,
Thank you for describing the issue.
You should not load fonts from system folders of OS. System fonts are used automatically by Aspose.Slides. You can save custom fonts to your own folder and use the FontsLoader
class to load them from the folder, if you don’t want install them on OS.
Without that font, I have the same results. But when I installed the font on my OS, I have correct results. Please check carefully again if the font has been installed on your OS.
Thanks for your help, but I do had this problem.Could you send me the result file that you processed?
Code
void Test()
{
var doc = new Aspose.Slides.Presentation(@"C:\Users\Administrator\Desktop\test\1.pptx");
doc.Save(@"C:\Users\Administrator\Desktop\test\1.pdf", Aspose.Slides.Export.SaveFormat.Pdf);
}
C:\Windows\Fonts
:
image.png (201.3 KB)
After process:
image.jpg (457.7 KB)
@xucongli1989,
Please look at my results: output.zip (3.7 MB). It looks like it is an environment-specific issue. Please try to collect additional information about your environment.
@xucongli1989,
However, I was also unable to load the font as a custom font using the FontsLoader
class.
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): SLIDESNET-44077
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.
Thanks for your reply, the problem seems about the font cann’t be found by Aspose Slides. It may be related to the name of the font, because in Chinese environment, a font has a Chinese name and an English name.
If I change the code, it was working for the target text.
void Test()
{
var loadOps = new Aspose.Slides.LoadOptions();
loadOps.DefaultRegularFont = "zihun55hao-longyinshoushu";//English name of the Chinese font.
var doc = new Aspose.Slides.Presentation(@"C:\Users\Administrator\Desktop\test\1.pptx", loadOps);
doc.Save(@"C:\Users\Administrator\Desktop\test\1.pdf", Aspose.Slides.Export.SaveFormat.Pdf);
}
@xucongli1989,
Thank you for the additional information. However, I do not recommend this way of solving the problem. The DefaultRegularFont
property is used to replace any font that is not found with the specified font.
I will pass your information on to our developers.
@xucongli1989,
Thank you, I forwarded it to our developers.