It might be easier to use the class RadioCheckField. There's an example in the javadoc.
Paulo ----- Original Message ----- From: "feanor7" <[EMAIL PROTECTED]> To: <[email protected]> Sent: Saturday, July 21, 2007 3:41 PM Subject: Re: [iText-questions] set the border of a checkbox > > Sorry if I am new to itext (I will be ordering the book this week), but I > have an urgent need to figure this out soon. Can you clarify further what > you said, or point me in the right direction or to a simple example? I'm > specifying what the checkbox looks like with the PdfAppearance class, so > I'm > guessing there are further steps I need to take with that class in order > to > get what I want? > > > > Paulo Soares wrote: >> >> You'll have to draw the checkbox with the required appearance, shape, >> size, >> color. It's just a drawing. >> >> Paulo >> >> ----- Original Message ----- >> From: "feanor7" <[EMAIL PROTECTED]> >> To: <[email protected]> >> Sent: Friday, July 20, 2007 7:59 PM >> Subject: [iText-questions] set the border of a checkbox >> >> >>> >>> I simply want to set the border of a checkbox (i want the border to be >>> thin...like 1 pt.). I tried experimenting with a couple things but i >>> can't >>> seem to accomplish it. Can anyone help me? >>> I don't see anything about setting the border in the PdfAppearance >>> class. >>> In >>> the Rectangle class there are multiple setBorder methods, and in >>> PdfFormField there is the setBorder and setBorderStyle methods. I tried >>> all >>> of these with no success. Does anyone know the correct one to use and >>> more >>> importantly the correct WAY to use it? The following is my code (after I >>> gave up trying to set the border). >>> >>> import java.awt.Color; >>> import java.io.FileOutputStream; >>> import java.io.IOException; >>> >>> import com.lowagie.text.*; >>> import com.lowagie.text.pdf.*; >>> >>> public class PdfHelper >>> { >>> public static void main(String[] args) >>> { >>> System.out.println("Textfield"); >>> >>> // step 1: creation of a document-object >>> Document document = new Document(PageSize.A4); >>> >>> try >>> { >>> String fileName = "Temp/checkbox.pdf"; >>> PdfWriter writer = PdfWriter.getInstance(document, new >>> FileOutputStream(fileName)); >>> document.open(); >>> PdfContentByte cb = writer.getDirectContent(); >>> BaseFont font = BaseFont.createFont("Helvetica", "winansi", false); >>> >>> writer.addAnnotation(getPdfCheckBox(writer, cb, "fieldName1", 10, font, >>> 12, >>> 170, 780, 10, 10, true)); >>> } >>> catch(DocumentException de) { >>> System.err.println(de.getMessage()); >>> } >>> catch(IOException ioe) { >>> System.err.println(ioe.getMessage()); >>> } >>> catch(Exception ioe) { >>> System.err.println(ioe.getMessage()); >>> } >>> >>> document.close(); >>> } >>> >>> public static synchronized PdfFormField getPdfCheckBox( PdfWriter >>> writer, >>> PdfContentByte cb, >>> String fieldName, // Acro field name >>> int maxLength, // Maximum characters you can fill in >>> BaseFont font, >>> float fontSize, >>> int x, // top left corner x-coordinate >>> int y, // top left corner y-coordinate >>> int width, >>> int height, >>> boolean isChecked) throws Exception >>> { >>> cb.moveTo(0, 0); >>> PdfAppearance tpOff = cb.createAppearance(width, height); >>> tpOff.rectangle(1, 1, width-2, height-2); >>> tpOff.stroke(); >>> >>> PdfAppearance tpOn = cb.createAppearance(width, height); >>> tpOn.rectangle(1, 1, width-2, height-2); >>> tpOn.setRGBColorFill(255, 255, 255); >>> tpOn.fillStroke(); >>> tpOn.moveTo(1, 1); >>> tpOn.lineTo(width-1, height-1); >>> tpOn.moveTo(1, width-1); >>> tpOn.lineTo(height-1, 1); >>> tpOn.stroke(); >>> >>> Rectangle size = new Rectangle(x, y, x+width, y+height); >>> >>> PdfFormField formField = PdfFormField.createCheckBox(writer); >>> formField.setWidget(size, PdfAnnotation.HIGHLIGHT_INVERT); >>> formField.setFieldName(fieldName); >>> formField.setValueAsName("Off"); >>> formField.setAppearanceState("Off"); >>> formField.setFieldFlags(PdfFormField.FLAGS_PRINT); >>> if (isChecked) >>> formField.setAppearanceState("On"); >>> formField.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, "Off", tpOff); >>> formField.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, "On", tpOn); >>> >>> return formField; >>> } >>> } ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/ _______________________________________________ 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/
