''
'' 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
Imports System.Numerics
'' Shows how to use GcPdfGraphics.Transform to rotate a text string.
'' See also RotatedText2.
Public Class RotatedText
Function CreatePDF(ByVal stream As Stream) As Integer
'' Rotation angle, degrees clockwise:
Dim angle = -45.0F
''
Dim doc = New GcPdfDocument()
Dim g = doc.NewPage().Graphics
'' Create a text layout, pick a font and font size:
Dim tl = g.CreateTextLayout()
tl.DefaultFormat.Font = StandardFonts.Times
tl.DefaultFormat.FontSize = 24
'' Add a text, and perform layout:
tl.Append("Rotated text.")
tl.PerformLayout(True)
'' Text insertion point at (1",1"):
Dim ip = New PointF(72, 72)
'' Now that we have text size, create text rectangle with top left at insertion point:
Dim rect = New RectangleF(ip.X, ip.Y, tl.ContentWidth, tl.ContentHeight)
'' Rotate the text around its bounding rect's center:
'' we now have the text size, and can rotate it about its center:
g.Transform = Matrix3x2.CreateRotation((angle * Math.PI) / 180.0F, New Vector2(ip.X + tl.ContentWidth / 2, ip.Y + tl.ContentHeight / 2))
'' Draw rotated text and bounding rectangle:
g.DrawTextLayout(tl, ip)
g.DrawRectangle(rect, Color.Black, 1)
'' Remove rotation and draw the bounding rectangle where the non-rotated text would have been:
g.Transform = Matrix3x2.Identity
g.DrawRectangle(rect, Color.ForestGreen, 1)
''
'' Done:
doc.Save(stream)
Return doc.Pages.Count
End Function
End Class