Hi all,
Here's my situation: I'm using PDFBox to parse a PDF file and grab the
text out of it. With each span of text, I get the postscript font name
and the font size. So far, so good.
Next, I will change some fonts without changing size or style. For
example, Times New Roman Bold Italic becomes Courier New Bold Italic,
or perhaps Arial Bold Italic. I'm not hardcoding this font mapping.
So what I need to do is extract the style of the font from the
postscript name, then I can apply the style to whatever font I want.
The problem is, how do I get the style from the postscript name?
My first idea was this:
FontFactory.registerFonts();
com.lowagie.text.Font afont = FontFactory.getFont("TimesNewRomanPS-
BoldItalicMT");
System.out.println("Font is " + afont.getFamilyname() + " " +
afont.getStyle());
The only problem is that while the family name turned out right, the
style was -1 (undefined). My next idea:
FontFactory.registerFonts();
Set<String> fontnames = FontFactory.getRegisteredFonts();
for (String fontname : fontnames)
{
com.lowagie.text.Font font = FontFactory.getFont(fontname);
System.out.println(fontname + " " +
font.getBaseFont().getPostscriptFontName());
}
That failed, too, because on one font, /Library/Fonts/AppleMyungjo.ttf
(I'm on OSX), I got this:
Exception in thread "main" ExceptionConverter:
com.lowagie.text.DocumentException: Table 'OS/2' does not exist in /
Library/Fonts/AppleMyungjo.ttf
OK, so after catching and ignoring that exception, I found many, many
fonts that matched my test name, and all of them had style -1.
So, is there a way to extract the style from a postscript font name?
Thanks!
--Rob
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://www.1t3xt.com/docs/book.php