'''' 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 '' Demonstrates text alignment options (horizontal alignment for LRT text):'' Left / Centered / Right / Justified.PublicClassTextAlignFunctionCreatePDF(ByVal stream AsStream) AsInteger'' Helper function to generate a paragraph of random text:Dim makePara As Func(OfString) =Function()ReturnUtil.LoremIpsum(1, 3, 4, 15, 20)EndFunction''Dim doc = NewGcPdfDocument()Dim g = doc.NewPage().Graphics'' Using Graphics.CreateTextLayout() ensures that TextLayout's resolution'' is set to the same value as that of the graphics (which is 72 dpi by default):Dim tl = g.CreateTextLayout() tl.DefaultFormat.Font = StandardFonts.Times tl.DefaultFormat.FontSize = 12'' Set layout size (full page with 1" margins): tl.MaxWidth = doc.Pages.Last.Size.Width - 72 * 2 tl.MaxHeight = doc.Pages.Last.Size.Height - 72 * 2'' Strong text format for 'headers':Dim tf = NewTextFormat(tl.DefaultFormat) With {.Font = StandardFonts.TimesBold}'' Insertion point:Dim ip = NewPointF(72, 72)'' TextAlignment controls how text is aligned horizontally within the layout rectangle.'' We render 5 paragraphs with different alignments.'' Leading: tl.TextAlignment = TextAlignment.Leading tl.Append("TextAlignment.Leading: ", tf) tl.Append(makePara()) tl.PerformLayout(True) g.DrawTextLayout(tl, ip)'' Advance insertion point, adding one line's height between paragraphs: ip.Y += tl.ContentHeight + tl.Lines(0).Height'' Center: tl.Clear() tl.TextAlignment = TextAlignment.Center tl.Append("TextAlignment.Center: ", tf) tl.Append(makePara()) tl.PerformLayout(True) g.DrawTextLayout(tl, ip)'' Advance insertion point, adding one line's height between paragraphs: ip.Y += tl.ContentHeight + tl.Lines(0).Height'' Trailing: tl.Clear() tl.TextAlignment = TextAlignment.Trailing tl.Append("TextAlignment.Trailing: ", tf) tl.Append(makePara()) tl.PerformLayout(True) g.DrawTextLayout(tl, ip)'' Advance insertion point, adding one line's height between paragraphs: ip.Y += tl.ContentHeight + tl.Lines(0).Height'' Justified: tl.Clear() tl.TextAlignment = TextAlignment.Justified tl.Append("TextAlignment.Justified: ", tf) tl.Append(makePara()) tl.PerformLayout(True) g.DrawTextLayout(tl, ip)'' Advance insertion point, adding one line's height between paragraphs: ip.Y += tl.ContentHeight + tl.Lines(0).Height'' Distributed: tl.Clear() tl.TextAlignment = TextAlignment.Distributed tl.Append("TextAlignment.Distributed: ", tf) tl.Append(makePara()) tl.PerformLayout(True) g.DrawTextLayout(tl, ip)'''' Done: doc.Save(stream)Return doc.Pages.CountEndFunctionEndClass