In the line:
TextField tf = new TextField(writer, new Rectangle(68,785, 340,800),
"Who");
how did you get to those coordinates? Maybe changing them will put the
field elsewhere...
Paulo
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On
> Behalf Of Prasad Potla
> Sent: Wednesday, September 26, 2007 1:09 PM
> To: [email protected]
> Subject: [iText-questions] placing textfield problem
>
>
> 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.DocumentExcept
> ion;
> 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();
> }
>
> }
>
Aviso Legal:
Esta mensagem é destinada exclusivamente ao destinatário. Pode conter
informação confidencial ou legalmente protegida. A incorrecta transmissão desta
mensagem não significa a perca de confidencialidade. Se esta mensagem for
recebida por engano, por favor envie-a de volta para o remetente e apague-a do
seu sistema de imediato. É proibido a qualquer pessoa que não o destinatário de
usar, revelar ou distribuir qualquer parte desta mensagem.
Disclaimer:
This message is destined exclusively to the intended receiver. It may contain
confidential or legally protected information. The incorrect transmission of
this message does not mean the loss of its confidentiality. If this message is
received by mistake, please send it back to the sender and delete it from your
system immediately. It is forbidden to any person who is not the intended
receiver to use, distribute or copy any part of this message.
-------------------------------------------------------------------------
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/