diff --git a/Table-Of-Contents/Apply-Custom-Font-For-TOC-Headings/.NET/Apply-Custom-Font-For-TOC-Headings.sln b/Table-Of-Contents/Apply-Custom-Font-For-TOC-Headings/.NET/Apply-Custom-Font-For-TOC-Headings.sln new file mode 100644 index 00000000..e32248a8 --- /dev/null +++ b/Table-Of-Contents/Apply-Custom-Font-For-TOC-Headings/.NET/Apply-Custom-Font-For-TOC-Headings.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.14.37614.0 d17.14 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Apply-Custom-Font-For-TOC-Headings", "Apply-Custom-Font-For-TOC-Headings\Apply-Custom-Font-For-TOC-Headings.csproj", "{000D8166-FF6B-E115-AEE0-A0A05404C8D8}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {000D8166-FF6B-E115-AEE0-A0A05404C8D8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {000D8166-FF6B-E115-AEE0-A0A05404C8D8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {000D8166-FF6B-E115-AEE0-A0A05404C8D8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {000D8166-FF6B-E115-AEE0-A0A05404C8D8}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {60A98D90-ADE4-44B7-B094-64DB371D3B67} + EndGlobalSection +EndGlobal diff --git a/Table-Of-Contents/Apply-Custom-Font-For-TOC-Headings/.NET/Apply-Custom-Font-For-TOC-Headings/Apply-Custom-Font-For-TOC-Headings.csproj b/Table-Of-Contents/Apply-Custom-Font-For-TOC-Headings/.NET/Apply-Custom-Font-For-TOC-Headings/Apply-Custom-Font-For-TOC-Headings.csproj new file mode 100644 index 00000000..0576fec6 --- /dev/null +++ b/Table-Of-Contents/Apply-Custom-Font-For-TOC-Headings/.NET/Apply-Custom-Font-For-TOC-Headings/Apply-Custom-Font-For-TOC-Headings.csproj @@ -0,0 +1,21 @@ + + + + Exe + net8.0 + Apply_Custom_Font_For_TOC_Headings + + + + + Always + + + + + + + + + + diff --git a/Table-Of-Contents/Apply-Custom-Font-For-TOC-Headings/.NET/Apply-Custom-Font-For-TOC-Headings/Output/.gitkeep b/Table-Of-Contents/Apply-Custom-Font-For-TOC-Headings/.NET/Apply-Custom-Font-For-TOC-Headings/Output/.gitkeep new file mode 100644 index 00000000..5f282702 --- /dev/null +++ b/Table-Of-Contents/Apply-Custom-Font-For-TOC-Headings/.NET/Apply-Custom-Font-For-TOC-Headings/Output/.gitkeep @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Table-Of-Contents/Apply-Custom-Font-For-TOC-Headings/.NET/Apply-Custom-Font-For-TOC-Headings/Output/Output.docx b/Table-Of-Contents/Apply-Custom-Font-For-TOC-Headings/.NET/Apply-Custom-Font-For-TOC-Headings/Output/Output.docx new file mode 100644 index 00000000..a02f6279 Binary files /dev/null and b/Table-Of-Contents/Apply-Custom-Font-For-TOC-Headings/.NET/Apply-Custom-Font-For-TOC-Headings/Output/Output.docx differ diff --git a/Table-Of-Contents/Apply-Custom-Font-For-TOC-Headings/.NET/Apply-Custom-Font-For-TOC-Headings/Program.cs b/Table-Of-Contents/Apply-Custom-Font-For-TOC-Headings/.NET/Apply-Custom-Font-For-TOC-Headings/Program.cs new file mode 100644 index 00000000..0faba920 --- /dev/null +++ b/Table-Of-Contents/Apply-Custom-Font-For-TOC-Headings/.NET/Apply-Custom-Font-For-TOC-Headings/Program.cs @@ -0,0 +1,84 @@ +using Syncfusion.DocIO.DLS; +using Syncfusion.DocIORenderer; +using System.IO; + +namespace Apply_Custom_Font_For_TOC_Headings +{ + class Program + { + static void Main(string[] args) + { + //Creates a new Word document + using (WordDocument document = new WordDocument()) + { + //Adds the section into the Word document. + IWSection section = document.AddSection(); + string paraText = "AdventureWorks Cycles, the fictitious company on which the AdventureWorks sample databases are based, is a large, multinational manufacturing company."; + //Adds the paragraph into the created section. + IWParagraph paragraph = section.AddParagraph(); + //Appends the TOC field with LowerHeadingLevel and UpperHeadingLevel to determines the TOC entries. + paragraph.AppendTOC(1, 3); + //Adds the section into the Word document. + section = document.AddSection(); + //Adds the paragraph into the created section. + paragraph = section.AddParagraph(); + //Adds the text for the headings. + IWTextRange textRange = paragraph.AppendText("First Chapter"); + //Apply character formatong to the text ranges. + textRange.CharacterFormat.FontName = "Calibri"; + textRange.CharacterFormat.FontSize = 15; + //Sets a built-in heading style. + paragraph.ApplyStyle(BuiltinStyle.Heading1); + //Gets the paragrapg style. + IWParagraphStyle style = paragraph.GetStyle(); + style.CharacterFormat.ClearFormatting(); + //Adds the text into the paragraph. + IWParagraph firstParagraph = section.AddParagraph(); + IWTextRange text = firstParagraph.AppendText(paraText); + //Sets font name and size for the paragraphs. + text.CharacterFormat.FontName = "Calibri"; + text.CharacterFormat.FontSize = 12; + //Adds the section into the Word document. + section = document.AddSection(); + //Adds the paragraph into the created section. + paragraph = section.AddParagraph(); + //Adds the text for the headings. + textRange = paragraph.AppendText("Second Chapter"); + //Apply character formatong to the text ranges. + textRange.CharacterFormat.FontName = "Verdana"; + textRange.CharacterFormat.FontSize = 15; + //Sets a built-in heading style. + paragraph.ApplyStyle(BuiltinStyle.Heading2); + style = paragraph.GetStyle(); + style.CharacterFormat.ClearFormatting(); + //Adds the text into the paragraph. + firstParagraph = section.AddParagraph(); + text = firstParagraph.AppendText(paraText); + text.CharacterFormat.FontName = "Verdana"; + text.CharacterFormat.FontSize = 12; + //Adds the section into the Word document. + section = document.AddSection(); + //Adds the paragraph into the created section. + paragraph = section.AddParagraph(); + //Adds the text into the headings. + textRange = paragraph.AppendText("Third Chapter"); + //Apply character formatong to the text ranges. + textRange.CharacterFormat.FontName = "Calibri"; + textRange.CharacterFormat.FontSize = 15; + //Sets a built-in heading style. + paragraph.ApplyStyle(BuiltinStyle.Heading3); + style = paragraph.GetStyle(); + style.CharacterFormat.ClearFormatting(); + //Adds the text into the paragraph. + firstParagraph = section.AddParagraph(); + text = firstParagraph.AppendText(paraText); + text.CharacterFormat.FontName = "Calibri"; + text.CharacterFormat.FontSize = 12; + //Updates the table of contents. + document.UpdateTableOfContents(); + //Save and close the Word document. + document.Save(Path.GetFullPath("../../../Output/Output.docx")); + } + } + } +}