Radio buttons

Docotic.Pdf Library Help > Samples > Forms and Annotations > Radio buttons

This sample shows how to use radio buttons in your PDF document.

You can add radio buttons to your PDF document using PdfPage.AddRadioButton(..) method. This method returns an instance of PdfRadionButton class.

PdfRadioButton.ExportValue property is used to specify a value to be exported when SubmitFormAction (see corresponding sample in "Actions" group) is activated.

CopyC#
using System.Diagnostics;

namespace BitMiracle.Docotic.Pdf.Samples
{
    public static class RadioButtons
    {
        public static void Main()
        {
            // NOTE: 
            // When used in trial mode, the library imposes some restrictions.
            // Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx
            // for more information.

            PdfDocument pdf = new PdfDocument();
            PdfPage page = pdf.Pages[0];

            page.Canvas.DrawString(10, 50, "Docotic.Pdf library is written using: ");

            PdfRadioButton radioButton = page.AddRadioButton("languages", 10, 60, 100, 15, "C#");
            radioButton.ExportValue = "csharp";
            radioButton.Checked = true;

            PdfRadioButton radioButton2 = page.AddRadioButton("languages", 10, 80, 100, 15, "Python");
            radioButton2.ExportValue = "python";
            radioButton2.Checked = false;

            string pathToFile = "RadioButtons.pdf";
            pdf.Save(pathToFile);
            pdf.Dispose();

            Process.Start(pathToFile);
        }
    }
}
CopyVB.NET
Imports System.Diagnostics

Imports BitMiracle.Docotic.Pdf

Namespace BitMiracle.Docotic.Pdf.Samples
    Public NotInheritable Class RadioButtons
        Public Shared Sub Main()
            ' NOTE: 
            ' When used in trial mode, the library imposes some restrictions.
            ' Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx
            ' for more information.


            Dim pdf As New PdfDocument()
            Dim page As PdfPage = pdf.Pages(0)

            page.Canvas.DrawString(10, 50, "Docotic.Pdf library is written using: ")

            Dim radioButton As PdfRadioButton = page.AddRadioButton("languages", 10, 60, 100, 15, "C#")
            radioButton.ExportValue = "csharp"
            radioButton.Checked = True

            Dim radioButton2 As PdfRadioButton = page.AddRadioButton("languages", 10, 80, 100, 15, "Python")
            radioButton2.ExportValue = "python"
            radioButton2.Checked = False

            Dim pathToFile As String = "RadioButtons.pdf"
            pdf.Save(pathToFile)
            pdf.Dispose()

            Process.Start(pathToFile)
        End Sub
    End Class
End Namespace