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);
    

      

  • 相关阅读:
    Pika的设计及实现
    高性能网络编程
    C语言的结构体
    消息队列库——ZeroMQ
    Diffie-Hellman密钥交换算法
    mysql-proxy 读写分离
    位运算
    分布式学习之一:事务
    Redis Cluster
    SpringBoot整合ActiveMQ,看这篇就够了
  • 原文地址:https://www.cnblogs.com/icejd/p/11868691.html
Copyright © 2011-2022 走看看