예제 #1
0
            public override void Draw(DrawContext context)
            {
                int          pageNumber = GetOccupiedArea().GetPageNumber();
                Rectangle    bbox       = GetInnerAreaBBox();
                PdfDocument  pdf        = context.GetDocument();
                PdfAcroForm  form       = PdfAcroForm.GetAcroForm(pdf, true);
                PdfFormField chk        = PdfFormField.CreateRadioButton(pdf, bbox, _group, _value, PdfAConformanceLevel.PDF_A_1B
                                                                         );

                chk.SetPage(pageNumber);
                chk.SetValue("Off");
                chk.RegenerateField();
                chk.SetVisibility(PdfFormField.VISIBLE);
                chk.SetBorderColor(ColorConstants.BLACK);
                chk.SetBackgroundColor(ColorConstants.WHITE);
                chk.SetReadOnly(true);
                PdfFormXObject appearance = new PdfFormXObject(bbox);
                PdfCanvas      canvas     = new PdfCanvas(appearance, pdf);

                canvas.SaveState().MoveTo(bbox.GetLeft(), bbox.GetBottom()).LineTo(bbox.GetRight(), bbox.GetBottom()).LineTo
                    (bbox.GetRight(), bbox.GetTop()).LineTo(bbox.GetLeft(), bbox.GetTop()).LineTo(bbox.GetLeft(), bbox.GetBottom
                                                                                                      ()).SetLineWidth(1f).Stroke().RestoreState();
                form.AddFieldAppearanceToPage(chk, pdf.GetPage(pageNumber));
                chk.SetAppearance(PdfName.N, "v1".Equals(_value) ? _value : "Off", appearance.GetPdfObject());
            }
            public override void Draw(DrawContext drawContext)
            {
                PdfDocument document = drawContext.GetDocument();
                PdfAcroForm form     = PdfAcroForm.GetAcroForm(document, true);

                // Create a radio button that is added to a radio group.
                PdfFormField field = PdfFormField.CreateRadioButton(document, GetOccupiedAreaBBox(),
                                                                    radioGroup, value);

                // This method merges field with its annotation and place it on the given page.
                // This method won't work if the field has no or more than one widget annotations.
                form.AddFieldAppearanceToPage(field, document.GetPage(GetOccupiedArea().GetPageNumber()));
            }