Trouble Generating Radio Button in Aspose.Pdf

I tried to create radio button using the code from http://www.aspose.com/docs/display/pdfnet/Add+Form+Field+in+a+PDF+Document , but I am getting this error:


An unhandled exception of type ‘System.NullReferenceException’ occurred in Aspose.Pdf.dll
Additional information: Object reference not set to an instance of an object.

This happens when I am try to set the value of the radio button
radio.Value = “”;

and when I try to add radio options
radio.AddOption(“Test”, new Aspose.Pdf.Rectangle(0, 0, 20, 20));

I am using .Net 4.0 with Aspose.Pdf 9.7.0 (latest version on nuget)
I have also included my console application project (Written in Visual Studio 2013).

Could this issue be addressed ASAP or could I get some suggestion for workarounds? I am trying to move away from the older generator and facades namespaces to the newer Apose.Pdf, but I am not able to progress due to this issue.

Hi Sung,


Thanks for your inquiry. Please used following code snippet to add radio button in PDF document. Hopefully it will help you to accomplish the task. We are update the documentation as well.

string outFile = myDir + “Form_out.pdf”;<o:p></o:p>

Document doc = new Document();

Page page = doc.Pages.Add();

//Instantiate a table object

Aspose.Pdf.Table tab1 = new Aspose.Pdf.Table();

//Add the table in paragraphs collection of the desired section

page.Paragraphs.Add(tab1);

//Set with column widths of the table

tab1.ColumnWidths = "100 100";

//Create rows in the table and then cells in the rows

RadioButtonField rf = new RadioButtonField(page);

rf.PartialName = "radio";

doc.Form.Add(rf, 1);

RadioButtonOptionField opt1 = new RadioButtonOptionField();

RadioButtonOptionField opt2 = new RadioButtonOptionField();

opt1.OptionName = "Item1";

opt2.OptionName = "Item2";

opt1.Width = 12;

opt1.Height = 12;

opt2.Width = 12;

opt2.Height = 12;

rf.Add(opt1);

rf.Add(opt2);

opt1.Caption = new TextFragment("Item10");

opt1.Border = new 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;

opt2.Caption = new TextFragment("Item11");

opt2.Border = new Border(opt1);

opt2.Border.Width = 1;

opt2.Border.Style = Aspose.Pdf.InteractiveFeatures.Annotations.BorderStyle.Solid;

opt2.Characteristics.Border = System.Drawing.Color.Yellow;

opt2.DefaultAppearance.TextColor = System.Drawing.Color.Red;

Aspose.Pdf.Row row = tab1.Rows.Add();

Aspose.Pdf.Cell c1 = row.Cells.Add();

c1.Paragraphs.Add(opt1);

Aspose.Pdf.Cell c2 = row.Cells.Add();

c2.Paragraphs.Add(opt2);

doc.Save(outFile);

Please feel free to contact us for any further assistance.


Best Regards,