ParagraphAlign.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 paragraph alignment options
  12. '' (top/center/justified/bottom for horizontal LTR text).
  13. Public Class ParagraphAlign
  14. Function CreatePDF(ByVal stream As Stream) As Integer
  15. Dim doc = New GcPdfDocument()
  16. Dim page = doc.NewPage()
  17. Dim g = page.Graphics
  18. Dim tl = g.CreateTextLayout()
  19. tl.DefaultFormat.Font = StandardFonts.Times
  20. tl.DefaultFormat.FontSize = 12
  21. Dim borderColor = Color.FromArgb(217, 217, 217)
  22.  
  23. Dim h = (page.Size.Height - 72) / 5
  24. Dim bounds = New RectangleF(36, 36, page.Size.Width - 72, h)
  25.  
  26. tl.MaxWidth = bounds.Width
  27. tl.MaxHeight = bounds.Height
  28.  
  29. Dim para = Util.LoremIpsum(1, 5, 5, 10, 12)
  30.  
  31. '' 1: ParagraphAlignment.Near
  32. tl.ParagraphAlignment = ParagraphAlignment.Near
  33. tl.Append("ParagraphAlignment.Near: ")
  34. tl.Append(para)
  35. tl.PerformLayout(True)
  36. g.DrawTextLayout(tl, bounds.Location)
  37. g.DrawRectangle(bounds, borderColor)
  38.  
  39. '' 2: ParagraphAlignment.Center
  40. bounds.Offset(0, h)
  41. tl.Clear()
  42. tl.ParagraphAlignment = ParagraphAlignment.Center
  43. tl.Append("ParagraphAlignment.Center: ")
  44. tl.Append(para)
  45. tl.PerformLayout(True)
  46. g.DrawTextLayout(tl, bounds.Location)
  47. g.DrawRectangle(bounds, borderColor)
  48.  
  49. '' 3: ParagraphAlignment.Justified
  50. bounds.Offset(0, h)
  51. tl.Clear()
  52. tl.ParagraphAlignment = ParagraphAlignment.Justified
  53. tl.Append("ParagraphAlignment.Justified: ")
  54. tl.Append(para)
  55. tl.PerformLayout(True)
  56. g.DrawTextLayout(tl, bounds.Location)
  57. g.DrawRectangle(bounds, borderColor)
  58.  
  59. '' 4: ParagraphAlignment.Distributed
  60. bounds.Offset(0, h)
  61. tl.Clear()
  62. tl.ParagraphAlignment = ParagraphAlignment.Distributed
  63. tl.Append("ParagraphAlignment.Distributed: ")
  64. tl.Append(para)
  65. tl.PerformLayout(True)
  66. g.DrawTextLayout(tl, bounds.Location)
  67. g.DrawRectangle(bounds, borderColor)
  68.  
  69. '' 5: ParagraphAlignment.Far
  70. bounds.Offset(0, h)
  71. tl.Clear()
  72. tl.ParagraphAlignment = ParagraphAlignment.Far
  73. tl.Append("ParagraphAlignment.Far: ")
  74. tl.Append(para)
  75. tl.PerformLayout(True)
  76. g.DrawTextLayout(tl, bounds.Location)
  77. g.DrawRectangle(bounds, borderColor)
  78. ''
  79. '' Done:
  80. doc.Save(stream)
  81. Return doc.Pages.Count
  82. End Function
  83. End Class
  84.