//// This code is part of Document Solutions for PDF .NET demos.// Copyright (c) MESCIUS inc. All rights reserved.//usingSystem.IO;usingSystem.Drawing;usingGrapeCity.Documents.Pdf;usingGrapeCity.Documents.Text;usingGCTEXT = GrapeCity.Documents.Text;usingGCDRAW = GrapeCity.Documents.Drawing; namespaceDsPdfWeb.Demos.Basics{// 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.publicclassLargeDocument3 {publicintCreatePDF(Stream stream) {// Number of pages to generate:constintN = Common.Util.LargeDocumentIterations;var start = Common.Util.TimeNow();var doc = newGcPdfDocument();// Prep a TextLayout to hold/format the text:var tl = newTextLayout(72) {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 (int paraIdx = 0; paraIdx < N; ++paraIdx) { tl.AppendLine(Common.Util.LoremIpsum(1)); } // Split and render TextLayout as shown in the PaginatedText sample:var tso = newTextSplitOptions(tl) {MinLinesInFirstParagraph = 2,MinLinesInLastParagraph = 2, }; tl.PerformLayout(true);// The loop splitting and rendering the layout:var tls = newTextLayoutSplitter(tl);for (var tlPage = tls.Split(tso); tlPage != null; tlPage = tls.Split(tso)) doc.NewPage().Graphics.DrawTextLayout(tlPage, PointF.Empty); tl.Clear();// Insert a title page (cannot be done if using StartDoc/EndDoc): tl.FirstLineIndent = 0;var fnt = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "NotoSerif-Regular.ttf"));var tf0 = newTextFormat() { FontSize = 24, FontBold = true, Font = fnt }; tl.Append(string.Format("Large Document\n{0} Paragraphs of Lorem Ipsum\n\n", N), tf0);var tf1 = newTextFormat(tf0) { FontSize = 14, FontItalic = true }; tl.Append(string.Format("Generated on {0} in {1:m\\m\\ s\\s\\ fff\\m\\s}.", Common.Util.TimeNow().ToString("R"), Common.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.Count; } }}