'''' This code is part of Document Solutions for PDF .NET demos.'' Copyright (c) MESCIUS inc. All rights reserved.''ImportsSystem.IOImportsSystem.DrawingImportsGrapeCity.Documents.PdfImportsGrapeCity.Documents.TextImports GCTEXT = GrapeCity.Documents.Text '' Generates a large PDF using a single TextLayout.'' Unlike other 'large document' samples (StartEndDoc, LargeDocument2),'' this sample actually paginates the whole document as a single sequence of paragraphs,'' optimally and correctly filling each page with text. Split options such as'' keeping at least 2 lines of paragraph on each page are also supported.'' Due to the extra work, this sample takes significantly more time to complete.PublicClassLargeDocument3FunctionCreatePDF(ByVal stream AsStream) AsInteger'' Number of pages to generate:ConstN = Util.LargeDocumentIterationsDim start = Util.TimeNow()Dim doc = NewGcPdfDocument()'' Prep a TextLayout to hold/format the text:Dim tl = NewTextLayout(72) With { .MaxWidth = doc.PageSize.Width, .MaxHeight = doc.PageSize.Height, .MarginAll = 72, .FirstLineIndent = 36 } tl.DefaultFormat.Font = StandardFonts.Times tl.DefaultFormat.FontSize = 12'' Generate the document:For paraIdx = 1ToN tl.AppendLine(Util.LoremIpsum(1))Next '' Split and render TextLayout as shown in the PaginatedText sample:Dim tso = NewTextSplitOptions(tl) With { .MinLinesInFirstParagraph = 2, .MinLinesInLastParagraph = 2 } tl.PerformLayout(True)'' The loop splitting and rendering the layout:Dim tls = NewTextLayoutSplitter(tl) Dim tlPage = tls.Split(tso)WhileNot tlPage IsNothing doc.NewPage().Graphics.DrawTextLayout(tlPage, PointF.Empty) tlPage = tls.Split(tso)EndWhile tl.Clear()'' Insert a title page (cannot be done if using StartDoc/EndDoc): tl.FirstLineIndent = 0Dim fnt = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "NotoSerif-Regular.ttf"))Dim tf0 = NewTextFormat() With {.FontSize = 24, .FontBold = True, .Font = fnt} tl.Append(String.Format("Large Document" + vbLf + "{0} Paragraphs of Lorem Ipsum" + vbLf + vbLf, N), tf0)Dim tf1 = NewTextFormat(tf0) With {.FontSize = 14, .FontItalic = True} tl.Append(String.Format("Generated on {0} in {1:m\m\ s\s\ fff\m\s}.", Util.TimeNow().ToString("R"), Util.TimeNow() - start), tf1) tl.TextAlignment = TextAlignment.Center tl.PerformLayout(True) doc.Pages.Insert(0).Graphics.DrawTextLayout(tl, PointF.Empty)'' Done: doc.Save(stream)Return doc.Pages.CountEndFunctionEndClass