That's a bit harder. You need to get the Default Appearance string,
"DA", from the AcroFields.Item for the field. From there, you parse out
the /Tf (text font, or something to that effect) command to discover the
font resource name.
Fortunately most font resource names are standardized for common fonts.
Helv: Helvetica
HeBo: Helvetica Bold
Etc.
If you cannot deduce the font name from the resource name, you need to
look it up. It should be stored in the acroform dictionary under /DR
(default resources), under /Fonts.
There might be A Better Way, but nothing comes to mind. When you set a
field's value, it needs to determine the correct font to render the
field's new appearance... but I rather doubt it's done in an accessible
way (through the normal public interfaces).
Aha! There sure is.
AcroFields.decodeGenericDictionary(). It'll populate a
BaseField-derived class from a merged dictionary
(AcroField.Item.getMerged(n)).
You can then: myField.getFont().getFullFontName();
So something like:
String getFieldFont(AcroFields acroFields, String fldName) {
AcroFields.Item item = acroFields.getFieldItem(fldName);
PdfDictionary merged = item.getMerged(0);
// we're cheating a lot with all those nulls, might not work.
TextField fld = new TextField(null, null, null);
acroFields.decodeGenericDictionary(merged, fld);
return fld.getFont().getFullName();
}
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.
--Mark Storer
Senior Software Engineer
Cardiff.com
import legalese.Disclaimer;
Disclaimer<Cardiff> DisCard = null;
> -----Original Message-----
> From: Thomas Hauk [mailto:[email protected]]
> Sent: Wednesday, June 09, 2010 4:21 PM
> To: Post all your questions about iText here
> Subject: Spam: [iText-questions] Getting font information for form
fields
>
> I can get an AcroFields object from a PdfStamper, and from that I can
> not only get the name of each field, but its dimensions, as well. How
> can I also get the font specified for each form field?
>
> --
> 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/
>
>
> No virus found in this incoming message.
> Checked by AVG - www.avg.com
> Version: 9.0.829 / Virus Database: 271.1.1/2913 - Release Date:
06/08/10
> 23:35:00
------------------------------------------------------------------------------
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/