AcroFields doesn't provide a high-level function for this, you'll have to go
"under the covers".
1) Get the fields AcroFields.Item:
Item fldItem = myAcroFields.getFieldItem( "FieldName" );
2) Figure out what your actual default value needs to be.
Text fields use a PdfString, everything else uses a PdfName.
List fields with an /Opt entry need PdfNames with the index into the Opt array
as their value
Check boxes and radio buttons need PdfNames with the string value, except that
radio buttons can also have an /Opt array, requiring an index again.
PdfObject defValObj = null;
defValObj = new PdfString( "fieldValue" );
or
defValObj = new PdfName( "fieldValue" ); // pdf names can only contain ascii,
that's why fields support the /Opt array.
You can have a look at the source to AcroFields.setField() to see which types
use what.
3) Stuff the default value into all the Item.values ArrayList entries. In many
cases, they'll all be the same object, but better safe than sorry.
You may also want to add the value to the "merged" ArrayList entries in case
you need to check it again later.
for (int i = 0; i < Item.values.size(); ++i) {
PdfDictionary fieldDict = (PdfDictionary) fldItem.values.get( i );
fieldDict.put( PdfName.DV, defValObj );
fieldDict = (PdfDictionary) fldItem.merged.get( i ); // all members of
Item are parallel (same length), though not all are PdfDictionary
fieldDict.put( PdfName.DV, defValObj );
}
Come to think of it, it might be easier to make a copy of SetField() and start
trimming & changing rather than writing a new function from scratch. You'd
want to change all the "dict.put( PdfName.V, ...) " to "dict.put( PdfName.DV,
... )", and remove all the code related to updating appearances (anything
related to "PdfName.AP", getAppearance(), and so on).
And once you're done, you can submit it back to Paulo for the benefit of the
rest of the world.
--Mark Storer
Senior Software Engineer
Cardiff.com
#include <disclaimer>
typedef std::Disclaimer<Cardiff> DisCard;
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Amit Sharma
Sent: Thursday, February 01, 2007 8:54 AM
To: Post all your questions about iText here
Subject: [iText-questions] AcroFields Help Required
Hi,
Is there anyway in which I can set the Default value of the Pdf fields using
Acrofield object.
I have seen method "setfield" but does nt set the default value of the pdf form
Thanks
Amit
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
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/