Skip to content

Commit 5b2d01c

Browse files
committed
Added the sample for Nested List
1 parent 9d645c0 commit 5b2d01c

3 files changed

Lines changed: 101 additions & 0 deletions

File tree

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.13.35617.110 d17.13
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Adding-an-Nested-list-to-PDF-document", "Adding-an-Nested-list-to-PDF-document\Adding-an-Nested-list-to-PDF-document.csproj", "{E18E9969-6272-490E-BB9D-56B67061905C}"
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+
{E18E9969-6272-490E-BB9D-56B67061905C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{E18E9969-6272-490E-BB9D-56B67061905C}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{E18E9969-6272-490E-BB9D-56B67061905C}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{E18E9969-6272-490E-BB9D-56B67061905C}.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 = {F4A9FDC3-77EC-469D-806F-1160EC64B5C3}
24+
EndGlobalSection
25+
EndGlobal
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_an_Nested_list_to_PDF_document</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>
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Create a new instance of PdfDocument class.
2+
using Syncfusion.Pdf;
3+
using Syncfusion.Pdf.Graphics;
4+
using Syncfusion.Pdf.Lists;
5+
using Syncfusion.Drawing;
6+
7+
PdfDocument document = new PdfDocument();
8+
// Add a new page to the document.
9+
PdfPage page = document.Pages.Add();
10+
11+
// Create PDF graphics for the page.
12+
SizeF size = page.Graphics.ClientSize;
13+
PdfFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 10, PdfFontStyle.Italic);
14+
15+
string[] products = { "Tools", "Grid", "Chart", "DocIO" };
16+
17+
// Create Ordered list
18+
PdfOrderedList pdfList = new PdfOrderedList();
19+
pdfList.Marker.Brush = PdfBrushes.Black;
20+
pdfList.Indent = 20;
21+
pdfList.Font = font;
22+
23+
PdfStringFormat format = new PdfStringFormat();
24+
format.LineSpacing = 10f;
25+
pdfList.StringFormat = format;
26+
27+
foreach (string s in products)
28+
{
29+
PdfListItem item = new PdfListItem($"Essential {s}");
30+
31+
// Add sub-list for the "Tools" product
32+
if (s == "Tools")
33+
{
34+
PdfOrderedList subList = new PdfOrderedList();
35+
subList.Indent = pdfList.Indent + 30;
36+
subList.Marker.Brush = PdfBrushes.Blue;
37+
subList.Font = new PdfStandardFont(PdfFontFamily.Helvetica, 9);
38+
39+
string[] tools = { "Syntax Editor", "DropDown", "Calculator" };
40+
foreach (string tool in tools)
41+
{
42+
subList.Items.Add(tool);
43+
}
44+
45+
item.SubList = subList;
46+
}
47+
48+
pdfList.Items.Add(item);
49+
}
50+
51+
pdfList.Draw(page, new RectangleF(0, 20, size.Width, size.Height));
52+
53+
//Create file stream.
54+
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite))
55+
{
56+
//Save the PDF document to file stream.
57+
document.Save(outputFileStream);
58+
}
59+
60+
//Close the document.
61+
document.Close(true);

0 commit comments

Comments
 (0)