ParagraphAlign.vb
'''' This code is part of Document Solutions for PDF .NET demos.'' Copyright (c) MESCIUS inc. All rights reserved.''Imports System.IOImports System.DrawingImports GrapeCity.Documents.PdfImports GrapeCity.Documents.Text
'' This sample demonstrates paragraph alignment options'' (top/center/justified/bottom for horizontal LTR text).Public Class ParagraphAlign Function CreatePDF(ByVal stream As Stream) As Integer Dim doc = New GcPdfDocument() Dim page = doc.NewPage() Dim g = page.Graphics Dim tl = g.CreateTextLayout() tl.DefaultFormat.Font = StandardFonts.Times tl.DefaultFormat.FontSize = 12 Dim borderColor = Color.FromArgb(217, 217, 217)
Dim h = (page.Size.Height - 72) / 5 Dim bounds = New RectangleF(36, 36, page.Size.Width - 72, h)
tl.MaxWidth = bounds.Width tl.MaxHeight = bounds.Height
Dim para = Util.LoremIpsum(1, 5, 5, 10, 12)
'' 1: ParagraphAlignment.Near tl.ParagraphAlignment = ParagraphAlignment.Near tl.Append("ParagraphAlignment.Near: ") tl.Append(para) tl.PerformLayout(True) g.DrawTextLayout(tl, bounds.Location) g.DrawRectangle(bounds, borderColor)
'' 2: ParagraphAlignment.Center bounds.Offset(0, h) tl.Clear() tl.ParagraphAlignment = ParagraphAlignment.Center tl.Append("ParagraphAlignment.Center: ") tl.Append(para) tl.PerformLayout(True) g.DrawTextLayout(tl, bounds.Location) g.DrawRectangle(bounds, borderColor)
'' 3: ParagraphAlignment.Justified bounds.Offset(0, h) tl.Clear() tl.ParagraphAlignment = ParagraphAlignment.Justified tl.Append("ParagraphAlignment.Justified: ") tl.Append(para) tl.PerformLayout(True) g.DrawTextLayout(tl, bounds.Location) g.DrawRectangle(bounds, borderColor)
'' 4: ParagraphAlignment.Distributed bounds.Offset(0, h) tl.Clear() tl.ParagraphAlignment = ParagraphAlignment.Distributed tl.Append("ParagraphAlignment.Distributed: ") tl.Append(para) tl.PerformLayout(True) g.DrawTextLayout(tl, bounds.Location) g.DrawRectangle(bounds, borderColor)
'' 5: ParagraphAlignment.Far bounds.Offset(0, h) tl.Clear() tl.ParagraphAlignment = ParagraphAlignment.Far tl.Append("ParagraphAlignment.Far: ") tl.Append(para) tl.PerformLayout(True) g.DrawTextLayout(tl, bounds.Location) g.DrawRectangle(bounds, borderColor) '' '' Done: doc.Save(stream) Return doc.Pages.Count End FunctionEnd Class