Example #1
0
        public virtual void CustomizedRadiobuttonWithGroupRegeneratingFieldTest()
        {
            String             file     = "customizedRadiobuttonWithGroupRegeneratingFieldTest.pdf";
            String             filename = destinationFolder + file;
            PdfDocument        pdfDoc   = new PdfDocument(new PdfWriter(filename));
            PdfAcroForm        form     = PdfAcroForm.GetAcroForm(pdfDoc, true);
            Rectangle          rect1    = new Rectangle(36, 700, 20, 20);
            Rectangle          rect2    = new Rectangle(36, 680, 20, 20);
            PdfButtonFormField group2   = PdfFormField.CreateRadioGroup(pdfDoc, "TestGroup2", "1");

            PdfFormField.CreateRadioButton(pdfDoc, rect1, group2, "1").SetBorderWidth(2).SetBorderColor(ColorConstants
                                                                                                        .RED).SetBackgroundColor(ColorConstants.LIGHT_GRAY).SetVisibility(PdfFormField.VISIBLE);
            PdfFormField.CreateRadioButton(pdfDoc, rect2, group2, "2").SetBorderWidth(2).SetBorderColor(ColorConstants
                                                                                                        .RED).SetBackgroundColor(ColorConstants.LIGHT_GRAY).SetVisibility(PdfFormField.VISIBLE);
            group2.RegenerateField();
            form.AddField(group2);
            pdfDoc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(filename, sourceFolder + "cmp_" + file, destinationFolder
                                                                             , "diff_"));
        }
Example #2
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);
            }