> 文章列表 > Word控件Spire.Doc 【脚注】字体(3):将Doc转换为PDF时如何使用卸载的字体

Word控件Spire.Doc 【脚注】字体(3):将Doc转换为PDF时如何使用卸载的字体

Word控件Spire.Doc 【脚注】字体(3):将Doc转换为PDF时如何使用卸载的字体

Spire.Doc for .NET是一款专门对 Word 文档进行操作的 .NET 类库。在于帮助开发人员无需安装 Microsoft Word情况下,轻松快捷高效地创建、编辑、转换和打印 Microsoft Word 文档。拥有近10年专业开发经验Spire系列办公文档开发工具,专注于创建、编辑、转换和打印Word/PDF/Excel等格式文件处理,小巧便捷。 

E-iceblue功能类库Spire 系列文档处理组件均由中国本土团队研发,不依赖第三方软件,不受其他国家的技术或法律法规限制,同时适配国产操作系统如中科方德、中标麒麟等,兼容国产文档处理软件 WPS(如 .wps/.et/.dps 等格式

Spire.Doc for.NET 最新下载(qun:767755948)icon-default.png?t=N3I4https://www.evget.com/product/3368/download

现在Spire.Doc支持在将Doc转换为PDF时使用未安装的字体以实现文本内容的多样化。在这篇文章中,我们将谈论如何实现这一功能:如何在通过Spire.Doc将Doc转换为PDF时使用卸载的字体

步骤1:下载一个在系统中卸载的字体。

步骤2:创建一个新的空白Word文档。

Document document = new Document();

步骤3:添加一个部分并创建一个新段落。

Section section = document.AddSection();
Paragraph paragraph = section.Paragraphs.Count > 0 ? section.Paragraphs[0] : section.AddParagraph();

步骤4:为 txtRange 附加文本。

TextRange txtRange = paragraph.AppendText(text);

步骤5:为名为pdf的类ToPdfParameterList创建一个示例,并为属性PrivateFontPaths创建一个新的PrivateFontPathlist,使用下载字体的名称和路径实例化一个PrivateFontPath。

ToPdfParameterList toPdf = new ToPdfParameterList()
{
PrivateFontPaths = new List()
{
new PrivateFontPath("DeeDeeFlowers",@"D:\\DeeDeeFlowers.ttf")
}
};

步骤6:为 txtaRange 设置新字体。

txtRange.CharacterFormat.FontName = "DeeDeeFlowers";

步骤7:将文档转换为 PDF。

document.SaveToFile("result.pdf", toPdf);

步骤8:查看转换后的 PDF 文件。

System.Diagnostics.Process.Start("result.pdf");

结果截图

完整代码如下

Document document = new Document();//Add the first secition
Section section = document.AddSection();
//Create a new paragraph and get the first paragraph
Paragraph paragraph
= section.Paragraphs.Count > 0 ? section.Paragraphs[0] : section.AddParagraph();//Append Text
String text
= "This paragraph is demo of text font and color. "
+ "The font name of this paragraph is Tahoma. "
+ "The font size of this paragraph is 20. "
+ "The under line style of this paragraph is DotDot. "
+ "The color of this paragraph is Blue. ";
TextRange txtRange = paragraph.AppendText(text);//Import the font
ToPdfParameterList toPdf = new ToPdfParameterList()
{
PrivateFontPaths = new List<PrivateFontPath>()
{
new PrivateFontPath("DeeDeeFlowers",@"D:\\DeeDeeFlowers.ttf")
}
};
//Make use of the font.
txtRange.CharacterFormat.FontName = "DeeDeeFlowers";document.SaveToFile("result.pdf", toPdf);System.Diagnostics.Process.Start("result.pdf");

以上便是通过Spire.Doc将Doc转换为PDF时如何使用卸载的字体的教程,如果您有其他问题也可以继续浏览本系列文章,获取相关教程,你还可以给我留言哦~

导航下载网