'''' This code is part of Document Solutions for PDF .NET demos.'' Copyright (c) MESCIUS inc. All rights reserved.''ImportsSystem.IOImportsSystem.DrawingImportsSystem.TextImportsGrapeCity.Documents.PdfImportsGrapeCity.Documents.Text '' Demonstrates how different styles of numbered lists can be rendered in DsPdf.'' See also NumberedList.PublicClassNumberedList2'' Encapsulate page layout constants used in the sample:PrivateStructureLayout'' All around page margins:PublicSharedMarginAsSingle = 72.0F'' List offset relative to item number:PublicSharedListOffsetAsSingle = 24.0F'' List level indent:PublicSharedListIndentAsSingle = 30.0FEndStructure '' Define simple tree type:PrivateClassNodePublicSubNew(ByVal txt AsString)Text = txtEndSubPublicPropertyTextAsStringPublicPropertyChildrenAs List(OfNode) = New List(OfNode)()EndClass '' Renders a list of nodes as a numbered list.PrivateFunctionRenderNodes(ByRef page AsPage, ByVal pt AsPointF, ByVal nodes As List(OfNode), ByVal level AsInteger) AsPointF Dim tlBullet = page.Graphics.CreateTextLayout() tlBullet.DefaultFormat.Font = StandardFonts.Times tlBullet.MarginLeft = Layout.ListIndent * level Dim tlText = page.Graphics.CreateTextLayout() tlText.DefaultFormat.Font = StandardFonts.Times tlText.MarginLeft = Layout.ListOffset + Layout.ListIndent * level For i = 0To nodes.Count - 1Dim g = page.Graphics'' Prep item text: tlText.Clear() tlText.Append(nodes(i).Text) tlText.PerformLayout(True)If pt.Y + tlText.ContentHeight > page.Size.Height - Layout.MarginThen page = page.Doc.NewPage() g = page.Graphics pt.Y = Layout.MarginEndIf'' Prep item number: tlBullet.Clear() tlBullet.Append(ItemIdxToString(i, level, tlBullet)) tlBullet.PerformLayout(True)'' Render item: g.DrawTextLayout(tlBullet, pt) g.DrawTextLayout(tlText, pt)'' Advance insertion point: pt.Y += tlText.ContentHeight'' Render children:If nodes(i).Children.Count > 0Then pt = RenderNodes(page, pt, nodes(i).Children, level + 1)EndIfNextReturn ptEndFunction '' Convert item index to item number representation, in a'' Arabic -> Latin letters -> Roman numbers loop.'' Roman numbers are right-aligned, others are left-aligned.PrivateFunctionItemIdxToString(ByVal itemIdx AsInteger, ByVal level AsInteger, ByVal tl AsTextLayout) AsString SelectCase (level Mod3)Case0 tl.MarginLeft = Layout.ListIndent * level tl.MaxWidth = Nothing tl.TextAlignment = TextAlignment.LeadingReturn$"{itemIdx + 1}."Case1 tl.MarginLeft = Layout.ListIndent * level tl.MaxWidth = Nothing tl.TextAlignment = TextAlignment.LeadingReturn$"{ChrW(AscW("a") + itemIdx)}."Case2 tl.MarginLeft = 0Dim font = tl.DefaultFormat.Font tl.MaxWidth = Layout.ListIndent * level + tl.DefaultFormat.FontSize tl.TextAlignment = TextAlignment.TrailingReturn$"{IntToRoman(itemIdx + 1)}."CaseElseThrowNew Exception("Unexpected.")EndSelectEndFunction '' From http://dotnet-snippets.com/snippet/roman-numerals/667PrivateFunctionIntToRoman(ByVal number AsInteger) AsString Dim result = NewStringBuilder()Dim digitsValues = {1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000}Dim romanDigits = {"I", "IV", "V", "IX", "X", "XL", "L", "XC", "C", "CD", "D", "CM", "M"}While number > 0For i = digitsValues.Count() - 1To0Step -1If (number / digitsValues(i) >= 1) Then number -= digitsValues(i) result.Append(romanDigits(i).ToLower())ExitForEndIfNextEndWhileReturn result.ToString()EndFunction '' Main entry point:FunctionCreatePDF(ByVal stream AsStream) AsIntegerDim doc = NewGcPdfDocument()Dim page = doc.NewPage()RenderNodes(page, NewPointF(Layout.Margin, Layout.Margin), _arthrapods.Children, 0)'''' Done: doc.Save(stream)Return doc.Pages.CountEndFunction '' Sample tree data:Private_arthrapodsAsNewNode("Animalia Arthrapoda") With { .Children = New List(OfNode) From {NewNode("Insecta") With { .Children = New List(OfNode) From {NewNode("Archaeognatha") With { .Children = New List(OfNode) From {NewNode("Protozoa") } },NewNode("Thysanura") With { .Children = New List(OfNode) From {NewNode("Silverfish") } },NewNode("Ephemeoptera") With { .Children = New List(OfNode) From {NewNode("Mafly") } },NewNode("Odonata") With { .Children = New List(OfNode) From {NewNode("Dragonfly"),NewNode("Azure Damzelfly"),NewNode("Emerald Damzelfly") } },NewNode("Orthoptera") With { .Children = New List(OfNode) From {NewNode("Grasshopper"),NewNode("Cricket"),NewNode("Cave Cricket") } },NewNode("Phasmatodea") With { .Children = New List(OfNode) From {NewNode("Walking Stick"),NewNode("Leaf Bug") } },NewNode("Mantodea") With { .Children = New List(OfNode) From {NewNode("Praying Mantis") } },NewNode("Blattoeda") With { .Children = New List(OfNode) From {NewNode("Cockroach") } },NewNode("Isoptera") With { .Children = New List(OfNode) From {NewNode("Termite") } },NewNode("Phithiraptera") With { .Children = New List(OfNode) From {NewNode("Bird Lice"),NewNode("Human Lice"),NewNode("Pubic Lice") } },NewNode("Hemiptera") With { .Children = New List(OfNode) From {NewNode("Cicada"),NewNode("Pond Skater"),NewNode("Tree Hopper"),NewNode("Stink Bug"),NewNode("Thrip"),NewNode("Alderfly") } },NewNode("Siphonatera") With { .Children = New List(OfNode) From {NewNode("Flea") } } } },NewNode("Myriapoda") With { .Children = New List(OfNode) From {NewNode("Chilopoda") With { .Children = New List(OfNode) From {NewNode("Centipede") } },NewNode("Diplopoda") With { .Children = New List(OfNode) From {NewNode("Millipede"),NewNode("Pitbug") } } } },NewNode("Crustacea") With { .Children = New List(OfNode) From {NewNode("Branchiopod") With { .Children = New List(OfNode) From {NewNode("Brine Shrimp"),NewNode("Water Flea") } },NewNode("Maxillopod") With { .Children = New List(OfNode) From {NewNode("Cyclopoid"),NewNode("Calgid"),NewNode("Barnacles") } },NewNode("Malacostracan") With { .Children = New List(OfNode) From {NewNode("Krill"),NewNode("Prawn"),NewNode("Shrimp"),NewNode("Cancrid Crab"),NewNode("Fidder Crab"),NewNode("Spider Crab"),NewNode("Lobster"),NewNode("Hermit Crab"),NewNode("Cray Fish") } } } },NewNode("Pycnogonida") With { .Children = New List(OfNode) From {NewNode("Pycnogonida") With { .Children = New List(OfNode) From {NewNode("Sea Spider") } } } },NewNode("Merostomata") With { .Children = New List(OfNode) From {NewNode("Merostomata") With { .Children = New List(OfNode) From {NewNode("Horseshoe Spider") } } } },NewNode("Arachnida") With { .Children = New List(OfNode) From {NewNode("Scorpiones") With { .Children = New List(OfNode) From {NewNode("Buthid"),NewNode("Imperial Scorpion") } },NewNode("Pseudoscorpions") With { .Children = New List(OfNode) From {NewNode("Neobisiid"),NewNode("Cheliferid") } },NewNode("Solfigugae") With { .Children = New List(OfNode) From {NewNode("Wind Scorpion") } },NewNode("Acari") With { .Children = New List(OfNode) From {NewNode("Tick"),NewNode("Mite") } },NewNode("Araneae") With { .Children = New List(OfNode) From {NewNode("Crib Weaver"),NewNode("Funnel-web Spider"),NewNode("Funnel Weaver"),NewNode("Water Spider"),NewNode("Jumping Spider"),NewNode("Wolf Spider"),NewNode("Nursery-web Spider"),NewNode("Crab Spider"),NewNode("Black Widow"),NewNode("Tiger Oriental Tarantula"),NewNode("Mexican Red-legged Tarantula") } } } } } }EndClass