TabsAlignment.vb
  1. ''
  2. '' This code is part of Document Solutions for PDF demos.
  3. '' Copyright (c) MESCIUS inc. All rights reserved.
  4. ''
  5. Imports System.IO
  6. Imports System.Drawing
  7. Imports GrapeCity.Documents.Pdf
  8. Imports GrapeCity.Documents.Text
  9. Imports GrapeCity.Documents.Drawing
  10.  
  11. '' This sample demonstrates how to use TextLayout.TabStops to render columns
  12. '' of floating point numbers aligned in different ways:
  13. '' - aligned on the decimal point via TabStopAlignment.Separator
  14. '' - left-aligned on the tab position using TabStopAlignment.Leading
  15. '' - centered around the tab position using TabStopAlignment.Center
  16. '' - right-aligned on the tab position using TabStopAlignment.Trailing.
  17. Public Class TabsAlignment
  18. Function CreatePDF(ByVal stream As Stream) As Integer
  19. '' Create and set up the document:
  20. Dim doc = New GcPdfDocument()
  21. Dim page = doc.NewPage()
  22. Dim g = page.Graphics
  23. '' Create and set up a TextLayout object to print the text:
  24. Dim tl = g.CreateTextLayout()
  25. tl.MaxWidth = page.Size.Width
  26. tl.MaxHeight = page.Size.Height
  27. tl.MarginLeft = 36
  28. tl.MarginRight = 36
  29. tl.MarginTop = 36
  30. tl.MarginBottom = 36
  31.  
  32.  
  33. tl.DefaultFormat.Font = StandardFonts.Times
  34. tl.DefaultFormat.FontSize = 10
  35. tl.DefaultFormat.BackColor = Color.FromArgb(217, 217, 217)
  36. '' Add tab stops with different alignment types
  37. '' (the 1st ctor creates a TabStopAlignment.Separator TabStop):
  38. tl.TabStops = New List(Of TabStop)() From {
  39. New TabStop(72, "."c),
  40. New TabStop(72 * 2.5F, TabStopAlignment.Leading),
  41. New TabStop(72 * 5, TabStopAlignment.Center),
  42. New TabStop(72 * 7.5F, TabStopAlignment.Trailing)
  43. }
  44. '' Render sample text:
  45. tl.Append($"TabStopAlignment:{vbCrLf}{vbTab}Separator '.'{vbTab}Leading{vbTab}Center{vbTab}Trailing{vbCrLf}")
  46. Dim v0 As Double = 1
  47. Dim q As Double = (1 + Math.Sqrt(5)) / 2
  48. For i = 1 To 50
  49. tl.Append($"{vbTab}{v0:R}{vbTab}{v0:R}{vbTab}{v0:R}{vbTab}{v0:R}{vbCrLf}")
  50. v0 *= q
  51. Next
  52.  
  53. tl.PerformLayout(True)
  54. '' Draw the text and images:
  55. g.DrawTextLayout(tl, PointF.Empty)
  56. ''
  57. '' Done:
  58. doc.Save(stream)
  59. Return doc.Pages.Count
  60. End Function
  61. End Class
  62.