I have created an interactive PDF Form dynamically from a bean. It has multiple
form fields like Textbox, selectbox,checkbox n so on...
I am trying to figure out, how to hide a form fieled when a particular option
of checkbox/radiobutton/selectbox is selected. Where do I need to trigger the
event after creating a javascript function using writer.addJavaScript(..)? Is
it at the parent checkbox level or at the option level? How do I call the
Javascript, what wud be the action??
Any help regarding the same would be highly appreciated.....The piece of code
am trying to execute is as follows:
PdfWriter writer = PdfWriter.getInstance(document,new
FileOutputStream("C://SamplePDFForm.pdf"));
document.open();
writer.addJavaScript(
"function actionOnChange(){var question=this.getField('Component(s)
Origin');app.alert('<P>Component(s) Origin</P>:'+this.getField('<P>Component(s)
Origin</P>'));if(this.getField('Ruminant.Bovine').value=='On')){question.display
= display.hidden;app.alert('Bovine
value:'+this.getField('Ruminant.Bovine').value)} else question.display =
display.visible;}",false);
PdfPTable checkboxOptionsTable = new PdfPTable(3);
checkboxOptionsTable.setWidthPercentage(100f);
float[] relativeWidths = {5.0f,50.0f,45.0f};
checkboxOptionsTable.setWidths(relativeWidths);
PdfFormField multipleCheckbox = PdfFormField.createCheckBox(writer);
multipleCheckbox.setButton(PdfFormField.FF_MULTISELECT);
multipleCheckbox.setFieldName(questionDataVO.getQuestionText().trim());
PdfAppearance cbOff = cb.createAppearance(10, 10);
PdfAppearance cbOn = cb.createAppearance(10, 10);
cbOff.rectangle(1, 1, 8, 8);
cbOff.stroke();
cbOn.rectangle(1, 1, 8, 8);
cbOn.stroke();
cbOn.moveTo(1, 1);
cbOn.lineTo(9, 9);
cbOn.moveTo(1, 9);
cbOn.lineTo(9, 1);
cbOn.fillStroke();
laQuestionOptions =
questionBO.getAllQuestionOptions(questionDataVO.getQuestionId());
for (int j = 0; j<laQuestionOptions.size();j++){
QuestionOptionsVO questionOptionsVO = (QuestionOptionsVO)
laQuestionOptions.get(j);
questionOptionsVO = (QuestionOptionsVO) laQuestionOptions.get(j);
PdfFormField multipleCheckbox1 = PdfFormField.createEmpty(writer);
multipleCheckbox1.setFieldName(questionOptionsVO.getControlLabelText());
multipleCheckbox1.setValueAsName(questionOptionsVO.getControlLabelText());
multipleCheckbox1.setValueAsString(questionOptionsVO.getControlLabelValue());
multipleCheckbox1.setAppearanceState("Off");
multipleCheckbox1.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, "Off", cbOff);
multipleCheckbox1.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, "On", cbOn);
if("Ruminant".equals(questionDataVO.getQuestionText())&
"Bovine".equals(questionOptionsVO.getControlLabelText()))
{
multipleCheckbox1.setAdditionalActions(PdfFormField.AA_DOWN,PdfAction.javaScript("actionOnChange();\r",writer));
}
multipleCheckbox.addKid(multipleCheckbox1);
PdfPCell cell = new PdfPCell();
cell.setCellEvent(new
CheckboxFormField(writer,questionOptionsVO.getControlLabelText(),multipleCheckbox1));
cell.setBorderColor(Color.white);
cell.setBorder(Rectangle.NO_BORDER);
checkboxOptionsTable.addCell(cell);
}
Thanks
Swapna.
swapna
---------------------------------
5, 50, 500, 5000 - Store N number of mails in your inbox. Click here.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/