'''' This code is part of Document Solutions for PDF .NET demos.'' Copyright (c) MESCIUS inc. All rights reserved.''ImportsSystem.IOImportsSystem.DrawingImportsGrapeCity.Documents.PdfImportsGrapeCity.Documents.TextImportsGrapeCity.Documents.Drawing '' Demonstrates how paragraphs of text can be rendered as a numbered list in DsPdf.'' The method of rendering pages of text in this sample is taken from the PaginatedText'' sample. See also TextRendering.PublicClassNumberedList'' Encapsulate page layout constants used in the sample:PrivateStructureLayoutPublicSharedMarginAsSingle = 72.0FPublicSharedListOffsetAsSingle = 24.0FEndStructure '' Utility method which pre-pends numbers to all paragraphs in a TextLayout.PrivateSubAddBullets(ByVal g AsGcGraphics, ByVal pt AsPointF, ByVal tl AsTextLayout, ByRef itemNo AsInteger)Dim tlBullet = g.CreateTextLayout() tlBullet.DefaultFormat.Font = StandardFonts.Times tlBullet.DefaultFormat.FontSize = 12ForEach line In tl.LinesIf (line.FirstLineInParagraph) Then tlBullet.Clear() tlBullet.Append($"{itemNo})") itemNo += 1 tlBullet.PerformLayout(True) g.DrawTextLayout(tlBullet, NewPointF(pt.X, pt.Y + line.Position + line.LineGap))EndIfNextEndSub '' Main entry point:FunctionCreatePDF(ByVal stream AsStream) AsIntegerDim doc = NewGcPdfDocument()Dim ip = NewPointF(Layout.Margin, Layout.Margin) '' Use TextLayout.MarginLeft to reserve space for list numbers/bullets:Dim tl = NewTextLayout(72) With { .MaxWidth = doc.PageSize.Width - Layout.Margin * 2, .MaxHeight = doc.PageSize.Height - Layout.Margin * 2, .ParagraphSpacing = 8, .MarginLeft = Layout.ListOffset } tl.DefaultFormat.Font = StandardFonts.Times '' Add 20 paragraphs of text that will render as a numbered list of 20 items: tl.Append(Util.LoremIpsum(20, 1, 6))'' Perform layout: tl.PerformLayout(True)'' Use split options to provide widow/orphan control:Dim tso = NewTextSplitOptions(tl) tso.MinLinesInFirstParagraph = 2 tso.MinLinesInLastParagraph = 2 '' In a loop, split and render the text (see PaginatedText),'' and add list numbers:Dim itemNo = 1While (True)'' 'rest' will accept the text that did not fit:Dim rest AsTextLayout = NothingDim splitResult = tl.Split(tso, rest)Dim g = doc.Pages.Add().Graphics g.DrawTextLayout(tl, ip)AddBullets(g, ip, tl, itemNo)If splitResult <> SplitResult.SplitThenExitWhileEndIf tl = restEndWhile'''' Done: doc.Save(stream)Return doc.Pages.CountEndFunctionEndClass