系統中明明有字體的,Word中顯示也正常,就是轉換爲PDF之後不正常,字體丟失,被替換成了等線字體字體
好一番研究,終於找到緣由blog
,緣由是Windows\Fonts下的文件,有些只是虛擬的路徑,真正的字體文件是在C:\Users\用戶名AppData\Local\Microsoft\Windows\Fonts\ 這個目錄下,從而致使的這個問題ci
只要將用戶的字體目錄添加進去就能夠了,代碼以下string
//取用戶字體目錄 string userfontsfoloder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)+ "\\Microsoft\\Windows\\Fonts\\"; Console.WriteLine("userfontsfoloder:" + userfontsfoloder); string outFilePdf = Path.GetDirectoryName(txtpicDir.Text) + "\\" + Path.GetFileNameWithoutExtension(txtpicDir.Text) + ".pdf"; Aspose.Words.Document document = new Aspose.Words.Document(txtpicDir.Text); 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);