This isn't
directly supported by AcroFields' API. You'll have to dig under the covers
a bit:
1) Get the
field's "Item":
AcroFields.Item fldItem =
myAcroFields.getFieldItem("SomeField");
2) For each
instance of that field
for (int i = 0; i < fldItem.widgets.size(); ++i) {
3) Get the
field instance's rectangle from the widget (the screen representation of the
form)
PdfArray fieldRect = (PdfArray)
fldItem.widgets[i].get(PdfName.BBOX);
ArrayList rectData = fieldRect.getArrayList();
4) Translate
the array into rectangle info
double llx = ((PdfNumber)rectData.get( 0
)).doubleValue();
double lly =
((PdfNumber)rectData.get( 1 )).doubleValue();
double urx = ((PdfNumber)rectData.get( 2
)).doubleValue();
double ury =
((PdfNumber)rectData.get( 3
)).doubleValue();
com.lowagie.text.Rectangle rect = new com.lowagie.text.Rectangle( llx, lly, urx,
ury );
5) Do Stuff to the
rectangle
... // your code
here
6) Get a new PdfRectangle( decended from
PdfArray)
PdfRectangle
finalRect = new PdfRectangle( rect );
7) Write this new rectangle into the merged and widget
dictionaries for this field.
fldItem.widgets[i].put( PdfName.BBOX, finalRect
);
fldItem.merged[i].put( PdfName.BBOX, finalRect
);
}
<sarcasm>And that's all there is to
it!</sarcasm>
I just wrote all this code into the email... there
could easily be a bug or three in there. The "for" loop is only necessary
if there are multiple instances of the same field name. Otherwise, you can
"get away with" dropping that loop and sticking to widgets[0] and
merged[0]. This is often the case... but not always. Better safe
than sorry.
If you want to write more
efficent-but-implementation-dependant code, you could modify the PdfArray from
fldItem.widgets[i] directly. Due to the way "widgets" and "merged" is
built (for the moment) they share the same object, so modifying that object will
affect both. This efficiency gain is probably not worth the effort (and
risk) unless you're modifying a LARGE number of fields. If not, I/O will
dwarf any processing at this level.
The above code also fails to take page rotation into
account... PdfRectangle has a construct that allows you to pass in the
rotation. Item keeps a page reference for each instance, so you can look
up the rotation.
--Mark Storer
Senior Software Engineer
Cardiff Software
#include <disclaimer>
typedef std::Disclaimer<Cardiff> DisCard;
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]On Behalf Of [EMAIL PROTECTED]
Sent: Friday, May 19, 2006 4:43 AM
To: [email protected]
Subject: [iText-questions] (no subject)
Hi mailinglist,
i need a method (perhapes setFieldProperty) to change the width of an textfield.
does anybody know a solution for my problem?
is it possible?
background: i have a pdf document with a lot of formelements (textfields). some of these elements are in the middle of an text. depence what i fill in there is a big space or not.
(what i want to do is a individual letter-writing)
Greetings
Christian Schmidt
