'''' 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 '' This sample shows how to render a long text spanning multiple pages.PublicClassPaginatedTextFunctionCreatePDF(ByVal stream AsStream) AsIntegerDim doc = NewGcPdfDocument()'''' Use TextLayout to render text:Dim tl = NewTextLayout(72)'' If not specifying formats for individual runs, we MUST provide'' font and font size on TextLayout.DefaultFormat: tl.DefaultFormat.Font = StandardFonts.Times tl.DefaultFormat.FontSize = 12'' First line offset 1/2": tl.FirstLineIndent = 72 / 2'''' All other formatting properties are left at their default values.'' In particular, TextLayout's default resolution is 72 dpi - '' the same as DsPdf's, and WordWrap is true.'''' Set TextLayout's area to the whole page: tl.MaxWidth = doc.PageSize.Width tl.MaxHeight = doc.PageSize.Height'' ...and have it manage the page margins (1" all around): tl.MarginAll = tl.Resolution'''' Append the text (20 paragraphs so they would not fit on a single page)'' (note that TextLayout interprets vbCrLf as paragraph delimiter): tl.Append(Util.LoremIpsum(20))'''' When all text has been added, we must calculate the glyphs needed to render the text,'' and perform the layout. This can be done by a single call to PerformLayout, passing true to'' recalculate glyphs first (even though the text won't all fit in the specified max size,'' we only need to call PerformLayout once): 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:While (True)'' 'rest' will accept the text that did not fit:Dim rest AsTextLayout = NothingDim splitResult = tl.Split(tso, rest) doc.Pages.Add().Graphics.DrawTextLayout(tl, PointF.Empty)If splitResult <> SplitResult.SplitThenExitWhileEndIf tl = restEndWhile'''' Done: doc.Save(stream)Return doc.Pages.CountEndFunctionEndClass