【Util】iText,iTextAsian,中文显示

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.****.net/inforstack/article/details/47083251

1.根据路径获取:

Font fontZh = FontFactory.getFont("C:\\Windows\\Fonts\\MSYH.TTF", BaseFont.IDENTITY_H,BaseFont.NOT_EMBEDDED);

2.使用iTextAsian.jar中的字体

Font fontZh = FontFactory.getFont("STSong-Light", "UniGB-UCS2-H", 14, Font.BOLD, new CMYKColor(0, 255, 0, 0));

3.TestPDF.java

public static void main(String[] args) {
	try {
		Document document = new Document();
		OutputStream os = new FileOutputStream(new File("C:\\Users\\Administrator\\Desktop\\test.pdf"));
		PdfWriter.getInstance(document, os);
		document.open();
		document.add(new Paragraph("看看有没有输出中文?", getFont()));
		document.close();
	} catch (Exception e) {
		e.printStackTrace();
	}
}


 

【Util】iText,iTextAsian,中文显示

注:

1.个人习惯用FontFactory,FontFactory只不过对BaseFont进行了封装(个人理解,不喜勿喷)。FontFactory.getFont()中最后的实现还是调用了BaseFont.createFont();

2.jar包地址:http://download.****.net/detail/inforstack/8936407

上一篇:期末考试题--局域网服务配置组


下一篇:2020最强合集:阿里巴巴研发效能&DevOps干货都在这里啦!