Hi,
I have just started working on iText API and adobe PDF forms lately.
I have been looking for XFA support through iText API for the forms
designed using Adobe Designer.
Let me explain what am I doing using iText API and the adobe forms.
I have some pdf templates designed using Adobe Designer. Using iText API
I was able to populate the pdf form data and could access the same.
But now the requirement is that I need to populate the pdf form's combo
box dynamically using iText API and when user selects any of the options
in the drop down, then I need to populate some other fields in the pdf,
depending on the drop down selection.
a) I was able to populate the drop down list but adobe XFA
javascript does n't idenfity the content I have added dynamically. So I
could n't find a way to get the selected drop down value or index.
FormsAction formsAction = new
FormsAction();
// Getting the clientLocations to be populated...
List<ClientLocationValueObject> clientLocationList =
formsAction.getClientLocations(this.clientId);
String address1 = null;
String address2 = null;
String city = null;
ArrayList<String> locationIds = new
ArrayList<String>();
ArrayList<String> locationNames =
new ArrayList<String>();
locationIds.add("-1");
locationNames.add("--------Select
Location--------");
AcroFields form =
stamper.getAcroFields();
for (int i = 0; i <
clientLocationList.size(); i++) {
ClientLocationValueObject clientLocVO = clientLocationList.get(i);
locationIds.add(clientLocVO.getId().toString());
locationNames.add(clientLocVO.getName());
address1 +=
clientLocVO.getAddress1();
address2 +=
clientLocVO.getAddress2();
city +=
clientLocVO.getCity();
}
// to populate the options and
values for the combo box
String[] combo_options = new String[locationIds.size()];
String[] combo_values = new
String[locationNames.size()];
for (int i = 0; i <
locationIds.size(); i++) {
combo_options[i] =
locationIds.get(i);
combo_values[i] =
locationNames.get(i);
}
// Setting combo box values
dynamically
form.setListOption("F[0].P1[0].clientLocation[0]", combo_options,
combo_values);
form.setField("F[0].P1[0].clientLocation[0]", combo_options[0]);
// but the above dynamically
populated data is not identified by adobe designer xfa javascript
Other alternative I tried to solve the above problem is :
b) I tried creating the combo box using iText API and then trying to get
the field using adobe javascript. Using this approach also, I could n't
get the selected content of the drop down list.
Please find out the code snippet that I was using
2)
Rectangle rect = new Rectangle(91, 650, 244, 665);
PdfWriter writer =
stamper.getWriter();
/* chapter15/ChoiceFields.java */
String options[] = combo_values;
// creating a new combo box using
iText API
PdfFormField combo = PdfFormField.createCombo(writer, true, options, 0);
combo.setFieldName("F[0].P1[0].testClientLocation[0]");
combo.setValueAsString(options[0]);
//combo.setAppearance);
//combo.setWidget(rect,
PdfName.FIELDS);
//combo.setWidget(rect,
PdfName.FIELDS);
combo.setWidget(rect,
PdfAnnotation.HIGHLIGHT_OUTLINE);
String comboMsg = "hello";
String script = "app.alert('coming
here');";
script +=
"app.alert(this.getField('address1').value);";
// if we create a combo box using iText, it would be an acro field
right? So this.getField("name") should return that element, but it
returns null
script += "this.getField('address1').value='" + address1 + "';";
//combo.setAdditionalActions(new
PdfName("K"),
//
PdfAction.javaScript("app.alert('COMB got the focus');", writer));
combo.setAdditionalActions(new
PdfName("K"),
PdfAction.javaScript(script, writer));
stamper.addAnnotation(combo, 1);
}
Could you suggest me if it is possible to resolve my problem using iText
API? Or would you suggest me if I could go for any other API which
provides good support for xfa javascript and dynamic pdf forms designed
using Adobe Designer.
Any help or suggestion provided is greatly appreciated.
Thanks in anticipation.
Regards
Siva
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
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/