[英]How to set a default windows font in a paragraph using iText
How can I set a font type by giving it's path in iText 如何通过在iText中提供字体类型来设置字体类型
I tried this one. 我尝试了这个。 But it is not working. 但这是行不通的。
Font ff = new Font(Font.getFamily("C:/Windows/Fonts/Harry Potter Regular.ttf"));
ff.setSize(12);
First create a BaseFont
with required font file: 首先使用所需的字体文件创建一个BaseFont
:
BaseFont bf = BaseFont.createFont(src, myEncoding, BaseFont.EMBEDDED);
Then create the actual font with size and style attributes, for example: 然后使用size和style属性创建实际的字体,例如:
com.itextpdf.text.Font f = new Font(bf, 14.5f, Font.ITALIC | Font.BOLD);
The getFamily method you used, refers to the Acrobat predefined fonts: FontFactory.COURIER, FontFactory.HELVETICA, FontFactory.TIMES_ROMAN, FontFactory.SYMBOL, FontFactory.ZAPFDINGBATS
. 您使用的getFamily方法引用Acrobat的预定义字体: FontFactory.COURIER, FontFactory.HELVETICA, FontFactory.TIMES_ROMAN, FontFactory.SYMBOL, FontFactory.ZAPFDINGBATS
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.