Skip to content

Commit 0bc58de

Browse files
Merge pull request #182 from SyncfusionExamples/972104
972104: Added the UG documentation for Support to add tags for the Nested list in the PDF document
2 parents 9d645c0 + a84c488 commit 0bc58de

File tree

5 files changed

+122
-0
lines changed

5 files changed

+122
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.14.36221.1 d17.14
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
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}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{04561C02-EB81-40BE-A859-F01B29D64216}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{04561C02-EB81-40BE-A859-F01B29D64216}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{04561C02-EB81-40BE-A859-F01B29D64216}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{04561C02-EB81-40BE-A859-F01B29D64216}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {9E0E1714-72FB-4681-83C2-0BF4BEDA3E0C}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>Adding-tags-to-nested-list</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Syncfusion.Pdf.Net.Core" Version="*" />
13+
</ItemGroup>
14+
15+
</Project>

Tagged PDF/Adding-tags-to-nested-list/.NET/Adding-tags-to-nested-list/Output/gitkeep.txt

Whitespace-only changes.
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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

Comments
 (0)