1+ using Syncfusion . Drawing ;
2+ using Syncfusion . Pdf ;
3+ using Syncfusion . Pdf . Graphics ;
4+ using Syncfusion . Pdf . Lists ;
5+
6+ Syncfusion . Licensing . SyncfusionLicenseProvider . RegisterLicense ( "YOUR LICENSE KEY" ) ;
7+ // Create a new PDF document
8+ PdfDocument document = new PdfDocument ( ) ;
9+
10+ // Set the document title
11+ document . DocumentInformation . Title = "Nested List" ;
12+
13+ // Add a new page to the PDF
14+ PdfPage page = document . Pages . Add ( ) ;
15+ PdfGraphics graphics = page . Graphics ;
16+ SizeF size = page . Graphics . ClientSize ;
17+
18+ //Get stream from the font file.
19+ FileStream fontStream = new FileStream ( Path . GetFullPath ( @"Data/Arial.ttf" ) , FileMode . Open , FileAccess . Read ) ;
20+ PdfFont font = new PdfTrueTypeFont ( fontStream , 14 ) ;
21+
22+ // Draw the title on the PDF
23+ graphics . DrawString ( "Nested Ordered List:" , font , PdfBrushes . Blue , new PointF ( 10 , 0 ) ) ;
24+
25+ // Create a string format for line spacing of list items
26+ PdfStringFormat format = new PdfStringFormat ( ) ;
27+ format . LineSpacing = 10f ;
28+
29+ // Create the main list structure element with a List tag for accessibility
30+ PdfStructureElement mainListElement = new PdfStructureElement ( PdfTagType . List ) ;
31+
32+ // Initialize the main ordered list
33+ PdfOrderedList mainList = new PdfOrderedList
34+ {
35+ PdfTag = mainListElement ,
36+ Marker = { Brush = PdfBrushes . Black } ,
37+ Indent = 20 ,
38+ Font = font ,
39+ StringFormat = format
40+ } ;
41+
42+ // Add items to the main list and tag each item for accessibility
43+ string [ ] mainItems = { "Essential Tools" , "Essential PDF" , "Essential XlsIO" } ;
44+ for ( int i = 0 ; i < mainItems . Length ; i ++ )
45+ {
46+ mainList . Items . Add ( mainItems [ i ] ) ;
47+ mainList . Items [ i ] . PdfTag = new PdfStructureElement ( PdfTagType . ListItem ) ;
48+ }
49+
50+ // Create a sublist with accessibility tags
51+ PdfStructureElement subListElement = new PdfStructureElement ( PdfTagType . List ) ;
52+ PdfOrderedList subList = new PdfOrderedList
53+ {
54+ PdfTag = subListElement ,
55+ Marker = { Brush = PdfBrushes . Black } ,
56+ Indent = 20 ,
57+ Font = font ,
58+ StringFormat = format
59+ } ;
60+
61+ // Add items to the sublist and tag each item for accessibility
62+ string [ ] subItems = { "Create PDF" , "Modify PDF" , "Secure PDF" , "Compress PDF" } ;
63+ for ( int i = 0 ; i < subItems . Length ; i ++ )
64+ {
65+ subList . Items . Add ( subItems [ i ] ) ;
66+ subList . Items [ i ] . PdfTag = new PdfStructureElement ( PdfTagType . ListItem ) ;
67+ }
68+
69+ // Nest the sublist under the second item of the main list
70+ mainList . Items [ 1 ] . SubList = subList ;
71+
72+ // Draw the main list, which includes the nested sublist, on the PDF
73+ mainList . Draw ( page , new RectangleF ( 0 , 30 , size . Width , size . Height ) ) ;
74+
75+ //Create file stream.
76+ using ( FileStream outputFileStream = new FileStream ( Path . GetFullPath ( @"Output/Output.pdf" ) , FileMode . Create , FileAccess . ReadWrite ) )
77+ {
78+ //Save the PDF document to file stream.
79+ document . Save ( outputFileStream ) ;
80+ }
81+
82+ //Close the document.
83+ document . Close ( true ) ;
0 commit comments