Here is my problem: I want to set the font size of a Text Field to zero
ONLY if the contents are too large for the Text Field, which will auto-size
the contents. If the contents fit, then I want to preserve the original
font. Is this possible?
Here is what I started trying... I used AcroFields.getFieldItem(fieldName)
to retrieve the Item object, then further down the line I retrieved the "DA"
PdfDictionary. The code is copied below. I was hoping to use the font name
and size to create a new Chunk and then use Chunk.getWidthPoint() to get the
width and compare that to the Text Field's width. However, I have two
problems:
1. The font returned from the PdfObject below returns "/Helv 8 Tf 0 g",
and "Helv" does not match with any of the iText fonts that I could find.
2. I'm not sure if I can retrieve the width of the Text Field in order
to compare it to Chunk.getWidthPoint().
Does anyone have a solution? Also, how can you know if text will overfill a
multi-line Text Field? Thank you!
Toby
--------------- Start of Code -----------------------
AcroFields.Item item = form.getFieldItem(fieldName);
PdfDictionary dict;
PdfName name;
for (Iterator i = item.merged.iterator(); i.hasNext(); ) {
dict = (PdfDictionary) i.next();
// Retrieve the "DA" dictionary
PdfObject obj = dict.get(new PdfName("DA"));
// The following prints "/Helv 8 Tf 0 g", which is a Helvetica font with
a size of 8.
System.out.println("DA = '" + obj + "'");
// The following prints "Helvetica".
System.out.println("BaseFont.HELVETICA = " + BaseFont.HELVETICA);
// The following prints "1".
System.out.println("Font.HELVETICA = " + Font.HELVETICA);
System.out.println("------------------------------------");
}
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/