Thanks Mark for the response and detailed explanation. This solved my problem. 
Thanks again :)

With thanks and regards,
S.K.Ramachandran




Date: Wed, 18 Nov 2009 09:52:48 -0800
From: "Mark Storer" <[email protected]>
Subject: Re: [iText-questions] Font size from a text box
To: "Post all your questions about iText here"
        <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"

You'll need to parse the field's /DA (default appearance) string:

for (Iterator i = fields.keySet().iterator(); i.hasNext();) {
  key = (String) i.next();

  AcroFields.Item fldItem = (AcroFields.Item)fields.get( key );
  PdfDictionary merged = fldItem.getMerged( 0 );
  PdfString defaultApp = merged.getAsString( PdfName.DA );
  String appStr = defaultApp.toString();
  ...
}

The string will look something like "/Helv 10 Tf 0 0 0 rg".  PDF content is 
written in "reverse polish notation".  You want the second parameter for the 
"Tf" command, which will be a number.  Tf: text font.  1st param: font name, 
2nd param: font size.  So in this case, the font size is 10pt.

Note that there's no particular requirement to the order in which these 
operators are present, and other operators are permitted as well.

The font size can be a float, it doesn't have to be a whole number.  It can 
also be ZERO, indicating that the viewer should render the text it will all be 
displayed within the field's borders (within reason, it won't go below 4pt).  
At that point, the only way to know the actual font size being used is to parse 
the field's appearance stream.  WHich isn't all that much harder.  It really 
boils down to solving the same parsing problem, getting the string to parse is 
a tad more involved (and may be entirely abscent in the case of "half baked" 
forms, forms with the "NeedAppearances" flag set).

--Mark Storer
  Senior Software Engineer
  Cardiff.com

#include <disclaimer>
typedef std::Disclaimer<Cardiff> DisCard;

-----Original Message-----
From: [email protected] [mailto:[email protected]]
Sent: Wednesday, November 18, 2009 3:27 AM
To: [email protected]
Subject: [iText-questions] Font size from a text box


Hi,

I am reading the form fields from the PDF using Acrofields. I would like to get 
the value and font size of the Text fields. I am getting the value of using 
form.getField(key). How do I get the fontsize of the text field?

Your inputs will be highly appreciated.

Coder Snippet::

PdfReader reader = new PdfReader("c:\\register_form2.pdf");
AcroFields form = reader.getAcroFields(); HashMap fields = form.getFields(); 
String key; for (Iterator i = fields.keySet().iterator(); i.hasNext();) {
     key = (String) i.next();
     switch (form.getFieldType(key))
    {
      case AcroFields.FIELD_TYPE_TEXT:
           System.out.println("Text");
           System.out.println("Value is" + form.getField(key));
           break;
      default:
           System.out.println("othes");
   }
}

With thanks and regards,

S.K.Ramachandran


******************************************************************************************************************************
"This message and any attachments are solely for the intended recipient and may 
contain Birlasoft confidential or privileged information. If you are not the 
intended recipient,any disclosure,copying, use, or distribution of the 
information included in this message and any attachments is 
prohibited. If you have received this communication in error, please notify us 
by reply e-mail([email protected]) immediately and permanently delete 
this message and any attachments. Thank you."
************************************************************************************************************************************************************************


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
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
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