The font on doc is not installed on my computer, but after converting to PDF, it is not the default font I set, but the first font of all fonts on my computer.
Env
Windows 11
Aspose.Words for .NET 24.1
Code
void Test()
{
Aspose.Words.Fonts.FontSettings.DefaultInstance.SubstitutionSettings.DefaultFontSubstitution.DefaultFontName = "Arial Unicode MS";
var doc = new Aspose.Words.Document(@"C:\Users\Administrator\Desktop\test.doc");
var ops = new Aspose.Words.Saving.PdfSaveOptions();
doc.Save(@"C:\Users\Administrator\Desktop\test.pdf", ops);
}
@xxtears Could you please attach your input and output document here for testing? We will check the issue and provide you more information. What fonts are available in your environment.
void Test()
{
Aspose.Words.Fonts.FontSettings.DefaultInstance.SubstitutionSettings.DefaultFontSubstitution.DefaultFontName = "微软雅黑";
var doc = new Aspose.Words.Document(@"C:\Users\Administrator\Desktop\test.doc");
doc.WarningCallback = new DocumentSubstitutionWarnings();
var ops = new Aspose.Words.Saving.PdfSaveOptions();
doc.Save(@"C:\Users\Administrator\Desktop\test.pdf", ops);
}
public class DocumentSubstitutionWarnings : IWarningCallback
{
public void Warning(WarningInfo info)
{
info.Dump();
}
public WarningInfoCollection FontWarnings = new WarningInfoCollection();
}
@xxtears As I can see by the provided warnings the fonts are substituted before default font substation rule is applied. There are substituted with font info substitution and alternative name substitution, which are applied before default font substitution rule.
This all seems a bit complicated, I just want that when converting word to pdf, if the font does not exist, a default font should be set. Currently this default font is the first among all Chinese fonts installed on my computer. I want to change it. I don’t want it to take the first Chinese font, but the font name I set myself. So, how should I modify this code?
void Test()
{
//Aspose.Words.Fonts.FontSettings.DefaultInstance.SubstitutionSettings.DefaultFontSubstitution.DefaultFontName ="Times New Roman";
var doc = new Aspose.Words.Document(@"C:\Users\Administrator\Desktop\test.doc");
doc.FontInfos.Dump();
doc.WarningCallback = new DocumentSubstitutionWarnings();
var ops = new Aspose.Words.Saving.PdfSaveOptions();
doc.Save(@"C:\Users\Administrator\Desktop\test.pdf", ops);
}
public class DocumentSubstitutionWarnings : IWarningCallback
{
public void Warning(WarningInfo info)
{
info.Dump();
}
public WarningInfoCollection FontWarnings = new WarningInfoCollection();
}
Summary
I’d rather it be Microsoft YaHei UI than zihun55hao-longyinshoushu, so I want to change it. image.png (266.0 KB)
@xxtears In the font substitution warning there is a reason. In this case this font info substitution rule. So the substitution is determined by the information from FontInfo stored in the document. Aspose.Words takes in account font panose, unicode ranges, codepages, pitch, charset and weight of the font to select a suitable substitution.