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;