diff --git a/Tagged PDF/Adding-tags-to-nested-list/.NET/Adding-tags-to-nested-list.sln b/Tagged PDF/Adding-tags-to-nested-list/.NET/Adding-tags-to-nested-list.sln new file mode 100644 index 00000000..58863dbc --- /dev/null +++ b/Tagged PDF/Adding-tags-to-nested-list/.NET/Adding-tags-to-nested-list.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.14.36221.1 d17.14 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Adding-tags-to-nested-list", "Adding-tags-to-nested-list\Adding-tags-to-nested-list.csproj", "{04561C02-EB81-40BE-A859-F01B29D64216}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {04561C02-EB81-40BE-A859-F01B29D64216}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {04561C02-EB81-40BE-A859-F01B29D64216}.Debug|Any CPU.Build.0 = Debug|Any CPU + {04561C02-EB81-40BE-A859-F01B29D64216}.Release|Any CPU.ActiveCfg = Release|Any CPU + {04561C02-EB81-40BE-A859-F01B29D64216}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {9E0E1714-72FB-4681-83C2-0BF4BEDA3E0C} + EndGlobalSection +EndGlobal diff --git a/Tagged PDF/Adding-tags-to-nested-list/.NET/Adding-tags-to-nested-list/Adding-tags-to-nested-list.csproj b/Tagged PDF/Adding-tags-to-nested-list/.NET/Adding-tags-to-nested-list/Adding-tags-to-nested-list.csproj new file mode 100644 index 00000000..a449c894 --- /dev/null +++ b/Tagged PDF/Adding-tags-to-nested-list/.NET/Adding-tags-to-nested-list/Adding-tags-to-nested-list.csproj @@ -0,0 +1,15 @@ + + + + Exe + net8.0 + Adding-tags-to-nested-list + enable + enable + + + + + + + diff --git a/Tagged PDF/Adding-tags-to-nested-list/.NET/Adding-tags-to-nested-list/Data/Arial.ttf b/Tagged PDF/Adding-tags-to-nested-list/.NET/Adding-tags-to-nested-list/Data/Arial.ttf new file mode 100644 index 00000000..ad7d8eab Binary files /dev/null and b/Tagged PDF/Adding-tags-to-nested-list/.NET/Adding-tags-to-nested-list/Data/Arial.ttf differ diff --git a/Tagged PDF/Adding-tags-to-nested-list/.NET/Adding-tags-to-nested-list/Output/gitkeep.txt b/Tagged PDF/Adding-tags-to-nested-list/.NET/Adding-tags-to-nested-list/Output/gitkeep.txt new file mode 100644 index 00000000..e69de29b diff --git a/Tagged PDF/Adding-tags-to-nested-list/.NET/Adding-tags-to-nested-list/Program.cs b/Tagged PDF/Adding-tags-to-nested-list/.NET/Adding-tags-to-nested-list/Program.cs new file mode 100644 index 00000000..76fdb6e4 --- /dev/null +++ b/Tagged PDF/Adding-tags-to-nested-list/.NET/Adding-tags-to-nested-list/Program.cs @@ -0,0 +1,82 @@ +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Lists; + +// Create a new PDF document +PdfDocument document = new PdfDocument(); + +// Set the document title +document.DocumentInformation.Title = "Nested List"; + +// Add a new page to the PDF +PdfPage page = document.Pages.Add(); +PdfGraphics graphics = page.Graphics; +SizeF size = page.Graphics.ClientSize; + +//Get stream from the font file. +FileStream fontStream = new FileStream(Path.GetFullPath(@"Data/Arial.ttf"), FileMode.Open, FileAccess.Read); +PdfFont font = new PdfTrueTypeFont(fontStream, 14); + +// Draw the title on the PDF +graphics.DrawString("Nested Ordered List:", font, PdfBrushes.Blue, new PointF(10, 0)); + +// Create a string format for line spacing of list items +PdfStringFormat format = new PdfStringFormat(); +format.LineSpacing = 10f; + +// Create the main list structure element with a List tag for accessibility +PdfStructureElement mainListElement = new PdfStructureElement(PdfTagType.List); + +// Initialize the main ordered list +PdfOrderedList mainList = new PdfOrderedList +{ + PdfTag = mainListElement, + Marker = { Brush = PdfBrushes.Black }, + Indent = 20, + Font = font, + StringFormat = format +}; + +// Add items to the main list and tag each item for accessibility +string[] mainItems = { "Essential Tools", "Essential PDF", "Essential XlsIO" }; +for (int i = 0; i < mainItems.Length; i++) +{ + mainList.Items.Add(mainItems[i]); + mainList.Items[i].PdfTag = new PdfStructureElement(PdfTagType.ListItem); +} + +// Create a sublist with accessibility tags +PdfStructureElement subListElement = new PdfStructureElement(PdfTagType.List); +PdfOrderedList subList = new PdfOrderedList +{ + PdfTag = subListElement, + Marker = { Brush = PdfBrushes.Black }, + Indent = 20, + Font = font, + StringFormat = format +}; + +// Add items to the sublist and tag each item for accessibility +string[] subItems = { "Create PDF", "Modify PDF", "Secure PDF", "Compress PDF" }; +for (int i = 0; i < subItems.Length; i++) +{ + subList.Items.Add(subItems[i]); + subList.Items[i].PdfTag = new PdfStructureElement(PdfTagType.ListItem); +} + +// Nest the sublist under the second item of the main list +mainList.Items[1].SubList = subList; + +// Draw the main list, which includes the nested sublist, on the PDF +mainList.Draw(page, new RectangleF(0, 30, size.Width, size.Height)); + +//Create file stream. +using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) +{ + //Save the PDF document to file stream. + document.Save(outputFileStream); +} + +//Close the document. +document.Close(true); \ No newline at end of file