Paulo,
I had a look at your
examples at the link below and they were very helpful in getting most of the
way there. The final point I now need is to get the third textfield to
total the other two textfield values. I have included a modified version
of your ‘text_fields’ example below to give you an idea of what I’m
after.
The only reference I
have found in regards to being able to perform calculations is the
addCalculationOrder() method, which allows me to state the order the fields
that are calculated, but not the ability to specify the formula that I need
within the third textfield.
I hope this
information helps with stating exactly what I’m trying to achieve with itext
and thanks in advance for all your help.
Regards, Greg.
import java.awt.Color;
import java.io.*;
import com.lowagie.text.*;
import com.lowagie.text.pdf.*;
public class text_fields {
public static void main(String[] args) {
Document document = new Document(PageSize.A4);
try {
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("c:\\text_fields.pdf"));
document.open();
TextField field1 = new TextField(writer,
new Rectangle(50, 760, 50 + 100, 760 + 50), "Value1");
field1.setBackgroundColor(Color.RED);
field1.setBorderColor(Color.BLUE);
field1.setBorderWidth(2);
field1.setBorderStyle(PdfBorderDictionary.STYLE_BEVELED);
field1.setText("Enter your #1 here");
field1.setAlignment(Element.ALIGN_CENTER);
field1.setFontSize(8);
PdfFormField fieldt1 = field1.getTextField();
writer.addAnnotation(fieldt1);
TextField field2 = new TextField(writer,
new Rectangle(50, 700, 50 + 100, 700 + 50), "Value2");
field2.setBackgroundColor(Color.RED);
field2.setBorderColor(Color.BLUE);
field2.setBorderWidth(2);
field2.setBorderStyle(PdfBorderDictionary.STYLE_BEVELED);
field2.setText("Enter your #2 here");
field2.setAlignment(Element.ALIGN_CENTER);
field2.setFontSize(8);
PdfFormField fieldt2 = field2.getTextField();
writer.addAnnotation(fieldt2);
TextField field3 = new TextField(writer,
new Rectangle(50, 640, 50 + 100, 640 + 50), "Values_Total");
field3.setBackgroundColor(Color.GREEN);
field3.setBorderColor(Color.BLUE);
field3.setBorderWidth(2);
field3.setBorderStyle(PdfBorderDictionary.STYLE_BEVELED);
field3.setText("Calc the total here");
field3.setAlignment(Element.ALIGN_CENTER);
field3.setFontSize(8);
PdfFormField fieldt3 = field3.getTextField();
//writer.addCalculationOrder(fieldt3);
writer.addAnnotation(fieldt3);
document.close();
System.out.println("Finished.");
}
catch (Exception de) {
de.printStackTrace();
}
}
}
-----Original
Message-----
From:
[EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Paulo Soares
Sent: Tuesday, 23 March
2004 9:48
PM
To: Greg McKernan;
[EMAIL PROTECTED]
Subject: RE: [iText-questions] Creating a
PdfFormField within PDF
Form
fields is a world in itself. See the examples in itextpdf.sf.net and if that's
not enought detail your requirements.
Best
Regards,
Paulo
Soares
From:
[EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Greg McKernan
Sent: Tuesday, March 23,
2004 10:12
AM
To:
[EMAIL PROTECTED]
Subject: [iText-questions] Creating a
PdfFormField within PDF
I’m having a lot of
trouble trying to get a PdfFormField into a PDF document, can anyone help me
please with a simple working example????
Thanks in
advance,
Greg.