List of usage examples for com.lowagie.text.pdf PdfFormField createEmpty
public static PdfFormField createEmpty(PdfWriter writer)
From source file:org.xhtmlrenderer.pdf.RadioButtonFormField.java
License:Open Source License
private void createField(RenderingContext c, ITextOutputDevice outputDevice, PdfContentByte cb, PdfWriter writer, PdfFormField group, RadioButtonFormField fieldElem, RadioButtonFormField checked) { Box box = fieldElem.getBox(); Element e = box.getElement(); String onValue = getValue(e); float width = outputDevice.getDeviceLength(fieldElem.getWidth()); float height = outputDevice.getDeviceLength(fieldElem.getHeight()); PdfFormField field = PdfFormField.createEmpty(writer); FSColor color = box.getStyle().getColor(); FSColor darker = box.getEffBackgroundColor(c).darkenColor(); createAppearances(cb, field, onValue, width, height, true, color, darker); createAppearances(cb, field, onValue, width, height, false, color, darker); field.setWidget(outputDevice.createTargetArea(c, box), PdfAnnotation.HIGHLIGHT_INVERT); // XXX createTargetArea already looks up the page, but hopefully a document // won't have enough radio buttons to matter Rectangle bounds = box.getContentAreaEdge(box.getAbsX(), box.getAbsY(), c); PageBox page = c.getRootLayer().getPage(c, bounds.y); field.setPlaceInPage(page.getPageNo() + 1); field.setBorderStyle(new PdfBorderDictionary(0.0f, 0)); field.setAppearanceState(fieldElem == checked ? onValue : OFF_STATE); if (isReadOnly(e)) { field.setFieldFlags(PdfFormField.FF_READ_ONLY); }/*from w w w .j ava 2 s .c om*/ group.addKid(field); }
From source file:questions.forms.FormWithTooltips.java
public static void main(String[] args) { Document document = new Document(); try {// ww w . ja v a 2s. co 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 ww . ja v a 2 s.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(); }