Articles in this section

How Radio Button Behavior in .NET PDF Forms with AllowUnisonSelection?

The Syncfusion Essential® PDF is a comprehensive, high-performance .NET PDF library that enables developers to create, read, and modify PDF documents programmatically without relying on Adobe components. It provides advanced features such as merging, splitting, stamping, form handling, compression, and securing PDF files. This article explains how radio button behavior in PDF forms changes when AllowUnisonSelection is enabled versus disabled.

Compare Radio Button Behavior in PDF Forms with AllowUnisonSelection Enabled and Disabled:

  1. Create a new project: Start a new console application in .NET core.
    Console App.png
  2. Install required packages: Add the Syncfusion.Pdf.Net.Core NuGet package to your project.
    NuGet Package.png
  3. Include namespaces: In your Program.cs file, include the essential namespaces.
using Syncfusion.Pdf;
using Syncfusion.Pdf.Graphics;
using Syncfusion.Pdf.Interactive;
using Syncfusion.Drawing; 
  1. Implement comparison logic: Use the provided code sample in Program.cs to demonstrate radio button behavior in PDF forms when AllowUnisonSelection is enabled versus disabled.
//Create a PDF document
using (PdfDocument document = new PdfDocument())
{
   //Page 1 - AllowUnisonSelection DISABLED(Independent behavior)
   PdfPage page1 = document.Pages.Add();
   page1.Graphics.DrawString("Independent Radio Buttons",
       new PdfStandardFont(PdfFontFamily.Helvetica, 16),
       PdfBrushes.Black, new PointF(10, 20));

   PdfRadioButtonListField independentGroup = new PdfRadioButtonListField(page1, "IndependentGroup")
   {
       // Each button acts independently
       AllowUnisonSelection = false 
   };
   PdfRadioButtonListItem item1 = new PdfRadioButtonListItem("OptionA")
   {
       Bounds = new RectangleF(10, 60, 20, 20)
   };
   // Same label but independent
   PdfRadioButtonListItem item2 = new PdfRadioButtonListItem("OptionA") 
   {
       Bounds = new RectangleF(10, 100, 20, 20)
   };
   independentGroup.Items.Add(item1);
   independentGroup.Items.Add(item2);
   document.Form.Fields.Add(independentGroup);
   page1.Graphics.DrawString("Option A (1)", new PdfStandardFont(PdfFontFamily.Helvetica, 12),
       PdfBrushes.Black, new PointF(40, 60));
   page1.Graphics.DrawString("Option A (2)", new PdfStandardFont(PdfFontFamily.Helvetica, 12),
       PdfBrushes.Black, new PointF(40, 100));
   //Page 2 - AllowUnisonSelection ENABLED(Unified behavior)
   PdfPage page2 = document.Pages.Add();
   page2.Graphics.DrawString("Unified Radio Buttons",
       new PdfStandardFont(PdfFontFamily.Helvetica, 16),
       PdfBrushes.Black, new PointF(10, 20));
   PdfRadioButtonListField unifiedGroup = new PdfRadioButtonListField(page2, "UnifiedGroup")
   {
       // Buttons share selection state
       AllowUnisonSelection = true 
   };
   PdfRadioButtonListItem item3 = new PdfRadioButtonListItem("OptionB")
   {
       Bounds = new RectangleF(10, 60, 20, 20)
   };
   // Same label, unified selection
   PdfRadioButtonListItem item4 = new PdfRadioButtonListItem("OptionB") 
   {
       Bounds = new RectangleF(10, 100, 20, 20)
   };
   unifiedGroup.Items.Add(item3);
   unifiedGroup.Items.Add(item4);
   document.Form.Fields.Add(unifiedGroup);
   page2.Graphics.DrawString("Option B (1)", new PdfStandardFont(PdfFontFamily.Helvetica, 12),
       PdfBrushes.Black, new PointF(40, 60));
   page2.Graphics.DrawString("Option B (2)", new PdfStandardFont(PdfFontFamily.Helvetica, 12),
       PdfBrushes.Black, new PointF(40, 100));
   //Save the document
   document.Save("Output.pdf");
} 

A complete working sample is available for download from GitHub.

By executing the program, you will generate the following PDF document.

Output.png

Take a moment to peruse the documentation to learn how to add form fields in a PDF document.

Conclusion

I hope you enjoyed learning how radio button behavior in PDF forms changes when AllowUnisonSelection is enabled versus disabled.

You can refer to our ASP.NET Core PDF feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our ASP.NET Core PDF example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied