Look at the AcroFields source.
Paulo
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On
> Behalf Of Toby
> Sent: Tuesday, January 15, 2008 5:09 AM
> To: [email protected]
> Subject: [iText-questions] Resize Text Field contents to fit
> box,but only if the contents are too big
>
> 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.n
> et/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/
>
Aviso Legal:
Esta mensagem é destinada exclusivamente ao destinatário. Pode conter
informação confidencial ou legalmente protegida. A incorrecta transmissão desta
mensagem não significa a perca de confidencialidade. Se esta mensagem for
recebida por engano, por favor envie-a de volta para o remetente e apague-a do
seu sistema de imediato. É proibido a qualquer pessoa que não o destinatário de
usar, revelar ou distribuir qualquer parte desta mensagem.
Disclaimer:
This message is destined exclusively to the intended receiver. It may contain
confidential or legally protected information. The incorrect transmission of
this message does not mean the loss of its confidentiality. If this message is
received by mistake, please send it back to the sender and delete it from your
system immediately. It is forbidden to any person who is not the intended
receiver to use, distribute or copy any part of this message.
-------------------------------------------------------------------------
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/