List of usage examples for com.lowagie.text.pdf PdfFormField setFieldName
public void setFieldName(String s)
From source file:at.reppeitsolutions.formbuilder.components.pdf.itext.ITextRadio.java
License:Open Source License
@Override public void cellLayout(PdfPCell cell, Rectangle rectangle, PdfContentByte[] canvases) { PdfWriter writer = canvases[0].getPdfWriter(); PdfFormField radiogroup = PdfFormField.createRadioButton(writer, true); radiogroup.setFieldName(UUID.randomUUID().toString()); if (locked) { radiogroup.setFieldFlags(BaseField.READ_ONLY); }/*from ww w .j a v a 2 s .c o m*/ RadioCheckField radio; for (int i = 0; i < values.length; i++) { try { Rectangle rect = getBoxRectangle(rectangle, i); radio = new RadioCheckField(writer, rect, null, UUID.randomUUID().toString()); radio.setBorderColor(GrayColor.GRAYBLACK); radio.setBackgroundColor(GrayColor.GRAYWHITE); radio.setCheckType(RadioCheckField.TYPE_CIRCLE); if (value != null && values[i].equals(value)) { radio.setChecked(true); } PdfFormField field = radio.getRadioField(); radiogroup.addKid(field); addBoxDescription(rectangle, i, values, canvases); } catch (IOException ex) { Logger.getLogger(ITextRadio.class.getName()).log(Level.SEVERE, null, ex); } catch (DocumentException ex) { Logger.getLogger(ITextRadio.class.getName()).log(Level.SEVERE, null, ex); } } writer.addAnnotation(radiogroup); }
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();/*from w w w .j ava2 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:com.geek.tutorial.itext.acroform.RadioCheckBoxForm.java
License:Open Source License
public RadioCheckBoxForm() throws Exception { Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("RadioCheckBoxForm.pdf")); document.open();/*from w w w . j a v a2 s . c o m*/ PdfContentByte cb = writer.getDirectContent(); BaseFont bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED); Rectangle rect; // Code 1 create radio button String[] radios = { "Radio1", "Radio2", "Radio3" }; PdfFormField radioField = PdfFormField.createRadioButton(writer, true); radioField.setFieldName("radioField"); radioField.setValueAsName(radios[0]); for (int i = 0; i < radios.length; i++) { rect = new Rectangle(40, 815 - i * 30, 60, 797 - i * 30); addRadioButton(writer, rect, radioField, radios[i], i == 0); cb.beginText(); cb.setFontAndSize(bf, 12); cb.showTextAligned(Element.ALIGN_LEFT, radios[i], 70, 802 - i * 30, 0); cb.endText(); } writer.addAnnotation(radioField); // Code 2 create checkbox button String[] options = { "Check1", "Check2", "Check3" }; for (int i = 0; i < options.length; i++) { rect = new Rectangle(160, 815 - i * 30, 180, 797 - i * 30); addCheckbox(writer, rect, options[i]); cb.beginText(); cb.setFontAndSize(bf, 12); cb.showTextAligned(Element.ALIGN_LEFT, options[i], 190, 802 - i * 30, 0); cb.endText(); } // Code 3 add function and button for showing state writer.addJavaScript( "function showState(){" + "app.alert('Radio:'+ this.getField('radioField').value +'\\n\\n'+" + "'Check1:'+this.getField('Check1').value +'\\n'+" + "'Check2:'+this.getField('Check2').value +'\\n'+" + "'Check3:'+this.getField('Check3').value);" + "}"); PushbuttonField push = new PushbuttonField(writer, new Rectangle(80, 710, 150, 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;/* w ww .j a va 2 s. com*/ } 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. ja v a 2s . 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); }
From source file:questions.forms.FormWithTooltips.java
public static void main(String[] args) { Document document = new Document(); try {/*from w ww . ja v a 2 s . c o m*/ PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT)); document.open(); PdfFormField person = PdfFormField.createEmpty(writer); person.setFieldName("person"); document.add(createTable(writer, person)); writer.addAnnotation(person); } catch (DocumentException de) { System.err.println(de.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } // step 5 document.close(); }
From source file:questions.forms.KidsOnDifferentPages.java
public static void createPdf() { Document document = new Document(); try {//from w w w. j a va 2s.c o m PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(FORM)); document.open(); // create the parent field and its kids PdfFormField person = PdfFormField.createEmpty(writer); person.setFieldName("person"); // one kid on page 1 TextField field1 = new TextField(writer, new Rectangle(0, 0), "name1"); PdfFormField kid1 = field1.getTextField(); kid1.setPlaceInPage(1); person.addKid(kid1); // another kid on page 2 TextField field2 = new TextField(writer, new Rectangle(0, 0), "name2"); PdfFormField kid2 = field2.getTextField(); kid2.setPlaceInPage(2); person.addKid(kid2); writer.addAnnotation(person); // now add the page content document.add(createTable(kid1)); document.newPage(); document.add(createTable(kid2)); } catch (DocumentException de) { System.err.println(de.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } document.close(); }
From source file:questions.forms.RadioButtonsOnDifferentPages.java
public static void main(String[] args) { Document document = new Document(); try {/* ww w. j av a 2 s. c om*/ PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT)); document.open(); PdfContentByte cb = writer.getDirectContent(); BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED); String[] languages = { "English", "French", "Dutch" }; Rectangle rect; // create radio button field and its kids PdfFormField language = PdfFormField.createRadioButton(writer, true); language.setFieldName("language"); language.setValueAsName(languages[0]); for (int i = 0; i < languages.length; i++) { rect = new Rectangle(40, 806 - i * 40, 60, 788 - i * 40); addRadioButton(writer, rect, language, languages[i], i == 0, writer.getPageNumber() + i); } writer.addAnnotation(language); // add the page content for (int i = 0; i < languages.length; i++) { cb.beginText(); cb.setFontAndSize(bf, 18); cb.showTextAligned(Element.ALIGN_LEFT, languages[i], 70, 790 - i * 40, 0); cb.endText(); document.newPage(); } } catch (Exception e) { e.printStackTrace(); } // step 5: we close the document document.close(); }
From source file:questions.javascript.AddJavaScriptToForm.java
public static void createPdf(String filename) throws IOException, DocumentException { Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename)); document.open();/*w ww .j a v a 2 s. c o m*/ BaseFont bf = BaseFont.createFont(); PdfContentByte directcontent = writer.getDirectContent(); directcontent.beginText(); directcontent.setFontAndSize(bf, 12); directcontent.showTextAligned(Element.ALIGN_LEFT, "Married?", 36, 770, 0); directcontent.showTextAligned(Element.ALIGN_LEFT, "YES", 58, 750, 0); directcontent.showTextAligned(Element.ALIGN_LEFT, "NO", 102, 750, 0); directcontent.showTextAligned(Element.ALIGN_LEFT, "Name partner?", 36, 730, 0); directcontent.endText(); PdfFormField married = PdfFormField.createRadioButton(writer, true); married.setFieldName("married"); married.setValueAsName("yes"); Rectangle rectYes = new Rectangle(40, 766, 56, 744); RadioCheckField yes = new RadioCheckField(writer, rectYes, null, "yes"); yes.setChecked(true); married.addKid(yes.getRadioField()); Rectangle rectNo = new Rectangle(84, 766, 100, 744); RadioCheckField no = new RadioCheckField(writer, rectNo, null, "no"); no.setChecked(false); married.addKid(no.getRadioField()); writer.addAnnotation(married); Rectangle rect = new Rectangle(40, 710, 200, 726); TextField partner = new TextField(writer, rect, "partner"); partner.setBorderColor(Color.BLACK); partner.setBorderWidth(0.5f); writer.addAnnotation(partner.getTextField()); document.close(); }