示例#1
0
            public override void Draw(DrawContext drawContext)
            {
                PdfFont font;

                try
                {
                    font = PdfFontFactory.CreateFont(StandardFonts.HELVETICA);
                }
                catch (IOException e)
                {
                    throw new PdfException(e);
                }

                String[][] optionsArray = new String[options.Length][];
                for (int i = 0; i < options.Length; i++)
                {
                    optionsArray[i]    = new String[2];
                    optionsArray[i][0] = exports[i];
                    optionsArray[i][1] = options[i];
                }

                PdfAcroForm form = PdfAcroForm.GetAcroForm(drawContext.GetDocument(), true);

                // The 3rd parameter is the combobox name, the 4th parameter is the combobox's initial value
                PdfChoiceFormField choice = PdfFormField.CreateComboBox(drawContext.GetDocument(),
                                                                        GetOccupiedAreaBBox(), name, name, optionsArray);

                choice.SetFont(font);
                choice.GetWidgets()[0].SetBorderStyle(PdfAnnotation.STYLE_BEVELED);
                choice.SetVisibility(PdfFormField.VISIBLE_BUT_DOES_NOT_PRINT);
                choice.SetBorderColor(ColorConstants.GRAY);
                choice.SetJustification(PdfFormField.ALIGN_CENTER);
                form.AddField(choice);
            }
示例#2
0
        public override void Draw(DrawContext drawContext)
        {
            // Fictitiously layout the renderer and find out, how much space does it require
            IRenderer pr = content.CreateRendererSubTree().SetParent(this);

            LayoutResult textArea = pr.Layout(new LayoutContext(
                                                  new LayoutArea(0, new Rectangle(GetOccupiedAreaBBox().GetWidth(), 1000))));

            float spaceNeeded = textArea.GetOccupiedArea().GetBBox().GetHeight();

            Console.WriteLine("The content requires {0} pt whereas the height is {1} pt.",
                              spaceNeeded, GetOccupiedAreaBBox().GetHeight());

            float offset = (GetOccupiedAreaBBox().GetHeight() - textArea.GetOccupiedArea()
                            .GetBBox().GetHeight()) / 2;

            Console.WriteLine("The difference is {0} pt; we'll need an offset of {1} pt.",
                              -2f * offset, offset);

            PdfFormXObject xObject = new PdfFormXObject(new Rectangle(GetOccupiedAreaBBox().GetWidth(),
                                                                      GetOccupiedAreaBBox().GetHeight()));

            Canvas layoutCanvas = new Canvas(new PdfCanvas(xObject, drawContext.GetDocument()),
                                             drawContext.GetDocument(),
                                             new Rectangle(0, offset, GetOccupiedAreaBBox().GetWidth(), spaceNeeded));

            layoutCanvas.Add(content);

            drawContext.GetCanvas().AddXObject(xObject, occupiedArea.GetBBox().GetLeft(),
                                               occupiedArea.GetBBox().GetBottom());
        }
示例#3
0
            public override void Draw(DrawContext drawContext)
            {
                PdfTextFormField field = PdfTextFormField.CreateText(drawContext.GetDocument(),
                                                                     GetOccupiedAreaBBox(), fieldName);

                PdfAcroForm.GetAcroForm(drawContext.GetDocument(), true)
                .AddField(field);
            }
            public override void Draw(DrawContext drawContext)
            {
                base.Draw(drawContext);

                PdfAcroForm      form  = PdfAcroForm.GetAcroForm(drawContext.GetDocument(), true);
                PdfTextFormField field = PdfFormField.CreateText(drawContext.GetDocument(),
                                                                 occupiedArea.GetBBox(), "myField2", "Another Value");

                form.AddField(field);
            }
示例#5
0
            public override void Draw(DrawContext drawContext)
            {
                base.Draw(drawContext);
                PdfFormField field = PdfFormField.CreateSignature(drawContext.GetDocument(), GetOccupiedAreaBBox());

                field.SetFieldName(name);
                field.GetWidgets()[0].SetHighlightMode(PdfAnnotation.HIGHLIGHT_INVERT);
                field.GetWidgets()[0].SetFlags(PdfAnnotation.PRINT);
                PdfAcroForm.GetAcroForm(drawContext.GetDocument(), true).AddField(field);
            }
示例#6
0
            public override void Draw(DrawContext drawContext)
            {
                base.Draw(drawContext);
                String name = "dest" + (counter++);

                int pageNumber = occupiedArea.GetPageNumber();

                toc.Add(new KeyValuePair <String, KeyValuePair <String, int> >(((Text)modelElement).GetText(),
                                                                               new KeyValuePair <String, int>(name, pageNumber)));

                PdfPage page = drawContext.GetDocument().GetPage(pageNumber);

                drawContext.GetDocument().AddNamedDestination(name,
                                                              PdfExplicitDestination.CreateFitH(page, page.GetPageSize().GetTop()).GetPdfObject());
            }
示例#7
0
            public override void Draw(DrawContext drawContext)
            {
                base.Draw(drawContext);
                PdfFormField field = PdfFormField.CreateSignature(drawContext.GetDocument(), GetOccupiedAreaBBox());

                field.SetFieldName(name);
                if (Lock != null)
                {
                    field.Put(PdfName.Lock, this.Lock.MakeIndirect(drawContext.GetDocument()).GetPdfObject());
                }

                field.GetWidgets()[0].SetFlag(PdfAnnotation.PRINT);
                field.GetWidgets()[0].SetHighlightMode(PdfAnnotation.HIGHLIGHT_INVERT);
                PdfAcroForm.GetAcroForm(drawContext.GetDocument(), true).AddField(field);
            }
            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());
            }
示例#9
0
        /* (non-Javadoc)
         * @see com.itextpdf.html2pdf.attach.impl.layout.form.renderer.AbstractFormFieldRenderer#applyAcroField(com.itextpdf.layout.renderer.DrawContext)
         */
        protected internal override void ApplyAcroField(DrawContext drawContext)
        {
            String    value    = GetDefaultValue();
            String    name     = GetModelId();
            UnitValue fontSize = (UnitValue)this.GetPropertyAsUnitValue(Property.FONT_SIZE);

            if (!fontSize.IsPointValue())
            {
                ILog logger = LogManager.GetLogger(typeof(iText.Html2pdf.Attach.Impl.Layout.Form.Renderer.ButtonRenderer));
                logger.Error(MessageFormatUtil.Format(iText.IO.LogMessageConstant.PROPERTY_IN_PERCENTS_NOT_SUPPORTED, Property
                                                      .FONT_SIZE));
            }
            PdfDocument doc  = drawContext.GetDocument();
            Rectangle   area = flatRenderer.GetOccupiedArea().GetBBox().Clone();

            ApplyPaddings(area, true);
            PdfPage            page   = doc.GetPage(occupiedArea.GetPageNumber());
            PdfButtonFormField button = PdfFormField.CreatePushButton(doc, area, name, value, font, fontSize.GetValue(
                                                                          ));
            Background background = this.GetProperty <Background>(Property.BACKGROUND);

            if (background != null && background.GetColor() != null)
            {
                button.SetBackgroundColor(background.GetColor());
            }
            ApplyDefaultFieldProperties(button);
            PdfAcroForm.GetAcroForm(doc, true).AddField(button, page);
        }
 public override void Draw(DrawContext drawContext)
 {
     base.Draw(drawContext);
     if (!IsFlatten())
     {
         String    value    = GetDefaultValue();
         String    name     = GetModelId();
         UnitValue fontSize = (UnitValue)this.GetPropertyAsUnitValue(Property.FONT_SIZE);
         if (!fontSize.IsPointValue())
         {
             fontSize = UnitValue.CreatePointValue(DEFAULT_FONT_SIZE);
         }
         PdfDocument doc  = drawContext.GetDocument();
         Rectangle   area = GetOccupiedArea().GetBBox().Clone();
         ApplyMargins(area, false);
         PdfPage            page   = doc.GetPage(occupiedArea.GetPageNumber());
         PdfButtonFormField button = PdfFormField.CreatePushButton(doc, area, name, value, doc.GetDefaultFont(), fontSize
                                                                   .GetValue());
         button.GetWidgets()[0].SetHighlightMode(PdfAnnotation.HIGHLIGHT_NONE);
         button.SetBorderWidth(0);
         button.SetBackgroundColor(null);
         TransparentColor color = GetPropertyAsTransparentColor(Property.FONT_COLOR);
         if (color != null)
         {
             button.SetColor(color.GetColor());
         }
         PdfAcroForm forms = PdfAcroForm.GetAcroForm(doc, true);
         //Add fields only if it isn't already added. This can happen on split.
         if (forms.GetField(name) == null)
         {
             forms.AddField(button, page);
         }
     }
 }
示例#11
0
            public override void Draw(DrawContext drawContext)
            {
                base.Draw(drawContext);
                drawContext.GetCanvas().AddXObjectFittedIntoRectangle(img.GetXObject(), GetOccupiedAreaBBox());
                drawContext.GetCanvas().Stroke();

                UnitValue fontSizeUv = GetPropertyAsUnitValue(Property.FONT_SIZE);
                float     x          = GetOccupiedAreaBBox().GetX() + wPct * GetOccupiedAreaBBox().GetWidth();
                float     y          = GetOccupiedAreaBBox().GetY() + hPct *
                                       (GetOccupiedAreaBBox().GetHeight() - (fontSizeUv.IsPointValue()
                               ? fontSizeUv.GetValue()
                               : 12f) * 1.5f);

                new Canvas(drawContext.GetDocument().GetFirstPage(), drawContext.GetDocument().GetDefaultPageSize())
                .ShowTextAligned(content, x, y, alignment);
            }
示例#12
0
        /* (non-Javadoc)
         * @see com.itextpdf.html2pdf.attach.impl.layout.form.renderer.AbstractFormFieldRenderer#applyAcroField(com.itextpdf.layout.renderer.DrawContext)
         */
        protected internal override void ApplyAcroField(DrawContext drawContext)
        {
            PdfDocument        doc        = drawContext.GetDocument();
            PdfAcroForm        form       = PdfAcroForm.GetAcroForm(doc, true);
            Rectangle          area       = flatRenderer.GetOccupiedArea().GetBBox().Clone();
            PdfPage            page       = doc.GetPage(occupiedArea.GetPageNumber());
            String             groupName  = this.GetProperty <String>(Html2PdfProperty.FORM_FIELD_VALUE);
            PdfButtonFormField radioGroup = (PdfButtonFormField)form.GetField(groupName);
            bool addNew = false;

            if (null == radioGroup)
            {
                radioGroup = PdfFormField.CreateRadioGroup(doc, groupName, "on");
                addNew     = true;
            }
            if (IsBoxChecked())
            {
                radioGroup.SetValue(GetModelId());
            }
            PdfFormField radio = PdfFormField.CreateRadioButton(doc, area, radioGroup, GetModelId());

            radio.SetCheckType(PdfFormField.TYPE_CIRCLE);
            if (addNew)
            {
                form.AddField(radioGroup, page);
            }
            else
            {
                form.ReplaceField(GetModelId(), radioGroup);
            }
            WriteAcroFormFieldLangAttribute(doc);
        }
示例#13
0
            override public void Draw(DrawContext drawContext)
            {
                base.Draw(drawContext);
                iText.Kernel.Geom.Rectangle cuadro = GetOccupiedAreaBBox();
                cuadro.MoveUp(margenExterior).MoveRight(margenExterior);
                cuadro.SetHeight(cuadro.GetHeight() - (margenExterior * 2));
                cuadro.SetWidth(cuadro.GetWidth() - (margenExterior * 2));
                PdfTextFormField field = PdfFormField.CreateText(drawContext.GetDocument(), cuadro, fieldName, valor);

                field.SetJustification(justificacion);
                field.SetVisibility(PdfFormField.VISIBLE);
                field.SetFontSize(fontSize);
                PdfAcroForm form = PdfAcroForm.GetAcroForm(drawContext.GetDocument(), true);

                form.AddField(field);
            }
示例#14
0
        /* (non-Javadoc)
         * @see com.itextpdf.html2pdf.attach.impl.layout.form.renderer.AbstractFormFieldRenderer#applyAcroField(com.itextpdf.layout.renderer.DrawContext)
         */
        protected internal override void ApplyAcroField(DrawContext drawContext)
        {
            font.SetSubset(false);
            String    value    = GetDefaultValue();
            String    name     = GetModelId();
            UnitValue fontSize = (UnitValue)this.GetPropertyAsUnitValue(Property.FONT_SIZE);

            if (!fontSize.IsPointValue())
            {
                ILog logger = LogManager.GetLogger(typeof(iText.Html2pdf.Attach.Impl.Layout.Form.Renderer.TextAreaRenderer
                                                          ));
                logger.Error(MessageFormatUtil.Format(iText.IO.LogMessageConstant.PROPERTY_IN_PERCENTS_NOT_SUPPORTED, Property
                                                      .FONT_SIZE));
            }
            PdfDocument  doc        = drawContext.GetDocument();
            Rectangle    area       = flatRenderer.GetOccupiedArea().GetBBox().Clone();
            PdfPage      page       = doc.GetPage(occupiedArea.GetPageNumber());
            PdfFormField inputField = PdfFormField.CreateText(doc, area, name, value, font, fontSize.GetValue());

            inputField.SetFieldFlag(PdfFormField.FF_MULTILINE, true);
            inputField.SetDefaultValue(new PdfString(GetDefaultValue()));
            ApplyDefaultFieldProperties(inputField);
            PdfAcroForm.GetAcroForm(doc, true).AddField(inputField, page);
            WriteAcroFormFieldLangAttribute(doc);
        }
示例#15
0
            public override void Draw(DrawContext drawContext)
            {
                PdfAcroForm form = PdfAcroForm.GetAcroForm(drawContext.GetDocument(), true);

                // Define the coordinates of the middle
                float x = (GetOccupiedAreaBBox().GetLeft() + GetOccupiedAreaBBox().GetRight()) / 2;
                float y = (GetOccupiedAreaBBox().GetTop() + GetOccupiedAreaBBox().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, name, "Yes");

                form.AddField(checkBox);
            }
            public override void DrawBorder(DrawContext drawContext)
            {
                PdfPage currentPage = drawContext.GetDocument().GetPage(GetOccupiedArea().GetPageNumber());

                // Create an above canvas in order to draw above borders.
                // Notice: bear in mind that iText draws cell borders on its TableRenderer level.
                PdfCanvas aboveCanvas = new PdfCanvas(currentPage.NewContentStreamAfter(), currentPage.GetResources(),
                                                      drawContext.GetDocument());

                new Canvas(aboveCanvas, drawContext.GetDocument(), GetOccupiedAreaBBox())
                .Add(new Paragraph(title)
                     .SetMultipliedLeading(1)
                     .SetMargin(0)
                     .SetBackgroundColor(ColorConstants.LIGHT_GRAY)
                     .SetFixedPosition(GetOccupiedAreaBBox().GetLeft() + 5,
                                       GetOccupiedAreaBBox().GetTop() - 8, 30));
            }
示例#17
0
            public override void Draw(DrawContext drawContext)
            {
                base.Draw(drawContext);
                PdfAnnotation annotation = new PdfLinkAnnotation(GetOccupiedAreaBBox())
                                           .SetAction(PdfAction.CreateURI("https://lowagie.com/bio"));

                drawContext.GetDocument().GetLastPage().AddAnnotation(annotation);
            }
示例#18
0
            public override void Draw(DrawContext drawContext)
            {
                base.Draw(drawContext);

                PdfLinkAnnotation linkAnnotation = new PdfLinkAnnotation(GetOccupiedAreaBBox());

                linkAnnotation.SetHighlightMode(PdfAnnotation.HIGHLIGHT_INVERT);
                linkAnnotation.SetAction(PdfAction.CreateURI(url));
                drawContext.GetDocument().GetLastPage().AddAnnotation(linkAnnotation);
            }
示例#19
0
        /* (non-Javadoc)
         * @see com.itextpdf.html2pdf.attach.impl.layout.form.renderer.AbstractFormFieldRenderer#applyAcroField(com.itextpdf.layout.renderer.DrawContext)
         */
        protected internal override void ApplyAcroField(DrawContext drawContext)
        {
            String             name     = GetModelId();
            PdfDocument        doc      = drawContext.GetDocument();
            Rectangle          area     = flatRenderer.GetOccupiedArea().GetBBox().Clone();
            PdfPage            page     = doc.GetPage(occupiedArea.GetPageNumber());
            PdfButtonFormField checkBox = PdfFormField.CreateCheckBox(doc, area, name, IsBoxChecked() ? "Yes" : "Off");

            PdfAcroForm.GetAcroForm(doc, true).AddField(checkBox, page);
        }
            public override void Draw(DrawContext drawContext)
            {
                base.Draw(drawContext);
                Rectangle      rect = this.GetOccupiedAreaBBox();
                PdfDestination dest = PdfExplicitDestination.CreateFitH(drawContext.GetDocument().GetLastPage(), rect.GetTop
                                                                            ());
                PdfOutline outline = this.parent.AddOutline(this.title);

                outline.AddDestination(dest);
            }
示例#21
0
            public override void Draw(DrawContext drawContext)
            {
                base.Draw(drawContext);
                Rectangle      rect = GetOccupiedAreaBBox();
                PdfPage        page = drawContext.GetDocument().GetPage(GetOccupiedArea().GetPageNumber());
                PdfDestination dest = PdfExplicitDestination.CreateXYZ(page, rect.GetLeft(), rect.GetTop(), 0);

                list.Add(new KeyValuePair <String, PdfDestination>(((Text)modelElement).GetText(), dest));

                PdfOutline curOutline = root.AddOutline(((Text)modelElement).GetText());

                curOutline.AddDestination(dest);
            }
            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()));
            }
示例#23
0
 public override void Draw(DrawContext drawContext)
 {
     base.Draw(drawContext);
     if (!IsFlatten())
     {
         String    value    = GetDefaultValue();
         String    name     = GetModelId();
         UnitValue fontSize = (UnitValue)this.GetPropertyAsUnitValue(Property.FONT_SIZE);
         if (!fontSize.IsPointValue())
         {
             fontSize = UnitValue.CreatePointValue(DEFAULT_FONT_SIZE);
         }
         PdfDocument doc  = drawContext.GetDocument();
         Rectangle   area = GetOccupiedArea().GetBBox().Clone();
         ApplyMargins(area, false);
         PdfPage            page   = doc.GetPage(occupiedArea.GetPageNumber());
         PdfButtonFormField button = PdfFormField.CreatePushButton(doc, area, name, value, doc.GetDefaultFont(), fontSize
                                                                   .GetValue());
         button.GetWidgets()[0].SetHighlightMode(PdfAnnotation.HIGHLIGHT_NONE);
         button.SetBorderWidth(0);
         button.SetBackgroundColor(null);
         TransparentColor color = GetPropertyAsTransparentColor(Property.FONT_COLOR);
         if (color != null)
         {
             button.SetColor(color.GetColor());
         }
         PdfAcroForm forms = PdfAcroForm.GetAcroForm(doc, true);
         //Add fields only if it isn't already added. This can happen on split.
         if (forms.GetField(name) == null)
         {
             forms.AddField(button, page);
         }
         if (doc.IsTagged())
         {
             TagTreePointer formParentPointer = doc.GetTagStructureContext().GetAutoTaggingPointer();
             IList <String> kidsRoles         = formParentPointer.GetKidsRoles();
             int            lastFormIndex     = kidsRoles.LastIndexOf(StandardRoles.FORM);
             TagTreePointer formPointer       = formParentPointer.MoveToKid(lastFormIndex);
             String         lang = this.GetProperty <String>(Html2PdfProperty.FORM_ACCESSIBILITY_LANGUAGE);
             if (lang != null)
             {
                 formPointer.GetProperties().SetLanguage(lang);
             }
             formParentPointer.MoveToParent();
         }
     }
 }
示例#24
0
            public override void Draw(DrawContext drawContext)
            {
                PdfPattern.Tiling imgPattern = new PdfPattern.Tiling(img.GetWidth(), img.GetHeight(),
                                                                     img.GetWidth(), img.GetHeight());

                PdfPatternCanvas patternCanvas = new PdfPatternCanvas(imgPattern, drawContext.GetDocument());

                patternCanvas.AddImageAt(img, 0, 0, false);

                PdfCanvas canvas = drawContext.GetCanvas();

                canvas.SaveState();

                ColorRectangle(canvas, new PatternColor(imgPattern), GetOccupiedAreaBBox().GetX(),
                               GetOccupiedAreaBBox().GetY(), GetOccupiedAreaBBox().GetWidth(), GetOccupiedAreaBBox().GetHeight());

                canvas.SetFillColor(new PatternColor(imgPattern));
                canvas.Stroke();

                canvas.RestoreState();
            }
示例#25
0
            public override void Draw(DrawContext drawContext)
            {
                base.Draw(drawContext);

                // Draws a line to delimit the text every 25 words
                if (0 == count % 25)
                {
                    Rectangle textRect   = GetOccupiedAreaBBox();
                    int       pageNumber = GetOccupiedArea().GetPageNumber();
                    PdfCanvas canvas     = drawContext.GetCanvas();
                    Rectangle pageRect   = drawContext.GetDocument().GetPage(pageNumber).GetPageSize();
                    canvas
                    .SaveState()
                    .SetLineDash(5, 5)
                    .MoveTo(pageRect.GetLeft(), textRect.GetBottom())
                    .LineTo(textRect.GetRight(), textRect.GetBottom())
                    .LineTo(textRect.GetRight(), textRect.GetTop())
                    .LineTo(pageRect.GetRight(), textRect.GetTop())
                    .Stroke()
                    .RestoreState();
                }
            }
示例#26
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);
            }
            public override void Draw(DrawContext drawContext)
            {
                base.Draw(drawContext);

                Rectangle area = GetOccupiedAreaBBox();

                img.ScaleToFit(area.GetWidth(), area.GetHeight());

                drawContext.GetCanvas().AddXObjectFittedIntoRectangle(img.GetXObject(), new Rectangle(
                                                                          area.GetX() + (area.GetWidth() - img.GetImageWidth() *
                                                                                         img.GetProperty <float>(Property.HORIZONTAL_SCALING)) / 2,
                                                                          area.GetY() + (area.GetHeight() - img.GetImageHeight() *
                                                                                         img.GetProperty <float>(Property.VERTICAL_SCALING)) / 2,
                                                                          img.GetImageWidth() * img.GetProperty <float>(Property.HORIZONTAL_SCALING),
                                                                          img.GetImageHeight() * img.GetProperty <float>(Property.VERTICAL_SCALING)));

                drawContext.GetCanvas().Stroke();

                Paragraph p       = new Paragraph(content);
                Leading   leading = p.GetDefaultProperty <Leading>(Property.LEADING);

                UnitValue defaultFontSizeUv = new DocumentRenderer(new Document(drawContext.GetDocument()))
                                              .GetPropertyAsUnitValue(Property.FONT_SIZE);

                float         defaultFontSize = defaultFontSizeUv.IsPointValue() ? defaultFontSizeUv.GetValue() : 12f;
                float         x;
                float         y;
                TextAlignment?alignment;

                switch (position)
                {
                case POSITION.TOP_LEFT:
                {
                    x         = area.GetLeft() + 3;
                    y         = area.GetTop() - defaultFontSize * leading.GetValue();
                    alignment = TextAlignment.LEFT;
                    break;
                }

                case POSITION.TOP_RIGHT:
                {
                    x         = area.GetRight() - 3;
                    y         = area.GetTop() - defaultFontSize * leading.GetValue();
                    alignment = TextAlignment.RIGHT;
                    break;
                }

                case POSITION.BOTTOM_LEFT:
                {
                    x         = area.GetLeft() + 3;
                    y         = area.GetBottom() + 3;
                    alignment = TextAlignment.LEFT;
                    break;
                }

                case POSITION.BOTTOM_RIGHT:
                {
                    x         = area.GetRight() - 3;
                    y         = area.GetBottom() + 3;
                    alignment = TextAlignment.RIGHT;
                    break;
                }

                default:
                {
                    x         = 0;
                    y         = 0;
                    alignment = TextAlignment.CENTER;
                    break;
                }
                }

                new Canvas(drawContext.GetCanvas(), area).ShowTextAligned(p, x, y, alignment);
            }
 public override void Draw(DrawContext drawContext)
 {
     // Create a radio button that is added to a radio group.
     PdfFormField.CreateRadioButton(drawContext.GetDocument(), GetOccupiedAreaBBox(), radioGroup,
                                    value);
 }