'''' 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 prevent a page break between a paragraph'' and the next one when splitting a TextLayout.'' Splitting of text in this sample is similar to that in PaginatedText,'' see comments in PaginatedText for more info on text handling.PublicClassKeepWithNextFunctionCreatePDF(ByVal stream AsStream) AsIntegerConstNPAR = 40Dim doc = NewGcPdfDocument()Dim tl = NewTextLayout(72) With { .FirstLineIndent = 72 / 2, .MaxWidth = doc.PageSize.Width, .MaxHeight = doc.PageSize.Height, .MarginAll = 72 } tl.DefaultFormat.Font = StandardFonts.Times tl.DefaultFormat.FontSize = 12'' Text format for paragraphs kept together with next one:Dim tf = NewTextFormat(tl.DefaultFormat) With { .FontSize = tl.DefaultFormat.FontSize + 2, .FontBold = True }'' We add a number of random 'lorem ipsum' paragraphs to this document,'' adding a 'caption' before each paragraph which is kept together'' with the following 'lorem ipsum' paragraph:For i = 0ToNPAR - 1'' 'Caption' kept together with the next paragraph: tl.Append("Caption kept together with the next paragraph. No page break after this.", tf)'' AppendParagraphBreak adds a paragraph break but prevents a page break between the two paragraphs: tl.AppendParagraphBreak()'' Random paragraph after 'caption': tl.Append(Util.LoremIpsum(1))Next tl.PerformLayout(True)'' We force all paragraph lines to stay on the same page,'' this makes it more obvious that 'caption' and following paragraph'' are kept on the same page:Dim tso = NewTextSplitOptions(tl) With { .KeepParagraphLinesTogether = True }'' 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.Split) ThenExitWhileEndIf tl = restEndWhile'' Done: doc.Save(stream)Return doc.Pages.CountEndFunctionEndClass