List of usage examples for com.lowagie.text.pdf TextField TextField
public TextField(PdfWriter writer, Rectangle box, String fieldName)
TextField
. From source file:corner.orm.tapestry.pdf.service.FieldCreator.java
License:Apache License
/** * @see corner.orm.tapestry.pdf.service.IFieldCreator#createTextField(com.lowagie.text.pdf.PdfWriter, com.lowagie.text.Rectangle, java.lang.String) *//*from ww w .j av a2 s . c o m*/ public TextField createTextField(PdfWriter writer, Rectangle rec, String name) { Defense.notNull(name, "field name"); if (alreadyExistFields.contains(name)) { //? name = createUniqueName(); } TextField textField = new TextField(writer, rec, name); textField.setOptions(TextField.READ_ONLY); //? alreadyExistFields.add(name); return textField; }
From source file:net.sf.jasperreports.forms.textinput.TextInputElementPdfHandler.java
License:Open Source License
public void exportElement(JRPdfExporterContext exporterContext, JRGenericPrintElement element) { PdfWriter writer = exporterContext.getPdfWriter(); JasperPrint jasperPrint = exporterContext.getExportedReport(); JRPrintText printText = (JRPrintText) element .getParameterValue(TextInputElement.PARAMETER_PRINT_TEXT_ELEMENT); if (printText == null) //FIXMEINPUT deal with xml serialization {//from www. ja v a 2 s . co m return; } Rectangle rectangle = new Rectangle(element.getX() + exporterContext.getOffsetX(), jasperPrint.getPageHeight() - element.getY() - exporterContext.getOffsetY(), element.getX() + exporterContext.getOffsetX() + element.getWidth(), jasperPrint.getPageHeight() - element.getY() - exporterContext.getOffsetY() - element.getHeight()); TextField text = new TextField(writer, rectangle, getFieldName(element)); text.setBackgroundColor(printText.getBackcolor()); text.setTextColor(printText.getForecolor()); text.setText(printText.getFullText()); text.setDefaultText("default:" + printText.getFullText()); // text.setBackgroundColor(element.getBackcolor()); // text.setTextColor(element.getForecolor()); // text.setText(getText(element)); // text.setDefaultText(getDefaultText(element)); //FIXME: dynamic settings below: // text.setAlignment(Element.ALIGN_LEFT); // text.setBorderColor(Color.BLACK); // text.setBorderWidth(TextField.BORDER_WIDTH_THIN); // text.setBorderStyle(PdfBorderDictionary.STYLE_INSET); // text.setChoiceExports(null); // text.setChoices(null); // text.setChoiceSelection(0); // text.setExtensionFont(null); // text.setExtraMargin(0, 0); // try{ // text.setFont(BaseFont.createFont(BaseFont.COURIER, BaseFont.CP1250, true)); // }catch(Exception e){ // throw new JRRuntimeException(e); // } text.setFontSize(printText.getFontsize()); if (Boolean.TRUE.equals(element.getParameterValue(TextInputElement.PARAMETER_MULTI_LINE))) { text.setOptions(TextField.MULTILINE); } // text.setRotation(90); // text.setVisibility(TextField.VISIBLE); try { PdfFormField field = text.getTextField(); writer.addAnnotation(field); } catch (Exception e) { throw new JRRuntimeException(e); } }
From source file:org.xhtmlrenderer.pdf.TextFormField.java
License:Open Source License
public void paint(RenderingContext c, ITextOutputDevice outputDevice, BlockBox box) { PdfWriter writer = outputDevice.getWriter(); Element elem = box.getElement(); Rectangle targetArea = outputDevice.createLocalTargetArea(c, box); TextField field = new TextField(writer, targetArea, getFieldName(outputDevice, elem)); String value = getValue(elem); field.setText(value);/*from w w w . java2 s . co m*/ try { PdfFormField formField = field.getTextField(); createAppearance(c, outputDevice, box, formField, value); //TODO add max length back in if (isReadOnly(elem)) { formField.setFieldFlags(PdfFormField.FF_READ_ONLY); } writer.addAnnotation(formField); } catch (IOException ioe) { System.out.println(ioe); } catch (DocumentException de) { System.out.println(de); } }
From source file:questions.forms.AddFieldToExistingForm.java
public static void main(String[] args) { PdfReader reader;/*from w w w . j a v a 2 s . c o m*/ try { reader = new PdfReader(FORM); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(RESULT)); TextField tf = new TextField(stamper.getWriter(), new Rectangle(100, 760, 400, 785), "added_field"); tf.setText("\u00e4\u00f4\u00df"); tf.setOptions(TextField.READ_ONLY); stamper.addAnnotation(tf.getTextField(), 1); AcroFields form = stamper.getAcroFields(); form.setField("Who", "\u00e4\u00f3\u00df\u00f4"); stamper.close(); } catch (IOException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } }
From source file:questions.forms.FormWithTooltips.java
private static PdfPTable createTable(PdfWriter writer, PdfFormField parent) throws IOException, DocumentException { PdfPTable table = new PdfPTable(2); PdfPCell cell;/* w ww . j a v a 2 s . c o m*/ TextField field; table.getDefaultCell().setPadding(5f); table.addCell("Your name:"); cell = new PdfPCell(); field = new TextField(writer, new Rectangle(0, 0), "name"); field.setFontSize(12); cell.setCellEvent(new FormWithTooltips(parent, field.getTextField(), 1, "Your name")); table.addCell(cell); table.addCell("Your home address:"); cell = new PdfPCell(); field = new TextField(writer, new Rectangle(0, 0), "address"); field.setFontSize(12); cell.setCellEvent(new FormWithTooltips(parent, field.getTextField(), 1, "Street and number")); table.addCell(cell); table.addCell("Postal code:"); cell = new PdfPCell(); field = new TextField(writer, new Rectangle(0, 0), "postal_code"); field.setFontSize(12); cell.setCellEvent(new FormWithTooltips(parent, field.getTextField(), 1, "Postal code")); table.addCell(cell); table.addCell("City:"); cell = new PdfPCell(); field = new TextField(writer, new Rectangle(0, 0), "city"); field.setFontSize(12); cell.setCellEvent(new FormWithTooltips(parent, field.getTextField(), 1, "City")); table.addCell(cell); table.addCell("Country:"); cell = new PdfPCell(); field = new TextField(writer, new Rectangle(0, 0), "country"); field.setFontSize(12); cell.setCellEvent(new FormWithTooltips(parent, field.getTextField(), 1, "Country")); table.addCell(cell); table.addCell("Your email address:"); cell = new PdfPCell(); field = new TextField(writer, new Rectangle(0, 0), "email"); field.setFontSize(12); cell.setCellEvent(new FormWithTooltips(parent, field.getTextField(), 1, "mail address")); table.addCell(cell); return table; }
From source file:questions.forms.KidsOnDifferentPages.java
public static void createPdf() { Document document = new Document(); try {//from w w w . jav a 2 s .c om 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.MultipleChoice.java
public static void createPdf() throws IOException, DocumentException { // step 1/*w ww . j a va2 s .com*/ Document document = new Document(); // step 2 PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT)); // step 3 document.open(); // step 4 TextField field = new TextField(writer, new Rectangle(36, 750, 144, 806), "iText"); field.setFontSize(9); String[] list_options = { "JAVA", "C", "CS", "VB", "PHP" }; field.setChoiceExports(list_options); String[] list_values = { "Java", "C/C++", "C#", "VB", "PHP" }; field.setChoices(list_values); PdfFormField f = field.getListField(); f.setFieldFlags(PdfFormField.FF_MULTISELECT); f.put(PdfName.I, new PdfArray(new int[] { 0, 2 })); writer.addAnnotation(f); // step 5 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();//from ww w . ja v a2 s . co 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(); }