//// 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; namespaceDsPdfWeb.Demos.Basics{// Creates a simple 3-column text layout.// For a slightly more complex but practically more useful way // to render text in columns, see BalancedColumns.publicclassMultiColumnText {publicintCreatePDF(Stream stream) {var doc = newGcPdfDocument();var g = doc.NewPage().Graphics;var tl = g.CreateTextLayout(); tl.DefaultFormat.Font = StandardFonts.Times; tl.DefaultFormat.FontSize = 12; tl.TextAlignment = TextAlignment.Justified; tl.FirstLineIndent = 72 / 2; tl.ParagraphSpacing = 72 / 8;// Add some text (note that TextLayout interprets "\r\n" as paragraph delimiter): tl.Append(Common.Util.LoremIpsum(20));// Set up columns:constintcolCount = 3;// 1/2" margins all around:constfloatmargin = 72 / 2;// 1/4" gap between columns:constfloatcolGap = margin / 4;float colWidth = (doc.Pages.Last.Size.Width - margin * 2) / colCount - colGap * (colCount - 1); tl.MaxWidth = colWidth; tl.MaxHeight = doc.Pages.Last.Size.Height - margin * 2;// Calculate glyphs and perform layout for the whole text: tl.PerformLayout(true);// In a loop, split and render the text in the current column:int col = 0;while (true) {// 'rest' will accept the text that did not fit:var splitResult = tl.Split(null, outTextLayout rest); g.DrawTextLayout(tl, newPointF(margin + col * (colWidth + colGap), margin));if (splitResult != SplitResult.Split)break; tl = rest;if (++col == colCount) { doc.Pages.Add(); g = doc.Pages.Last.Graphics; col = 0; } }// Done: doc.Save(stream);return doc.Pages.Count; } }}