Position Of Radio Button

How to set the position of the radio buttons created in pdf file.


I tried the following code:
wholeData.shapes[i].t = “Gender, Male, Female”;
string[] txtString = wholeData.shapes[i].t.Split(’,’);
RadioButtonField radio = new RadioButtonField(doc.Pages[1]);
radio.PartialName = txtString[0];
for(int loopStrArr = 1; loopStrArr < txtString.Length; loopStrArr++)
{
int row = (loopStrArr - 1) * 15;
float positionX = shapeX + row;
double positionY = yaxis + row;
RadioButtonOptionField opt1 = new RadioButtonOptionField();
opt1.OptionName = txtString[loopStrArr].Replace(" ",string.Empty);
opt1.Width = Convert.ToInt32(wholeData.shapes[i].s);
opt1.Height = Convert.ToInt32(wholeData.shapes[i].s);
radio.Add(opt1);
opt1.Caption = new Aspose.Pdf.Text.TextFragment(txtString[loopStrArr]);
opt1.Border = new Aspose.Pdf.InteractiveFeatures.Annotations.Border(opt1);
opt1.Border.Width = 1;
opt1.Border.Style = Aspose.Pdf.InteractiveFeatures.Annotations.BorderStyle.Solid;
opt1.Characteristics.Border = System.Drawing.Color.Yellow;
opt1.DefaultAppearance.TextColor = System.Drawing.Color.Red;
opt1.SetPosition(new Point((double)positionX, (double)positionY));
doc.Pages[wholeData.shapes[i].p].Paragraphs.Add(opt1);
}
radio.SetPosition(new Point((double)shapeX, (double)yaxis));
doc.Form.Add(radio);

But these radio buttons are generating at the starting of the page. Can anybody please help me out in the.

Regards,
Nithin Eate.

Hi Nithin,

Thanks for contacting support.

You can add RadioButton in FloatingBox and then set the position of FloatingBox as per your requirement. In order to add RadioButtons in FloatingBox and setting the position, Please check the following code snippet.

Document pdfDocument = new Document();

Page pdfPage = pdfDocument.Pages.Add();

RadioButtonField radioButton = new RadioButtonField(pdfPage);

radioButton.PartialName = "radio";

RadioButtonOptionField yesField = new RadioButtonOptionField();

yesField.OptionName = "YesOption";

yesField.Height = 10;

yesField.Width = 20;

yesField.Caption = new TextFragment("Yes");

RadioButtonOptionField noField = new RadioButtonOptionField();

noField.OptionName = "NoOption";

noField.Height = 10;

noField.Width = 20;

noField.Caption = new TextFragment("No");

radioButton.Add(yesField);

radioButton.Add(noField);

pdfDocument.Form.Add(radioButton, pdfPage.Number);

radioButton.CommitImmediately = true;

radioButton.Selected = 1;

FloatingBox fb = new FloatingBox(50, 50);

fb.Top = 300;

fb.Left = 200;

fb.Paragraphs.Add(yesField);

fb.Paragraphs.Add(noField);

pdfDocument.Pages[1].Paragraphs.Add(fb);

pdfDocument.Save(dataDir + @"RadioButton_out.pdf");

In case of any further assistance, please feel free to contact us.

Best Regards,