'''' This code is part of Document Solutions for PDF .NET demos.'' Copyright (c) MESCIUS inc. All rights reserved.''ImportsSystem.IOImportsSystem.DrawingImportsGrapeCity.Documents.PdfImportsGrapeCity.Documents.Text '' Demonstrates rendering of vertical text in LTR and RTL modes.'' Also shows how to have text flow around rectangular objects.'' See also JapaneseColumns.PublicClassVerticalTextFunctionCreatePDF(ByVal stream AsStream) AsIntegerDim doc = NewGcPdfDocument()Dim page = doc.NewPage()'' Use Landscape orientation: page.Landscape = TrueDim 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 = NewFontCollection() fc.RegisterDirectory(Path.Combine("Resources", "Fonts"))Dim fnt1 = fc.FindFamilyName("Noto Sans JP")Dim fnt2 = fc.FindFamilyName("Noto Sans")Dim fnt3 = fc.FindFamilyName("Noto Sans Arabic")'' Create text formats:Dim tf1 = NewTextFormat() With {.Font = fnt1}Dim tf2 = NewTextFormat() With {.Font = fnt2}Dim tf3 = NewTextFormat() With {.Font = fnt3}'' 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(OfObjectRect) From {NewObjectRect(540, 100, 120, 160),NewObjectRect(100, 290, 170, 100),NewObjectRect(500, 350, 170, 100) }'' Fill corresponding rectangles on page so that we can see them:ForEach objRect In tl.ObjectRects g.FillRectangle(objRect.ToRectangleF(), Color.PaleVioletRed)Next '' Add text to layout:For i = 1To3 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 = 1To3 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 = 1To3 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.CountEndFunctionEndClass