Dear Sir
We encountered a strange problem when using the Aspose. word component which version is 22.11 at dot net platform to convert Word into a PDf document. Please see the screenshot below where the font has been changed.
image.png (6.0 KB)
bellow is the word document and pdf document .
fonts_problem.docx (19.9 KB)
fonts_problem.pdf (30.9 KB)
However, the same set of code converted from my local server has a normal font, and running it on the server will cause problems. Here is our code
byte[] datas = File.ReadAllBytes("D:\\fonts_problem.docx");
Aspose.Words.Document doc = new Aspose.Words.Document(new MemoryStream(datas));
string userfontsfoloder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\Microsoft\\Windows\\Fonts\\";
Console.WriteLine(userfontsfoloder);
ArrayList fontSources = new ArrayList(FontSettings.DefaultInstance.GetFontsSources());
//将用户目录字体添加到字体源中
Aspose.Words.Fonts.FolderFontSource folderFontSource = new Aspose.Words.Fonts.FolderFontSource(userfontsfoloder, true);
fontSources.Add(folderFontSource);
Aspose.Words.Fonts.FontSourceBase[] updatedFontSources = (Aspose.Words.Fonts.FontSourceBase[])fontSources.ToArray(typeof(Aspose.Words.Fonts.FontSourceBase));
FontSettings.DefaultInstance.SetFontsSources(updatedFontSources);
var options = new Aspose.Words.Saving.PdfSaveOptions();
options.DownsampleOptions.Resolution = 120;
//options.FontEmbeddingMode = PdfFontEmbeddingMode.EmbedAll;
options.UseCoreFonts = true;
//options.EmbedFullFonts = true;
options.AllowEmbeddingPostScriptFonts = true;
MemoryStream output = new MemoryStream();
SaveOutputParameters rlt = doc.Save(output, options);
File.WriteAllBytes("d:\\1.pdf", output.ToArray());