zoukankan      html  css  js  c++  java
  • Aspose.Words转换为PDF的时候字体丢失的问题解决

    系统中明明有字体的,Word中显示也正常,就是转换为PDF以后不正常,字体丢失,被替换成了等线字体

    好一番研究,终于找到原因

    ,原因是WindowsFonts下的文件,有些只是虚拟的路径,真正的字体文件是在C:Users用户名AppDataLocalMicrosoftWindowsFonts 这个目录下,从而导致的这个问题

    只要将用户的字体目录添加进去就可以了,代码如下

    //取用户字体目录
                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);
    

      

  • 相关阅读:
    运算符的方向--好神奇
    a++ 和 ++a ;
    c语言中!和~的区别
    函数的参数,参数为数组
    反射的理解
    ThreadLocal类
    多线程面试题-sleep()和wait()区别
    话题1-关键字
    实现多线程的另一种方式-Callable
    线程池
  • 原文地址:https://www.cnblogs.com/icejd/p/11868691.html
Copyright © 2011-2022 走看看