如何利用Aspose.Pdf为PDF文件设置采用中文字体

作者:控件中国网   出处:控件中国网   2015-09-23 09:36:18   阅读:57

Aspose PDF在对PDF文档创建、添加文本时支持多种国家的语言,对中文支持也很好,当需要为PDF文件设置某种字体显示时,电脑上必须有改字体,如果没有则需要安装该字体,一般对于中文显示,可以设置PDF文件的字体为Arial Unicode MS font字体,下面的代码阐述了如何为部分文本设置字体:

Document textdoc = new Document();

Page page = textdoc.Pages.Add();

//Chinese

TextFragment textc = new TextFragment("The Chinese Text Project (CTP; Chinese: 中國哲學書電子化計劃) is a digital library project");

//Set text properties

textc.TextState.FontSize = 8;

textc.TextState.Font = FontRepository.FindFont("Arial Unicode MS");

//Add a new text paragraph in paragraphs collection and pass the TextFramment object

page.Paragraphs.Add(textc);

//Save resultant PDF file

textdoc.Save(myDir + "TextPDF.pdf");

当然也可以为整页或者整个PDF文件设置统一的字体:

Document doc = new Document();

Aspose.Pdf.Text.Font font = Aspose.Pdf.Text.FontRepository.FindFont("Arial");

doc.PageInfo.DefaultTextState.Font = font;

Copyright© 2006-2015 ComponentCN.com all rights reserved.重庆磐岩科技有限公司(控件中国网) 版权所有 渝ICP备12000264号 法律顾问:元炳律师事务所
客服软件
live chat