'''' This code is part of Document Solutions for PDF .NET demos.'' Copyright (c) MESCIUS inc. All rights reserved.''ImportsSystem.IOImportsSystem.DrawingImportsGrapeCity.Documents.PdfImportsGrapeCity.Documents.Text '' Shows how to add ouline entries to a document.'' See also PaginatedText.PublicClassOutlinesFunctionCreatePDF(ByVal stream AsStream) AsIntegerDim doc = NewGcPdfDocument()'' Text layout for main text (default DsPdf resolution is 72dpi):Dim tl = NewTextLayout(72) tl.DefaultFormat.Font = StandardFonts.Times tl.DefaultFormat.FontSize = 12 tl.FirstLineIndent = 72 / 2 tl.MaxWidth = doc.PageSize.Width tl.MaxHeight = doc.PageSize.Height tl.MarginAll = tl.Resolution'' Text layout for chapter headers:Dim tlCaption = NewTextLayout(72) tlCaption.DefaultFormat.Font = StandardFonts.TimesBold tlCaption.DefaultFormat.FontSize = tl.DefaultFormat.FontSize + 4 tlCaption.DefaultFormat.Underline = True tlCaption.MaxWidth = tl.MaxWidth tlCaption.MarginLeft = tlCaption.Resolution tlCaption.MarginTop = tlCaption.Resolution tlCaption.MarginRight = tlCaption.Resolution tlCaption.MarginBottom = tlCaption.Resolution'' Split options to control splitting of text between pages:Dim tso = NewTextSplitOptions(tl) With { .RestMarginTop = tl.Resolution, .MinLinesInFirstParagraph = 2, .MinLinesInLastParagraph = 2 }'' Generate a number of "chapters", provide outline entry for each:ConstNChapters = 20For i = 0ToNChapters - 1 doc.Pages.Add()'' Chapter title - print as chapter header and add as outline node:Dim chapter = $"Chapter {i + 1}" tlCaption.Clear() tlCaption.Append(chapter) tlCaption.PerformLayout(True)'' Add outline node for the chapter: doc.Outlines.Add(NewOutlineNode(chapter, NewDestinationFitH(doc.Pages.Last, tlCaption.MarginTop)))'' Print the caption: doc.Pages.Last.Graphics.DrawTextLayout(tlCaption, PointF.Empty)'' Chapter text: tl.Clear() tl.FirstLineIsStartOfParagraph = True tl.LastLineIsEndOfParagraph = True tl.Append(Util.LoremIpsum(7))'' Account for chapter header in the main text layout: tl.MarginTop = tlCaption.ContentRectangle.Bottom + 12 tl.PerformLayout(True)'' Print the chapter:WhileTrue'' 'rest' will accept the text that did not fit:Dim rest AsTextLayout = NothingDim splitResult = tl.Split(tso, rest) doc.Pages.Last.Graphics.DrawTextLayout(tl, PointF.Empty)If splitResult <> SplitResult.SplitThenExitWhileEndIf tl = rest doc.Pages.Add()EndWhileNext'''' Done: doc.Save(stream)Return doc.Pages.CountEndFunctionEndClass