Example #1
0
            public override void Draw(DrawContext drawContext)
            {
                Rectangle   position = GetOccupiedAreaBBox();
                PdfAcroForm form     = PdfAcroForm.GetAcroForm(drawContext.GetDocument(), true);

                // Define the coordinates of the middle
                float x = (position.GetLeft() + position.GetRight()) / 2;
                float y = (position.GetTop() + position.GetBottom()) / 2;

                // Define the position of a check box that measures 20 by 20
                Rectangle rect = new Rectangle(x - 10, y - 10, 20, 20);

                // The 4th parameter is the initial value of checkbox: 'Yes' - checked, 'Off' - unchecked
                // By default, checkbox value type is cross.
                PdfButtonFormField checkBox =
                    PdfFormField.CreateCheckBox(drawContext.GetDocument(), rect, this.name, "Yes");

                switch (checkboxTypeIndex)
                {
                case 0:
                {
                    checkBox.SetCheckType(PdfFormField.TYPE_CHECK);

                    // Use this method if you changed any field parameters and didn't use setValue
                    checkBox.RegenerateField();
                    break;
                }

                case 1:
                {
                    checkBox.SetCheckType(PdfFormField.TYPE_CIRCLE);
                    checkBox.RegenerateField();
                    break;
                }

                case 2:
                {
                    checkBox.SetCheckType(PdfFormField.TYPE_CROSS);
                    checkBox.RegenerateField();
                    break;
                }

                case 3:
                {
                    checkBox.SetCheckType(PdfFormField.TYPE_DIAMOND);
                    checkBox.RegenerateField();
                    break;
                }

                case 4:
                {
                    checkBox.SetCheckType(PdfFormField.TYPE_SQUARE);
                    checkBox.RegenerateField();
                    break;
                }

                case 5:
                {
                    checkBox.SetCheckType(PdfFormField.TYPE_STAR);
                    checkBox.RegenerateField();
                    break;
                }
                }

                form.AddField(checkBox);
            }