I have been having trouble in placing the text field where I want. The text
field is always coming in the top location. How would i specify the co
ordinates on the document. Please let me know.

I am developing everything using table, cell ..etc

here is my code
Thanks
Prasad


//package com.pdf.helper;

import java.awt.Color;
import java.io.FileOutputStream;
import java.io.IOException;

import com.lowagie.text.Chunk;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Element;
import com.lowagie.text.Font;
import com.lowagie.text.FontFactory;
import com.lowagie.text.HeaderFooter ;
import com.lowagie.text.PageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Phrase;
import com.lowagie.text.Rectangle;
import com.lowagie.text.SimpleCell;
import com.lowagie.text.SimpleTable ;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.ColumnText;
import com.lowagie.text.pdf.GrayColor;
import com.lowagie.text.pdf.MultiColumnText;
import com.lowagie.text.pdf.PdfAction;
import com.lowagie.text.pdf.PdfAnnotation;
import com.lowagie.text.pdf.PdfAppearance;
import com.lowagie.text.pdf.PdfBorderDictionary;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfFormField ;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfPageLabels;
import com.lowagie.text.pdf.PdfWriter;
import com.lowagie.text.pdf.TextField;
import com.lowagie.text.pdf.events.FieldPositioningEvents;

public class GeneratePDF3 {

    Document document = null;
    PdfWriter writer=null;

    final Font font =FontFactory.getFont(FontFactory.HELVETICA ,
Font.DEFAULTSIZE,    Font.UNDERLINE);
    final Font fonts0 = new Font(Font.COURIER, 8, Font.NORMAL);
    final Font fonts1 = new Font(Font.COURIER, 9, Font.NORMAL);
    final Font fonts1b = new Font(Font.COURIER , 9, Font.BOLD);
    final Font fonts2 = new Font(Font.COURIER, 7, Font.NORMAL);
    final Font fonts3 = new Font(Font.COURIER, 6, Font.NORMAL);
    final Font fonts2b = new Font(Font.COURIER, 6, Font.BOLD);





public  void createPdf() {
        // step 1: creation of a document-object
         document = new Document(PageSize.A4);
        try {
            // step 2:
            writer = PdfWriter.getInstance(document,
                    new FileOutputStream("c:\\temp\\b.pdf"));
            // step 3: we open the document
            HeaderFooter header = new HeaderFooter(new Phrase("    header
",fonts2),false);
            header.setAlignment(Element.ALIGN_LEFT);
            header.setBorder(0);
            document.setHeader(header);

            HeaderFooter footer = new HeaderFooter(new Phrase("
footer ",fonts2),false);
            footer.setAlignment(Element.ALIGN_LEFT);
            footer.setBorder(0);
            document.setFooter(footer);

            document.open();
            document.newPage();


            PdfPTable table = new PdfPTable(4);
            PdfPCell cell = new PdfPCell();
            cell.setColspan(3);
            cell.addElement(new Paragraph(" one  \n",fonts2));
            cell.addElement(new Paragraph(" two  \n", fonts2));
            cell.addElement(new Paragraph(" three \n",fonts1b));
            table.addCell(cell);

            cell = new PdfPCell();

            cell.addElement(new Paragraph("DATE\n",fonts2));
            table.addCell(cell);

            document.add(table);

            table=new PdfPTable(1);
            cell = new PdfPCell();
            cell.addElement(new Paragraph("
IDENTIFICATION\n",fonts1b));

            table.addCell(cell);
            document.add(table);


            // step 4:
            BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA,
                    BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
            PdfContentByte cb = writer.getDirectContent ();
            cb.beginText();
            cb.setFontAndSize(bf, 10);
            cb.moveText(36f, 788);
            cb.showText("Hello");
            cb.endText();


            TextField tf = new TextField(writer, new Rectangle(68,785,
340,800), "Who");
            tf.setBorderWidth(1);
            tf.setBorderColor(Color.gray);
            tf.setFontSize(12);
            tf.setFont(bf);
            tf.setMaxCharacterLength(65);
            writer.addAnnotation (tf.getTextField());

        } catch (DocumentException de) {
            System.err.println(de.getMessage());
        } catch (IOException ioe) {
            System.err.println(ioe.getMessage());
        }

        // step 5: we close the document
        document.close();
        writer.close();
    }

}
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/

Reply via email to