开发者

TIMES NEW ROMAN font in iText (Java version)

I need to do something like this in iText:

Font fuente=new Font(Font.getFamily("ARIAL"),30,Font.BOLD);

But instead using ARIAL font, I need t开发者_如何学Pythono use the TIMES NEW ROMAN font over a Paragraph. How could I accomplish this?

Thanks.


You have a problem.

Font.getFamily(string) only works for the "Base 14" fonts, Helvetica, Times Roman, Courier (plus their bold & italic variants), plus Symbol and ZapfDingbats. Asking it for anything but one of those fonts will return FontFamily.UNDEFINED.

Your code isn't working the way you think it does. If you happen to be ending up with Arial, that's only because it's the default font.

What you want is FontFactory.getFont(...). Before FontFactory can return a given font by name, you need to register that font's file. The easiest way to do that is to call FontFactory.registerDirectories() which will enumerate all the directories known operating systems use to store fonts and register all the fonts found there. This will take longer depending on how many fonts you have there, and how big those fonts are. A lot of CJKV fonts will take a significant amount of time to register... under 30 seconds in all likelyhood, but my beast of a system can take 10-20 seconds to do so (but I have a LOT of Big Fonts).

You can also register individual files with FontFactory.register(fontPath), but that requires that you know where to find them in the first place.

At any rate, your code could read something like:

FontFactory.registerDirectories();

Font fuente = FontFactory.getFont("Times New Roman");

And FontFactory does indeed ignore case when looking up fonts. Font.getFamily() does not.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜