如何使用java向Itext添加新字体 [英] How to add new fonts to Itext using java
问题描述
当我想使用 iText 字体时,我会执行以下操作:
when I want to use a font is iText I do the following:
protected final static Font FONT_SIZE_11_BOLD = new Font(Font.HELVETICA, 11f, Font.BOLD);
然后我可以随心所欲地使用它,如下所示:
and then I can use it whereever I want, as follows:
monthSize11 = new Chunk(month, FONT_SIZE_11_BOLD);
我想用 Arial 代替 HELVETICA,但 Arial 不能直接使用.我的意思是,我做不到
I want to use Arial instead of HELVETICA, but Arial is not directly available. I mean, I cannot do
new Font(Font.ARIAL, 11f, Font.BOLD);
因为 Arial 未在 Font 类中定义,但 Arial.ttf 文件位于我的系统中的 C:WINDOWSFonts 下.问题是如何将 Arial.ttf 文件绑定到 iText 以及如何使用它.
because Arial is not defined at the Font class, but the Arial.ttf file is at my System under C:WINDOWSFonts. The question is how I can bind the Arial.ttf file to iText and how can I use it.
提前很多次.
我想使用自己的字体.我的意思是,我有一个名为myCompany.ttf"的文件,其中定义了自己的字体,并且在某些地方我必须使用.问题不仅在于 Arial.
I would like to use own fonts. I mean, I have a file called "myCompany.ttf" where own fonts have been defined and at some places I must use. The problem is not only with Arial.
推荐答案
BaseFont base = BaseFont.createFont("c:/windows/fonts/arial.ttf", BaseFont.WINANSI);
Font font = new Font(base, 11f, Font.BOLD);
....
在此处阅读更多信息.
这篇关于如何使用java向Itext添加新字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!