VerticalText.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. '' Demonstrates rendering of vertical text in LTR and RTL modes.
  12. '' Also shows how to have text flow around rectangular objects.
  13. '' See also JapaneseColumns.
  14. Public Class VerticalText
  15. Function CreatePDF(ByVal stream As Stream) As Integer
  16. Dim doc = New GcPdfDocument()
  17. Dim page = doc.NewPage()
  18. '' Use Landscape orientation:
  19. page.Landscape = True
  20. Dim g = page.Graphics
  21. '' Some sample texts in Japanese, English and Arabic:
  22. Dim text1 = "学校教育の「国語」で教えられる。"
  23. Dim text2 = " flow direction. "
  24. Dim text3 = "النص العربي 12 + 34 = 46 مع الأرقام "
  25. '' Init font cache and get the required fonts:
  26. Dim fc = New FontCollection()
  27. fc.RegisterDirectory(Path.Combine("Resources", "Fonts"))
  28. Dim fYuMin = fc.FindFamilyName("Yu Mincho")
  29. Dim fTimes = fc.FindFamilyName("Times New Roman")
  30. Dim fArial = fc.FindFamilyName("Arial")
  31. '' Create text formats:
  32. Dim tf1 = New TextFormat() With {.Font = fYuMin}
  33. Dim tf2 = New TextFormat() With {.Font = fTimes}
  34. Dim tf3 = New TextFormat() With {.Font = fArial}
  35. '' Create TextLayout and set some options on it:
  36. Dim tl = g.CreateTextLayout()
  37. tl.FirstLineIndent = 36
  38. tl.TextAlignment = TextAlignment.Justified
  39. '' This setting justifies the last line too:
  40. tl.LastLineIsEndOfParagraph = False
  41. '' Set all margins to 1":
  42. tl.MarginAll = tl.Resolution
  43. tl.MaxWidth = page.Size.Width
  44. tl.MaxHeight = page.Size.Height
  45. '' RTL layout:
  46. tl.RightToLeft = False
  47. '' Build a list of objects for the text to flow around:
  48. tl.ObjectRects = New List(Of ObjectRect) From {
  49. New ObjectRect(540, 100, 120, 160),
  50. New ObjectRect(100, 290, 170, 100),
  51. New ObjectRect(500, 350, 170, 100)
  52. }
  53. '' Fill corresponding rectangels on page so that we can see them:
  54. For Each objRect In tl.ObjectRects
  55. g.FillRectangle(objRect.ToRectangleF(), Color.PaleVioletRed)
  56. Next
  57.  
  58. '' Add text to layout:
  59. For i = 1 To 3
  60. tl.Append(text1, tf1)
  61. tl.Append("Horizontal Top To Bottom" + text2, tf2)
  62. tl.AppendLine(text3, tf3)
  63. Next
  64.  
  65. '' Perform and draw first layout:
  66. tl.PerformLayout(True)
  67. g.DrawTextLayout(tl, PointF.Empty)
  68. g.FillRectangle(tl.ContentRectangle, Color.FromArgb(20, Color.Red))
  69.  
  70. '' Create 2nd layout - vertical rotated counter-clockwise:
  71. Dim t = tl.ContentHeight
  72. tl.Clear()
  73. tl.RotateSidewaysCounterclockwise = True
  74. tl.FlowDirection = FlowDirection.VerticalLeftToRight
  75. tl.MarginTop += t
  76. '' Add text to layout:
  77. For i = 1 To 3
  78. tl.Append(text1, tf1)
  79. tl.Append("Vertical Left To Right" + text2, tf2)
  80. tl.AppendLine(text3, tf3)
  81. Next
  82. '' Perform and draw second layout:
  83. tl.PerformLayout(True)
  84. g.DrawTextLayout(tl, PointF.Empty)
  85. g.FillRectangle(tl.ContentRectangle, Color.FromArgb(20, Color.Green))
  86.  
  87. '' Create 3rd layout - vertical:
  88. tl.Clear()
  89. tl.FlowDirection = FlowDirection.VerticalRightToLeft
  90. tl.RotateSidewaysCounterclockwise = False
  91. '' Add text to layout:
  92. For i = 1 To 3
  93. tl.Append(text1, tf1)
  94. tl.Append("Vertical Right To Left" + text2, tf2)
  95. tl.AppendLine(text3, tf3)
  96. Next
  97. '' Perform and draw third layout:
  98. tl.PerformLayout(True)
  99. g.DrawTextLayout(tl, PointF.Empty)
  100. g.FillRectangle(tl.ContentRectangle, Color.FromArgb(20, Color.Blue))
  101. ''
  102. '' Done:
  103. doc.Save(stream)
  104. Return doc.Pages.Count
  105. End Function
  106. End Class
  107.