Sarah1 wrote:
Please help. Thanks.

This is an old question, so I guess you've found the answer by now.
If not, have a look at the attached example.
br,
Bruno

import java.io.FileOutputStream;
import java.io.IOException;

import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Element;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfFormField;
import com.lowagie.text.pdf.PdfWriter;
import com.lowagie.text.pdf.RadioCheckField;


public class RadioButtons {

        /**
         * Test example
         */
        public static void main(String[] args) {
                // step 1: creation of a document-object
                Document document = new Document();
                try {

                        // step 2:
                        PdfWriter writer = PdfWriter.getInstance(document,
                                        new FileOutputStream("buttons.pdf"));
                        // step 3:
                        document.open();
                        // step 4:
                        PdfContentByte cb = writer.getDirectContent();
                        BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA,
                                        BaseFont.WINANSI, 
BaseFont.NOT_EMBEDDED);
                        String[] languages = { "English", "French", "Dutch" };
                        Rectangle rect;

                        PdfFormField language = PdfFormField
                                        .createRadioButton(writer, true);
                        language.setFieldName("language");
                        language.setValueAsName(languages[0]);
                        for (int i = 0; i < languages.length; i++) {
                                rect = new Rectangle(40, 806 - i * 40, 60, 788 
- i * 40);
                                addRadioButton(writer, rect, language, 
languages[i], i == 0, writer.getPageNumber() + i);
                        }
                        writer.addAnnotation(language);
                        for (int i = 0; i < languages.length; i++) {
                                cb.beginText();
                                cb.setFontAndSize(bf, 18);
                                cb.showTextAligned(Element.ALIGN_LEFT, 
languages[i], 70,
                                                790 - i * 40, 0);
                                cb.endText();
                                document.newPage();
                        }
                } catch (Exception e) {
                        e.printStackTrace();
                }
                // step 5: we close the document
                document.close();

        }

        private static void addRadioButton(PdfWriter writer, Rectangle rect,
                        PdfFormField radio, String name, boolean on, int page) 
throws IOException,
                        DocumentException {
                RadioCheckField check = new RadioCheckField(writer, rect, null, 
name);
                check.setCheckType(RadioCheckField.TYPE_CIRCLE);
                check.setChecked(on);
                PdfFormField field = check.getRadioField();
                field.setPlaceInPage(page);
                radio.addKid(field);
        }
}
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/

Reply via email to