1- using Syncfusion . Pdf . Graphics ;
1+ using Syncfusion . Pdf ;
2+ using Syncfusion . Pdf . Graphics ;
23using Syncfusion . Pdf . Interactive ;
3- using Syncfusion . Pdf ;
44using Syncfusion . Drawing ;
55
6- //Create a new PDF document
7- PdfDocument document = new PdfDocument ( ) ;
8- for ( int i = 1 ; i <= 5 ; i ++ )
6+ // Create a new PDF document
7+ using ( PdfDocument document = new PdfDocument ( ) )
98{
10- //Add a new page to PDF document
11- PdfPage page = document . Pages . Add ( ) ;
12- //Draw string
13- page . Graphics . DrawString ( "Radio Button Example-" + i , new PdfStandardFont ( PdfFontFamily . Helvetica , 20 ) , PdfBrushes . Black , new PointF ( 10 , 30 ) ) ;
14- //Create a Radio button
15- PdfRadioButtonListField employeesRadioList = new PdfRadioButtonListField ( page , "employeesRadioList" ) ;
16- //Add the radio button into form
17- document . Form . Fields . Add ( employeesRadioList ) ;
18- page . Graphics . DrawString ( "Option1" , new PdfStandardFont ( PdfFontFamily . Helvetica , 12 ) , PdfBrushes . Black , new PointF ( 50 , 70 ) ) ;
19- //Create radio button items
20- PdfRadioButtonListItem radioButtonItem1 = new PdfRadioButtonListItem ( "Option1" ) ;
21- radioButtonItem1 . Bounds = new RectangleF ( 10 , 70 , 20 , 20 ) ;
22- page . Graphics . DrawString ( "Option2" , new PdfStandardFont ( PdfFontFamily . Helvetica , 12 ) , PdfBrushes . Black , new PointF ( 50 , 100 ) ) ;
23- PdfRadioButtonListItem radioButtonItem2 = new PdfRadioButtonListItem ( "Option2" ) ;
24- radioButtonItem2 . Bounds = new RectangleF ( 10 , 100 , 20 , 20 ) ;
25- //Add the items to radio button group
26- employeesRadioList . Items . Add ( radioButtonItem1 ) ;
27- employeesRadioList . Items . Add ( radioButtonItem2 ) ;
28- }
29- // Save the PDF document to a file
30- using ( FileStream outputFileStream = new FileStream ( Path . GetFullPath ( @"Output/Output.pdf" ) , FileMode . Create , FileAccess . ReadWrite ) )
31- {
32- document . Save ( outputFileStream ) ;
33- }
34- //Close the document
35- document . Close ( true ) ;
9+ // Loop through multiple pages
10+ for ( int i = 1 ; i <= 5 ; i ++ )
11+ {
12+ // Add a new page to the PDF document
13+ PdfPage page = document . Pages . Add ( ) ;
14+ // Draw header text
15+ page . Graphics . DrawString ( $ "Radio Button Example - { i } ",
16+ new PdfStandardFont ( PdfFontFamily . Helvetica , 20 ) ,
17+ PdfBrushes . Black , new PointF ( 10 , 30 ) ) ;
18+ // Create a Radio Button List Field
19+ PdfRadioButtonListField employeesRadioList = new PdfRadioButtonListField ( page , $ "employeesRadioList_{ i } ")
20+ {
21+ AllowUnisonSelection = false // Each button acts independently
22+ } ;
23+ // Add the radio button field to the form
24+ document . Form . Fields . Add ( employeesRadioList ) ;
25+ // Draw option labels
26+ page . Graphics . DrawString ( "Option 1" , new PdfStandardFont ( PdfFontFamily . Helvetica , 12 ) ,
27+ PdfBrushes . Black , new PointF ( 50 , 70 ) ) ;
28+ page . Graphics . DrawString ( "Option 2" , new PdfStandardFont ( PdfFontFamily . Helvetica , 12 ) ,
29+ PdfBrushes . Black , new PointF ( 50 , 100 ) ) ;
30+ // Create radio button items with positions
31+ PdfRadioButtonListItem radioButtonItem1 = new PdfRadioButtonListItem ( "Option1" )
32+ {
33+ Bounds = new RectangleF ( 10 , 70 , 20 , 20 )
34+ } ;
35+ PdfRadioButtonListItem radioButtonItem2 = new PdfRadioButtonListItem ( "Option2" )
36+ {
37+ Bounds = new RectangleF ( 10 , 100 , 20 , 20 )
38+ } ;
39+ // Add items to the radio button group
40+ employeesRadioList . Items . Add ( radioButtonItem1 ) ;
41+ employeesRadioList . Items . Add ( radioButtonItem2 ) ;
42+ }
43+ document . Save ( Path . GetFullPath ( @"Output/Output.pdf" ) ) ;
44+ }
0 commit comments