aspose word转pdf 字体
时间: 2024-12-16 17:10:00 浏览: 58
在使用Aspose.Word进行Word文档转换为PDF时,字体的处理是一个重要的环节。默认情况下,Aspose.Word会尝试使用系统中的字体,但如果目标系统中缺少某些字体,可能会导致PDF文档中的字体显示不正确。为了确保转换后的PDF文档字体正确,可以采取以下几种方法:
嵌入字体:将使用的字体嵌入到PDF文档中。这样可以确保在任何设备上查看PDF时,字体都能正确显示。
Document doc = new Document("input.docx"); PdfSaveOptions options = new PdfSaveOptions(); options.EmbedFullFonts = true; doc.Save("output.pdf", options);
替换字体:如果目标系统中缺少某些字体,可以手动替换为系统存在的字体。
Document doc = new Document("input.docx"); foreach (Font font in doc.GetChildNodes(NodeType.Font, true)) { if (font.Name == "MissingFont") { font.Name = "Arial"; } } doc.Save("output.pdf");
使用字体映射:通过字体映射文件,将缺少的字体映射到系统中存在的字体。
FontSettings fontSettings = new FontSettings(); fontSettings.SubstitutionSettings.TableSubstitution = new FontSubstitutionCollection(); fontSettings.SubstitutionSettings.TableSubstitution.Add("MissingFont", "Arial"); doc.FontSettings = fontSettings; doc.Save("output.pdf");
通过以上方法,可以有效解决Aspose.Word转PDF时的字体问题,确保转换后的PDF文档字体显示正确。
相关推荐


















