'''' This code is part of Document Solutions for PDF .NET demos.'' Copyright (c) MESCIUS inc. All rights reserved.''ImportsSystem.IOImportsSystem.DrawingImportsGrapeCity.Documents.PdfImportsGrapeCity.Documents.TextImportsGrapeCity.Documents.DrawingImports GCTEXT = GrapeCity.Documents.TextImports GCDRAW = GrapeCity.Documents.Drawing '' Draws vertical right-to-left Japanese text using a layout with horizontal columns.'' See also ArabicColumns, MultiLang and VerticalText.PublicClassVerticalTextJP Consttext = "日本語(にほんご、にっぽんご)は、主として、日本列島で使用されてきた言語である。日本手話を母語とする者などを除いて、ほぼ全ての日本在住者は日本語を第一言語とする。日本国は法令上、公用語を明記していないが、事実上の公用語となっており、学校教育の「国語」で教えられる。使用者は、日本国内を主として約1億3千万人。日本語の文法体系や音韻体系を反映する手話として日本語対応手話がある。" FunctionCreatePDF(ByVal stream AsStream) AsIntegerUsing clouds AsGCDRAW.Image = GCDRAW.Image.FromFile(Path.Combine("Resources", "Images", "clouds.jpg")), firth AsGCDRAW.Image = GCDRAW.Image.FromFile(Path.Combine("Resources", "Images", "firth.jpg")), lavender AsGCDRAW.Image = GCDRAW.Image.FromFile(Path.Combine("Resources", "Images", "lavender.jpg")) Dim fnt = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "NotoSansJP-Regular.ttf"))Dim ia = NewImageAlign(ImageAlignHorz.Left, ImageAlignVert.Top, True, True, True, False, False)Dim doc = NewGcPdfDocument() '' The TextLayout that will hold and render the text:Dim tl = NewTextLayout(72) tl.FirstLineIndent = 18 tl.ParagraphSpacing = 6 tl.FlowDirection = FlowDirection.VerticalRightToLeft tl.TextAlignment = TextAlignment.JustifiedDim tf = NewTextFormat() With {.Font = fnt, .FontSize = 12}'' Repeat test text to fill a few pages:For i = 0To24 tl.Append(text, tf) tl.AppendLine()Next '' Layout text in 4 horizontal columns: '' (The logic/code in this sample is identical to ArabicColumns):ConstNCOLS = 4Dim margin = 36.0FDim gap = 18.0FDim page = doc.NewPage() page.Landscape = TrueDim colHeight = (page.Size.Height - margin * 2 - gap * (NCOLS - 1)) / NCOLS tl.MaxWidth = page.Size.Width tl.MaxHeight = page.Size.Height tl.MarginLeft = margin tl.MarginRight = margin tl.MarginTop = margin tl.MarginBottom = margin + (colHeight + gap) * (NCOLS - 1)'' We can specify arbitrary rectangles for the text to flow around.'' In this case, we add 3 areas to draw some images: tl.ObjectRects = New List(OfObjectRect) From {NewObjectRect(page.Size.Width - margin - 267, margin, 267, 200),NewObjectRect(margin + 100, margin + 60, 133, 100),NewObjectRect(margin, page.Size.Height - margin - 301, 200, 301) }'' Convert object rects to image areas, adjust to provide nice looking padding:Dim rClouds = tl.ObjectRects(0).ToRectangleF() rClouds.Inflate(-4, -3)Dim rFirth = tl.ObjectRects(1).ToRectangleF() rFirth.Inflate(-4, -3)Dim rLavender = tl.ObjectRects(2).ToRectangleF() rLavender.Inflate(-4, -3) page.Graphics.DrawImage(clouds, rClouds, Nothing, ia) page.Graphics.DrawImage(firth, rFirth, Nothing, ia) page.Graphics.DrawImage(lavender, rLavender, Nothing, ia) '' THE call: it calculates the glyphs needed to draw the text, and lays it out: tl.PerformLayout(True) '' Loop while there is still text to render:Dim done = FalseWhileNot doneFor col = 1ToNCOLSDim nextcol = If(col < NCOLS, col, 0)'' TextSplitOptions tell TextLayout.Split() how to layout the remaining text.'' In this case we advance from column to column by updating top and bottom margins:Dim tso = NewTextSplitOptions(tl) With { .RestMarginTop = margin + (colHeight + gap) * nextcol, .RestMarginBottom = margin + (colHeight + gap) * (NCOLS - 1 - nextcol) }Dim rest AsTextLayout = NothingDim split = tl.Split(tso, rest) page.Graphics.DrawTextLayout(tl, PointF.Empty)If split <> SplitResult.SplitThen done = TrueExitForEndIf tl = restNextIfNot done Then page = doc.NewPage() page.Landscape = True'' We only want to render images on the first page, so clear ObjectRect:If tl.ObjectRectsIsNotNothingThen tl.ObjectRects = Nothing'' We need to redo the layout, but no need to recalculate the glyphs: tl.PerformLayout(False)EndIfEndIfEndWhile'''' Done: doc.Save(stream)Return doc.Pages.CountEndUsingEndFunctionEndClass