''
'' This code is part of Document Solutions for PDF demos.
'' Copyright (c) MESCIUS inc. All rights reserved.
''
Imports System.IO
Imports System.Drawing
Imports GrapeCity.Documents.Pdf
Imports GrapeCity.Documents.Text
Imports GrapeCity.Documents.Drawing
'' This sample demonstrates how to use TextLayout.TabStops to render columns
'' of floating point numbers aligned in different ways:
'' - aligned on the decimal point via TabStopAlignment.Separator
'' - left-aligned on the tab position using TabStopAlignment.Leading
'' - centered around the tab position using TabStopAlignment.Center
'' - right-aligned on the tab position using TabStopAlignment.Trailing.
Public Class TabsAlignment
Function CreatePDF(ByVal stream As Stream) As Integer
'' Create and set up the document:
Dim doc = New GcPdfDocument()
Dim page = doc.NewPage()
Dim g = page.Graphics
'' Create and set up a TextLayout object to print the text:
Dim tl = g.CreateTextLayout()
tl.MaxWidth = page.Size.Width
tl.MaxHeight = page.Size.Height
tl.MarginLeft = 36
tl.MarginRight = 36
tl.MarginTop = 36
tl.MarginBottom = 36
tl.DefaultFormat.Font = StandardFonts.Times
tl.DefaultFormat.FontSize = 10
tl.DefaultFormat.BackColor = Color.FromArgb(217, 217, 217)
'' Add tab stops with different alignment types
'' (the 1st ctor creates a TabStopAlignment.Separator TabStop):
tl.TabStops = New List(Of TabStop)() From {
New TabStop(72, "."c),
New TabStop(72 * 2.5F, TabStopAlignment.Leading),
New TabStop(72 * 5, TabStopAlignment.Center),
New TabStop(72 * 7.5F, TabStopAlignment.Trailing)
}
'' Render sample text:
tl.Append($"TabStopAlignment:{vbCrLf}{vbTab}Separator '.'{vbTab}Leading{vbTab}Center{vbTab}Trailing{vbCrLf}")
Dim v0 As Double = 1
Dim q As Double = (1 + Math.Sqrt(5)) / 2
For i = 1 To 50
tl.Append($"{vbTab}{v0:R}{vbTab}{v0:R}{vbTab}{v0:R}{vbTab}{v0:R}{vbCrLf}")
v0 *= q
Next
tl.PerformLayout(True)
'' Draw the text and images:
g.DrawTextLayout(tl, PointF.Empty)
''
'' Done:
doc.Save(stream)
Return doc.Pages.Count
End Function
End Class