On Jun 9, 2010, at 4:51 PM, Mark Storer wrote:
> I just banged that out in this email here... you'll want to check  
> things
> against null hither and yon in Real Code... heck it might not even
> compile.


Almost spot-on. Here's what I ended up with:

private String getFieldFont(AcroFields acroFields, String fieldName)
{
     String fontName = null;
     try
     {
         AcroFields.Item item = acroFields.getFieldItem(fieldName);
         PdfDictionary merged = item.getMerged(0);
         TextField textField = new TextField(null, null, null);
         acroFields.decodeGenericDictionary(merged, textField);
         String[][] fullFontName =  
textField.getFont().getFullFontName();
         fontName = fullFontName[0][3];
     }
     catch (DocumentException de)
     {
         getServletContext().log(de.getMessage());
     }
     catch (IOException ioe)
     {
         getServletContext().log(ioe.getMessage());
     }
     return fontName;
}

Now, for the rest of the story.

I had my designer create a PDF using Acrobat/Illustrator with twelve  
form fields (representing 12 of the 14 base fonts) and then I logged  
the values. Here's what I got:

Courier
Courier-Bold
Courier-BoldOblique
Courier-Oblique
Helvetica
Helvetica-Bold
Helvetica-BoldOblique
Helvetica-Oblique
Times-Bold
Times-BoldItalic
Times-Italic
Times-Roman

There is a bit of inconsistency there (there is "Times-Roman", but the  
bold version is not called "Times-Roman-Bold") but I think that's  
either Adobe's fault or it's part of the spec.

Assuming I need to recreate a Font object from those names, can I do  
so using FontFactory.getFont() by feeding it a String made up of  
letters up to the first hyphen?

--
Thomas Hauk
Shaggy Frog Software
www.shaggyfrog.com


------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate 
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the 
lucky parental unit.  See the prize list and enter to win: 
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.itextpdf.com/book/
Check the site with examples before you ask questions: 
http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/

Reply via email to