List of usage examples for com.lowagie.text.pdf PdfFormField setValueAsString
public void setValueAsString(String s)
From source file:com.geek.tutorial.itext.acroform.ListFieldForm.java
License:Open Source License
public ListFieldForm() throws Exception { Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("ListFieldForm.pdf")); document.open();//w ww. ja v a 2 s. c o m // Code 1 String options[] = { "PS3", "XBOX 360", "Wii", "PSP", "NDS", "GBA" }; // Code 2 create drop-down list PdfFormField dropDown = PdfFormField.createCombo(writer, true, options, 0); dropDown.setWidget(new Rectangle(50, 785, 120, 800), PdfAnnotation.HIGHLIGHT_INVERT); dropDown.setFieldName("dropDownList"); dropDown.setValueAsString("PS3"); dropDown.setMKBorderColor(Color.BLACK); writer.addAnnotation(dropDown); // Code 3 create scrollable list TextField scrollableList = new TextField(writer, new Rectangle(150, 740, 250, 800), "scrollableList"); scrollableList.setBackgroundColor(Color.WHITE); scrollableList.setBorderColor(Color.BLUE); scrollableList.setBorderWidth(2); scrollableList.setBorderStyle(PdfBorderDictionary.STYLE_SOLID); scrollableList.setFontSize(10); scrollableList.setChoices(options); scrollableList.setChoiceSelection(0); writer.addAnnotation(scrollableList.getListField()); // Code 4 add function and button for showing state writer.addJavaScript( "function showState(){" + "app.alert('DropDown:'+ this.getField('dropDownList').value +'\\n'+" + "'Scrollable List:'+this.getField('scrollableList').value);" + "}"); PushbuttonField push = new PushbuttonField(writer, new Rectangle(70, 710, 140, 730), "pushAction"); push.setBackgroundColor(Color.LIGHT_GRAY); push.setBorderColor(Color.GRAY); push.setText("Show State"); push.setBorderStyle(PdfBorderDictionary.STYLE_BEVELED); push.setTextColor(Color.BLACK); PdfFormField pushbutton = push.getField(); pushbutton.setAction(PdfAction.javaScript("showState()", writer)); writer.addAnnotation(pushbutton); document.close(); }
From source file:org.xhtmlrenderer.pdf.RadioButtonFormField.java
License:Open Source License
public void paint(RenderingContext c, ITextOutputDevice outputDevice, BlockBox box) { String fieldName = getFieldName(outputDevice, box.getElement()); List radioBoxes = _factory.getRadioButtons(fieldName); // iText wants all radio buttons in a group added at once across all pages if (radioBoxes == null) { // Already added to document return;//from ww w. jav a 2 s . c o m } PdfContentByte cb = outputDevice.getCurrentPage(); PdfWriter writer = outputDevice.getWriter(); PdfFormField group = PdfFormField.createRadioButton(writer, true); group.setFieldName(fieldName); RadioButtonFormField checked = getChecked(radioBoxes); if (checked != null) { group.setValueAsString(getValue(checked.getBox().getElement())); } for (Iterator i = radioBoxes.iterator(); i.hasNext();) { RadioButtonFormField fieldElem = (RadioButtonFormField) i.next(); createField(c, outputDevice, cb, writer, group, fieldElem, checked); } writer.addAnnotation(group); _factory.remove(fieldName); }
From source file:org.xhtmlrenderer.pdf.SelectFormField.java
License:Open Source License
public void paint(RenderingContext c, ITextOutputDevice outputDevice, BlockBox box) { PdfWriter writer = outputDevice.getWriter(); String[][] options = getPDFOptions(); int selectedIndex = getSelectedIndex(); PdfFormField field; /*//from ww w.java 2 s . c om * Comment out for now. We need to draw an appropriate appearance for * this to work correctly. */ /* if (isMultiple(box.getElement())) { field = PdfFormField.createList(writer, options, selectedIndex); } else { field = PdfFormField.createCombo(writer, false, options, selectedIndex); } */ field = PdfFormField.createCombo(writer, false, options, selectedIndex); field.setWidget(outputDevice.createLocalTargetArea(c, box), PdfAnnotation.HIGHLIGHT_INVERT); field.setFieldName(getFieldName(outputDevice, box.getElement())); if (options.length > 0) { field.setValueAsString(options[selectedIndex][0]); } createAppearance(c, outputDevice, box, field); if (isReadOnly(box.getElement())) { field.setFieldFlags(PdfFormField.FF_READ_ONLY); } /* if (isMultiple(box.getElement())) { field.setFieldFlags(PdfFormField.FF_MULTISELECT); } */ writer.addAnnotation(field); }