VerticalText.vb
- ''
- '' 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
-
- '' Demonstrates rendering of vertical text in LTR and RTL modes.
- '' Also shows how to have text flow around rectangular objects.
- '' See also JapaneseColumns.
- Public Class VerticalText
- Function CreatePDF(ByVal stream As Stream) As Integer
- Dim doc = New GcPdfDocument()
- Dim page = doc.NewPage()
- '' Use Landscape orientation:
- page.Landscape = True
- Dim g = page.Graphics
- '' Some sample texts in Japanese, English and Arabic:
- Dim text1 = "学校教育の「国語」で教えられる。"
- Dim text2 = " flow direction. "
- Dim text3 = "النص العربي 12 + 34 = 46 مع الأرقام "
- '' Init font cache and get the required fonts:
- Dim fc = New FontCollection()
- fc.RegisterDirectory(Path.Combine("Resources", "Fonts"))
- Dim fYuMin = fc.FindFamilyName("Yu Mincho")
- Dim fTimes = fc.FindFamilyName("Times New Roman")
- Dim fArial = fc.FindFamilyName("Arial")
- '' Create text formats:
- Dim tf1 = New TextFormat() With {.Font = fYuMin}
- Dim tf2 = New TextFormat() With {.Font = fTimes}
- Dim tf3 = New TextFormat() With {.Font = fArial}
- '' Create TextLayout and set some options on it:
- Dim tl = g.CreateTextLayout()
- tl.FirstLineIndent = 36
- tl.TextAlignment = TextAlignment.Justified
- '' This setting justifies the last line too:
- tl.LastLineIsEndOfParagraph = False
- '' Set all margins to 1":
- tl.MarginAll = tl.Resolution
- tl.MaxWidth = page.Size.Width
- tl.MaxHeight = page.Size.Height
- '' RTL layout:
- tl.RightToLeft = False
- '' Build a list of objects for the text to flow around:
- tl.ObjectRects = New List(Of ObjectRect) From {
- New ObjectRect(540, 100, 120, 160),
- New ObjectRect(100, 290, 170, 100),
- New ObjectRect(500, 350, 170, 100)
- }
- '' Fill corresponding rectangels on page so that we can see them:
- For Each objRect In tl.ObjectRects
- g.FillRectangle(objRect.ToRectangleF(), Color.PaleVioletRed)
- Next
-
- '' Add text to layout:
- For i = 1 To 3
- tl.Append(text1, tf1)
- tl.Append("Horizontal Top To Bottom" + text2, tf2)
- tl.AppendLine(text3, tf3)
- Next
-
- '' Perform and draw first layout:
- tl.PerformLayout(True)
- g.DrawTextLayout(tl, PointF.Empty)
- g.FillRectangle(tl.ContentRectangle, Color.FromArgb(20, Color.Red))
-
- '' Create 2nd layout - vertical rotated counter-clockwise:
- Dim t = tl.ContentHeight
- tl.Clear()
- tl.RotateSidewaysCounterclockwise = True
- tl.FlowDirection = FlowDirection.VerticalLeftToRight
- tl.MarginTop += t
- '' Add text to layout:
- For i = 1 To 3
- tl.Append(text1, tf1)
- tl.Append("Vertical Left To Right" + text2, tf2)
- tl.AppendLine(text3, tf3)
- Next
- '' Perform and draw second layout:
- tl.PerformLayout(True)
- g.DrawTextLayout(tl, PointF.Empty)
- g.FillRectangle(tl.ContentRectangle, Color.FromArgb(20, Color.Green))
-
- '' Create 3rd layout - vertical:
- tl.Clear()
- tl.FlowDirection = FlowDirection.VerticalRightToLeft
- tl.RotateSidewaysCounterclockwise = False
- '' Add text to layout:
- For i = 1 To 3
- tl.Append(text1, tf1)
- tl.Append("Vertical Right To Left" + text2, tf2)
- tl.AppendLine(text3, tf3)
- Next
- '' Perform and draw third layout:
- tl.PerformLayout(True)
- g.DrawTextLayout(tl, PointF.Empty)
- g.FillRectangle(tl.ContentRectangle, Color.FromArgb(20, Color.Blue))
- ''
- '' Done:
- doc.Save(stream)
- Return doc.Pages.Count
- End Function
- End Class
-