Java Code Examples for com.lowagie.text.pdf.TextField#getTextField()
The following examples show how to use
com.lowagie.text.pdf.TextField#getTextField() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OptionalContentTest.java From itext2 with GNU Lesser General Public License v3.0 | 7 votes |
/** * Demonstrates the use of layers. * * @param args * no arguments needed */ @Test public void main() throws Exception { // step 1: creation of a document-object Document document = new Document(PageSize.A4, 50, 50, 50, 50); // step 2: creation of the writer PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("optionalcontent.pdf")); writer.setPdfVersion(PdfWriter.VERSION_1_5); writer.setViewerPreferences(PdfWriter.PageModeUseOC); // step 3: opening the document document.open(); // step 4: content PdfContentByte cb = writer.getDirectContent(); Phrase explanation = new Phrase( "Automatic layers, form fields, images, templates and actions", new Font(Font.HELVETICA, 18, Font.BOLD, Color.red)); ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, explanation, 50, 650, 0); PdfLayer l1 = new PdfLayer("Layer 1", writer); PdfLayer l2 = new PdfLayer("Layer 2", writer); PdfLayer l3 = new PdfLayer("Layer 3", writer); PdfLayer l4 = new PdfLayer("Form and XObject Layer", writer); PdfLayerMembership m1 = new PdfLayerMembership(writer); m1.addMember(l2); m1.addMember(l3); Phrase p1 = new Phrase("Text in layer 1"); Phrase p2 = new Phrase("Text in layer 2 or layer 3"); Phrase p3 = new Phrase("Text in layer 3"); cb.beginLayer(l1); ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p1, 50, 600, 0f); cb.endLayer(); cb.beginLayer(m1); ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p2, 50, 550, 0); cb.endLayer(); cb.beginLayer(l3); ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p3, 50, 500, 0); cb.endLayer(); TextField ff = new TextField(writer, new Rectangle(200, 600, 300, 620), "field1"); ff.setBorderColor(Color.blue); ff.setBorderStyle(PdfBorderDictionary.STYLE_SOLID); ff.setBorderWidth(TextField.BORDER_WIDTH_THIN); ff.setText("I'm a form field"); PdfFormField form = ff.getTextField(); form.setLayer(l4); writer.addAnnotation(form); Image img = Image.getInstance(PdfTestBase.RESOURCES_DIR + "pngnow.png"); img.setLayer(l4); img.setAbsolutePosition(200, 550); cb.addImage(img); PdfTemplate tp = cb.createTemplate(100, 20); Phrase pt = new Phrase("I'm a template", new Font(Font.HELVETICA, 12, Font.NORMAL, Color.magenta)); ColumnText.showTextAligned(tp, Element.ALIGN_LEFT, pt, 0, 0, 0); tp.setLayer(l4); tp.setBoundingBox(new Rectangle(0, -10, 100, 20)); cb.addTemplate(tp, 200, 500); ArrayList<Object> state = new ArrayList<Object>(); state.add("toggle"); state.add(l1); state.add(l2); state.add(l3); state.add(l4); PdfAction action = PdfAction.setOCGstate(state, true); Chunk ck = new Chunk("Click here to toggle the layers", new Font( Font.HELVETICA, 18, Font.NORMAL, Color.yellow)).setBackground( Color.blue).setAction(action); ColumnText.showTextAligned(cb, Element.ALIGN_CENTER, new Phrase(ck), 250, 400, 0); cb.sanityCheck(); // step 5: closing the document document.close(); }
Example 2
Source File: FieldPositioningEvents.java From gcs with Mozilla Public License 2.0 | 6 votes |
/** * @see com.lowagie.text.pdf.PdfPageEvent#onGenericTag(com.lowagie.text.pdf.PdfWriter, * com.lowagie.text.Document, com.lowagie.text.Rectangle, java.lang.String) */ @Override public void onGenericTag(PdfWriter writer, Document document, Rectangle rect, String text) { rect.setBottom(rect.getBottom() - 3); PdfFormField field = (PdfFormField) genericChunkFields.get(text); if (field == null) { TextField tf = new TextField(writer, new Rectangle(rect.getLeft(padding), rect.getBottom(padding), rect.getRight(padding), rect.getTop(padding)), text); tf.setFontSize(14); try { field = tf.getTextField(); } catch (Exception e) { throw new ExceptionConverter(e); } } else { field.put(PdfName.RECT, new PdfRectangle(rect.getLeft(padding), rect.getBottom(padding), rect.getRight(padding), rect.getTop(padding))); } if (parent == null) { writer.addAnnotation(field); } else { parent.addKid(field); } }
Example 3
Source File: FieldPositioningEvents.java From itext2 with GNU Lesser General Public License v3.0 | 6 votes |
/** * @see com.lowagie.text.pdf.PdfPageEvent#onGenericTag(com.lowagie.text.pdf.PdfWriter, com.lowagie.text.Document, com.lowagie.text.Rectangle, java.lang.String) */ public void onGenericTag(PdfWriter writer, Document document, Rectangle rect, String text) { rect.setBottom(rect.getBottom() - 3); PdfFormField field = (PdfFormField) genericChunkFields.get(text); if (field == null) { TextField tf = new TextField(writer, new Rectangle(rect.getLeft(padding), rect.getBottom(padding), rect.getRight(padding), rect.getTop(padding)), text); tf.setFontSize(14); try { field = tf.getTextField(); } catch (Exception e) { throw new ExceptionConverter(e); } } else { field.put(PdfName.RECT, new PdfRectangle(rect.getLeft(padding), rect.getBottom(padding), rect.getRight(padding), rect.getTop(padding))); } if (parent == null) writer.addAnnotation(field); else parent.addKid(field); }
Example 4
Source File: FieldPositioningEvents.java From itext2 with GNU Lesser General Public License v3.0 | 5 votes |
/** Creates a new event. This constructor will be used if you need to position fields with a Cell Event. * @throws DocumentException * @throws IOException*/ public FieldPositioningEvents(PdfWriter writer, String text) throws IOException, DocumentException { this.fieldWriter = writer; TextField tf = new TextField(writer, new Rectangle(0, 0), text); tf.setFontSize(14); cellField = tf.getTextField(); }
Example 5
Source File: FieldPositioningEvents.java From itext2 with GNU Lesser General Public License v3.0 | 5 votes |
/** Creates a new event. This constructor will be used if you need to position fields with a Cell Event. * @throws DocumentException * @throws IOException*/ public FieldPositioningEvents(PdfWriter writer, PdfFormField parent, String text) throws IOException, DocumentException { this.parent = parent; TextField tf = new TextField(writer, new Rectangle(0, 0), text); tf.setFontSize(14); cellField = tf.getTextField(); }
Example 6
Source File: SimpleRegistrationFormTest.java From itext2 with GNU Lesser General Public License v3.0 | 5 votes |
/** * @see com.lowagie.text.pdf.PdfPCellEvent#cellLayout(com.lowagie.text.pdf.PdfPCell, * com.lowagie.text.Rectangle, com.lowagie.text.pdf.PdfContentByte[]) */ public void cellLayout(PdfPCell cell, Rectangle position, PdfContentByte[] canvases) { TextField tf = new TextField(writer, position, fieldname); tf.setFontSize(12); try{ PdfFormField field = tf.getTextField(); writer.addAnnotation(field); } catch (Exception e) { throw new ExceptionConverter(e); } }
Example 7
Source File: FieldPositioningEvents.java From gcs with Mozilla Public License 2.0 | 3 votes |
/** * Creates a new event. This constructor will be used if you need to position fields with a Cell * Event. * * @throws DocumentException * @throws IOException */ public FieldPositioningEvents(PdfWriter writer, String text) throws IOException, DocumentException { fieldWriter = writer; TextField tf = new TextField(writer, new Rectangle(0, 0), text); tf.setFontSize(14); cellField = tf.getTextField(); }
Example 8
Source File: FieldPositioningEvents.java From gcs with Mozilla Public License 2.0 | 3 votes |
/** * Creates a new event. This constructor will be used if you need to position fields with a Cell * Event. * * @throws DocumentException * @throws IOException */ public FieldPositioningEvents(PdfWriter writer, PdfFormField parent, String text) throws IOException, DocumentException { this.parent = parent; TextField tf = new TextField(writer, new Rectangle(0, 0), text); tf.setFontSize(14); cellField = tf.getTextField(); }