如何使用java将新字体添加到Itext [英] How to add new fonts to Itext using java

查看:1129
本文介绍了如何使用java将新字体添加到Itext的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  protected final static Font FONT_SIZE_11_BOLD = new Font( Font.HELVETICA,11f,Font.BOLD); 

然后我可以随便使用它,如下所示:

  monthSize11 = new Chunk(month,FONT_SIZE_11_BOLD); 

我想使用Arial而不是HELVETICA,但是Arial不是直接可用的。
我的意思是,我不能这样做

pre code> new Font(Font.ARIAL,11f,Font.BOLD);

因为Arial没有在Font类中定义,但是Arial.ttf文件在我的系统下C:\WINDOWS\Fonts。
问题是如何将Arial.ttf文件绑定到iText,我怎样才能使用它。



许多提示。 b
$ b

编辑:我想使用自己的字体。我的意思是,我有一个名为myCompany.ttf的文件,在其中定义了自己的字体,并且在某些地方我必须使用它。问题不仅在于Arial。

解决方案

  BaseFont base = BaseFont.createFont(c:/ windows / fonts / arial .ttf,BaseFont.WINANSI); 
Font font = new Font(base,11f,Font.BOLD);
....

阅读更多在这里


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);

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);

because Arial is not defined at the Font class, but the Arial.ttf file is at my System under C:\WINDOWS\Fonts. The question is how I can bind the Arial.ttf file to iText and how can I use it.

Many thnaks in advance.

EDIT: 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);
....

Read more here.

这篇关于如何使用java将新字体添加到Itext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆