nanotime wrote:
> I'm using itext for creating PDF file with Unicode encoding.
> My workstation is Windows Vista, so I create fonts using this construction:
> 
> --------------------------
> BaseFont arialUnicode =
> BaseFont.createFont("C:\\Windows\\Fonts\\arialuni.ttf", BaseFont.IDENTITY_H,
> BaseFont.EMBEDDED);
> --------------------------

IMO using "c:/Windows/Fonts/arialuni.ttf" is better than using
"C:\\Windows\\Fonts\\arialuni.ttf".

> Then i moved to linux and therefore expirienced exception - can't find font

Of course not: on linux there is no "C:" drive; that's a windows only
concept. When I write examples, I use "c:/Windows/Fonts/arialuni.ttf"
and then I create a directory named "c:" on linux in the working dir
of my JVM. Funny enough that works ;-)

> I searched API and docs and found FontFactory.registerDirectories()

Of course working with registerDirectories is better.
My previous remark is just a dirty hack.

> After invocation of this method I'm printing out all registered fonts using
> code (all next code snippets run under Windows Vista):
> 
> --------------------------
> Set fonts = FontFactory.getRegisteredFonts();
> for (Object font : fonts) {
>     System.out.println(font);
> }
> --------------------------
> 
> that prints a lot of font names, and also "arialunicodems" and "arial
> unicode ms".

I've just tested this on Vista:

FontFactory.registerDirectories();
Font f = FontFactory.getFont("Arial Unicode MS", BaseFont.IDENTITY_H, 
BaseFont.EMBEDDED);

It works. It could also work on linux, provided that you have
arialuni.ttf in one of the following directories:
c:/windows/fonts
c:/winnt/fonts
d:/windows/fonts
d:/winnt/fonts
/usr/X/lib/X11/fonts/TrueType
/usr/openwin/lib/X11/fonts/TrueType
/usr/share/fonts/default/TrueType
/usr/X11R6/lib/X11/fonts/ttf
/Library/Fonts
/System/Library/Fonts

> I then tried both of them to pass into BaseFont.createFont() using code:
> 
> --------------------------
> BaseFont arialUnicode = BaseFont.createFont("arialunicodems",
> BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
> --------------------------
> 
> , but that code throws an exception:
> 
> --------------------------
> Exception in thread "main" com.lowagie.text.DocumentException: Font
> 'arialunicodems' with 'Identity-H' is not recognized
> --------------------------

Works for me with "Arial Unicode MS".

> Once generated on Linux, PDF file should open (and unicode text should not
> be broken) on other Windows machines.

I don't understand what you are saying here,
but it probably makes sense to you.

> What am I doing wrong and how can I make the program to work on both Windows
> and Linux? (suppose I can copy ARIALUNI.TTF on Linux)

If you want to make sure it works on all systems, put arialuni.ttf
in a path (for instance mypath) and register the font like this:

FontFactory.register("mypath/arialuni.ttf", "MyArial");
Font font = FontFactory.getFont("MyArial", BaseFont.IDENTITY_H, 
BaseFont.EMBEDDED);

This is (of course!) all explained in the book 'iText in Action'.
-- 
This answer is provided by 1T3XT BVBA

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

Do you like iText?
Buy the iText book: http://www.1t3xt.com/docs/book.php
Or leave a tip: https://tipit.to/itexttipjar

Reply via email to