We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

RadioButtons and Checkbox in a pdf that not need to be edited by the user

Hi All,

I’m need add a check boxes and radio buttons in the pdf but with no behavior, so the user can’t change if the option checked.

I found Aspose.Pdf.Generator.RadioButton() but no checkbox (http://www.aspose.com/docs/display/pdfnet/Inline+RadioButton)? I can use this to model muy pdf with radioButtons, but no for the pdf that need see a checkbox.

If I use this solution how can I put that in read only mode?

The other way is use for that part html tag like this
<input type=“checkbox” id=“2” checked=“false” disabled=“true” value=“No”>

then use the property isHtmlTagSuppported = true and delegate to aspose to perform the work.

Does Aspose have other way to do this?


Hi Diego,

Thank you for the details.

You can use FormField.IsReadOnly property to achieve your desired results. Please see the following sample code in which I have added 2 Radio Buttons (Read only) and one Checkbox (Read Only).

//Instantiate the Pdf document and add a section to it
Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();
Aspose.Pdf.Generator.Section sec1 = pdf1.Sections.Add();

//Create a table, set its column widths and add it to paragraphs collection
Aspose.Pdf.Generator.Table tab1 = new Aspose.Pdf.Generator.Table();
tab1.ColumnWidths = "120 120 120";

//Add a row to the table
Aspose.Pdf.Generator.Row r1 = tab1.Rows.Add();

//Add 1st cell to the row, set its padding and set the ID of the first paragraph
Aspose.Pdf.Generator.Cell c1 = r1.Cells.Add("item1");
c1.Padding.Left = 30;
c1.Paragraphs[0].ID = "text1";

//Add 2nd cell to the row, set its padding and set the ID of the first paragraph
Aspose.Pdf.Generator.Cell c2 = r1.Cells.Add("item2");
c2.Padding.Left = 30;
c2.Paragraphs[0].ID = "text2";

//Add 3rd cell to the row, set its padding and set the ID of the first paragraph
Aspose.Pdf.Generator.Cell c3 = r1.Cells.Add("item3");
c3.Padding.Left = 30;
c3.Paragraphs[0].ID = "text3";

Aspose.Pdf.Generator.FormField radio = new Aspose.Pdf.Generator.FormField();
radio.FormFieldType = Aspose.Pdf.Generator.FormFieldType.RadioButton;
radio.FieldName = "ARadio";
radio.ButtonColor = System.Drawing.Color.FromName("Red");
radio.RadioButtonCheckedIndex = 0;
radio.IsReadOnly = true;

Aspose.Pdf.Generator.RadioButton bt1 = radio.RadioButtons.Add();
bt1.ButtonHeight = 12;
bt1.ButtonWidth = 12;
bt1.PositioningType = Aspose.Pdf.Generator.PositioningType.ParagraphRelative;
bt1.ReferenceParagraphID = "text1";
bt1.Left = -20;
bt1.Top = 0;

Aspose.Pdf.Generator.RadioButton bt2 = radio.RadioButtons.Add();
bt2.ButtonHeight = 12;
bt2.ButtonWidth = 12;
bt2.PositioningType = Aspose.Pdf.Generator.PositioningType.ParagraphRelative;
bt2.ReferenceParagraphID = "text2";
bt2.Left = -20;
bt2.Top = 0;

//Add the radio form field to the paragraphs collection of the section

Aspose.Pdf.Generator.FormField checkbox = new Aspose.Pdf.Generator.FormField();
checkbox.FormFieldType = Aspose.Pdf.Generator.FormFieldType.CheckBox;
checkbox.FieldName = "CheckBox1";
checkbox.CheckBoxIsChecked = true;
checkbox.IsReadOnly = true;
checkbox.IsBordered = true;
checkbox.BorderColor= System.Drawing.Color.Black;
checkbox.FormWidth = 10;
checkbox.FormHeight = 10;
checkbox.PositioningType = Aspose.Pdf.Generator.PositioningType.ParagraphRelative;
checkbox.ReferenceParagraphID = "text3";
checkbox.Left = 30;
checkbox.Top = 0;

//Add the checkbox form field to the paragraphs collection of the section

pdf1.Save("D:\\AP Data\\October2012\\Radio_Check.pdf");

You may also check the following documentation link for details regarding form fields.

In case you need any further assistance, please do let us know.

Thank You & Best Regards,

Hi Naush, this help me a lot and solve my problem. But i have to said that use contols with aspose is very extranous and the documentation is limited.



Hi Diego,

Thanks for sharing the concern. From time to time, we keep on adding new documentation topics/articles in product documentation and I agree that currently documentation does not cover every possible aspect/feature available in our products. So in case user does not find any sufficient information in documentation, they ask us and we provide the possible solution. Nevertheless we going to add this topic in documentation so that other users can benefit from it.

In the event of any further query, please feel free to contact.