Parent fields can pass attributes down to their children, including /DA.  The 
merged dictionary contains all the "current" values, so I always use that when 
I'm reading something.
 
For example:  In a radio group, getValue(X) will return the parent of the radio 
group for any valid X, while getWidget(X) will *probably* contain the /DA for 
the given radio button.
 
 
That's for *reading*.  When *writing*, it really depends on what it is that is 
being set.  I'll write to both merged and value/widget depending on whether its 
"appearance" related or "field" related.  Widget and Value are often the same 
dictionary, but you can't depend on it.  That's why I wrote 
AcroFields.Item.writeToAll().  I found myself writing a lot of code to iterate 
over all the instances in an item and set a value in merged && (widget ^| 
value).  Being a "constructively lazy" programmer, I wrote a function to do it 
for me.
 
Here's some code from an older revision of AcroFields.setListSelection (SVN 
revision 3657):
http://itext.svn.sourceforge.net/viewvc/itext/trunk/src/core/com/lowagie/text/pdf/AcroFields.java?revision=3657
 
<http://itext.svn.sourceforge.net/viewvc/itext/trunk/src/core/com/lowagie/text/pdf/AcroFields.java?revision=3657&view=markup>
 &view=markup
 
1371 for (int idx = 0; idx < item.values.size(); ++idx) { 
1372 PdfDictionary valueDic = (PdfDictionary)item.values.get(idx); 
1373 valueDic.remove(PdfName.V); 
1374 valueDic.put(PdfName.I, array); 
1375 markUsed(valueDic); 
1376 PdfDictionary merged = (PdfDictionary)item.merged.get(idx); 
1377 merged.put(PdfName.I, array); 
1378 merged.remove(PdfName.V); 
1379 PdfDictionary widget = (PdfDictionary)item.widgets.get(idx); 
1380 widget.remove(PdfName.AP); 
1381 merged.remove(PdfName.AP); 
1382 markUsed(widget); 
1383 } 
 
And here's the current code (SVN revision 4065):
http://itext.svn.sourceforge.net/viewvc/itext/trunk/src/core/com/lowagie/text/pdf/AcroFields.java?revision=4065
 
<http://itext.svn.sourceforge.net/viewvc/itext/trunk/src/core/com/lowagie/text/pdf/AcroFields.java?revision=4065&view=markup>
 &view=markup
 
1446 item.writeToAll(PdfName.I, array, Item.WRITE_MERGED | Item.WRITE_VALUE);
1447 item.writeToAll(PdfName.V, null, Item.WRITE_MERGED | Item.WRITE_VALUE);
1448 item.writeToAll(PdfName.AP, null, Item.WRITE_MERGED | Item.WRITE_WIDGET); 
1449 item.markUsed( this, Item.WRITE_VALUE | Item.WRITE_WIDGET );
 
You don't have to write to merged at all IF you know you're not going to read 
merged again later.  If you only set a key/value in the Merged dictionary, it 
won't be reflected in your output PDF.  Merged dictionaries are never written 
to a PDF, they're a convenience so you don't have to go hunting up the /Parent 
references looking for some key/value pair that might have been inheritted.  
I'm a rather form-centric iText user, so I'm DEEPLY GRATEFUL that I can check 
just the one place every time.
 
NOTE: I've found some Odd Behavior in Acrobat/Reader 9.x when the /V (value) is 
missing.  Check boxes will DISPLAY based on the /AS, but if you export as FDF 
or query the field value with JS, it's always "Off"!  That's goddam insideous.  
It LOOKS RIGHT, but isn't.  Grr.  I recently noticed that mutli-select lists 
are doing to same thing (internally).  Setting the /V should take care of it, 
I'll be checking in a patch within a week or so.

--Mark Storer 
  Senior Software Engineer 
  Cardiff.com

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

-----Original Message-----
From: Iliadis Yannis [mailto:[email protected]]
Sent: Thursday, November 19, 2009 1:48 AM
To: Post all your questions about iText here
Subject: Re: [iText-questions] Font size from a text box


Hi Mark,

I saw that you used the getMerged(0) method to retrieve the dictionary and not 
the getValue(0).

I tried both in an example and got the same result.

So my question is, why you choose the first in favor over the second?

Yannis Iliadis



2009/11/19 < ramachandran.sk@ birlasoft.com>



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: ramachandran.sk@ BIRLASOFT.COM [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/



------------------------------------------------------------------------------
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