Hello,

I am attempting to add a check box to my PDF using iTextSharp and the following 
code:

PdfFormField field = PdfFormField.CreateCheckBox(m_PDFWriter);
Rectangle box = new Rectangle(m_CurrentX,
                              m_CurrentY,
                              m_CurrentX + Width,
                              m_CurrentY + Width);
field.SetWidget(box, PdfAnnotation.HIGHLIGHT_INVERT);
field.Flags = PdfAnnotation.FLAGS_PRINT;
field.FieldName = FieldName;
field.ValueAsName = Value ? "On" : "Off";
field.AppearanceState = Value ? "On" : "Off";
field.MKBorderColor = m_ForeColor;
field.MKBackgroundColor = m_FillColor;
PdfAppearance onApp = PdfAppearance.CreateAppearance(m_PDFWriter, Width, Width);
onApp.SetFontAndSize(m_Font.BaseFont, m_FontSize);
onApp.SetColorFill(m_FillColor);
onApp.SetColorStroke(m_ForeColor);
onApp.Rectangle(0, 0, Width, Width);
onApp.FillStroke();
PdfAppearance offApp = PdfAppearance.CreateAppearance(m_PDFWriter, Width, 
Width);
offApp.SetFontAndSize(m_Font.BaseFont, m_FontSize);
offApp.SetColorFill(m_FillColor);
offApp.SetColorStroke(m_ForeColor);
offApp.Rectangle(0, 0, Width - 1, Width - 1);
offApp.FillStroke();
PdfAppearance defaultApp = PdfAppearance.CreateAppearance(m_PDFWriter, Width, 
Width);
defaultApp.SetFontAndSize(m_Font.BaseFont, m_FontSize);
defaultApp.SetColorFill(m_FillColor);
defaultApp.SetColorStroke(m_ForeColor);
field.SetAppearance(PdfAnnotation.APPEARANCE_NORMAL, "On", onApp);
field.SetAppearance(PdfAnnotation.APPEARANCE_NORMAL, "Off", offApp);
field.DefaultAppearanceString = defaultApp;
m_PDFWriter.AddAnnotation(field);

The checkbox appears correctly whether or not it is on or off with the check 
mark displayed correctly. When the checkbox is selected with the mouse the box 
becomes completely filled with the fill color and the mark is not visible, 
whether the next state is "On" or "Off". I almost looks like there is a pattern 
that needs to be set for the rectangle that will display the checkmark when it 
is filled.

Any pointers would be greatly appreciated. Thanks.
  Bruce
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.itextpdf.com/book/
Check the site with examples before you ask questions: 
http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/

Reply via email to