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