Platforms to show: All Mac Windows Linux Cross-Platform
/DynaPDF/Create PDF with Circle Text
Required plugins for this example: MBS DynaPDF Plugin
Last modified Thu, 4th Dec 2024.
You find this example project in your MBS Xojo Plugin download as a Xojo project file within the examples folder: /DynaPDF/Create PDF with Circle Text
Download this example: Create PDF with Circle Text.zip
Project "Create PDF with Circle Text.xojo_binary_project"
FileTypes
Filetype Text
End FileTypes
MenuBar MenuBar1
MenuItem UntitledMenu1 = ""
MenuItem FileMenu = "&File"
MenuItem FileQuit = "Quit"
MenuItem UntitledMenu5 = ""
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem UntitledMenu0 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "Clear"
MenuItem UntitledMenu4 = ""
MenuItem UntitledMenu3 = ""
MenuItem UntitledMenu2 = ""
End MenuBar
Class App Inherits Application
EventHandler Sub Open()
Dim pdf As New MyDynapdfMBS
dim f as FolderItem = SpecialFolder.Desktop.Child("Create PDF with Circle Text.pdf")
// create new PDF
call pdf.CreateNewPDF f
pdf.SetLicenseKey "Starter" // For this example you can use a Starter, Lite, Pro or Enterprise License
// new page
call pdf.Append
If True Then
Const pi = 3.1415926535897932384626433832795
Call pdf.SetFontEx("Arial", pdf.kfsRegular, 12.0, True, pdf.kcpUnicode)
dim txt as string = "This text flows around a circle... "
Dim Len As Integer = Len(txt)
dim width as double = pdf.GetTextWidth(txt)
// circumference = d * pi or 2 * r * pi
dim r as double = width / pi * 0.5
// we need two rotations
// at -90 degree the first character should have rotation of 0 degree
// and the text should go in a circle.
// so we calculate first the destination position for a character and
// then we rotate it there in place
dim m as new DynapdfMatrixMBS
dim alpha, w, si, co, x, y as double
dim a as double = -90.0 / 180.0 * pi
dim g as double = 0.0
dim character as string = left(txt,1)
w = pdf.GetTextWidth(character)
// We change the rotating angle, so we rotate character in the center
// We subtract it back later with WriteAngleText()
g = w / r * 0.5
a = a + g
for i as integer = 1 to len
// calculate length of character
character = mid(txt,i,1)
w = pdf.GetTextWidth(character)
si = sin(a)
co = cos(a)
// we rotate the coordinate system at point 250, 590...
m.a = co
m.b = si
m.c = -si
m.d = co
m.x = 350.0
m.y = 690.0
x = -r
y = 0.0
m.Transform(x, y)
alpha = ((a-g) * 180.0 / pi) + 90.0
call pdf.WriteAngleText(character, alpha, x, y, 0.0, 0.0)
a = a - w / r // Radians
Next
end if
Const pi = 3.1415926535897932384626433832795
Call pdf.SetFontEx("Arial", pdf.kfsRegular, 9.6, True, pdf.kcpUnicode)
Dim txt As String = "* TRY ROTATING TEXT INSIDE A CIRCLE TURNING ON THE RIGHT "
Dim Len As Integer = Len(txt)
Dim width As Double = pdf.GetTextWidth(txt)
// circumference = d * pi or 2 * r * pi
Dim r As Double = width / pi * 0.5
Dim m As New DynapdfMatrixMBS
Dim alpha, w, si, co, x, y As Double
Dim a As Double = 90.0 / 180.0 * pi
Dim g As Double = 0.0
Dim character As String = Left(txt,1)
w = pdf.GetTextWidth(character)
// We change the rotating angle, so we rotate character in the center
// We subtract it back later with WriteAngleText()
g = w / r * 0.5
a = a + g
For i As Integer = 1 To Len
// calculate length of character
character = Mid(txt,i,1)
w = pdf.GetTextWidth(character)
si = Sin(a)
co = Cos(a)
a = a + w / r // Radians
// we rotate the coordinate system at point 250, 590...
m.a = co
m.b = si
m.c = -si
m.d = co
m.x = 250.0
m.y = 600.0
x = -r - 8
y = 0.0
m.Transform(x, y)
alpha = ((a-g) * 180.0 / pi) - 90.0
Call pdf.WriteAngleText(character, alpha, x, y, 0.0, 0.0)
Next
Call pdf.SetStrokeColor pdf.RGB(0,0,0) // red
Call pdf.DrawCircle(250,600, 64, pdf.kfmStroke)
Call pdf.DrawCircle(250,600, 48, pdf.kfmStroke)
// newer way:
Call pdf.SetFontEx("Arial", pdf.kfsRegular, 14, True, pdf.kcpUnicode)
Var radius As Double = 50
Var PosX As Double = 250
Var PosY As Double = 300
DrawRoundText pdf, "Approved by", -40, radius, PosX, PosY, True
DrawRoundText pdf, "Christian Schmitz", 22, radius, PosX, PosY, False
Call pdf.SetStrokeColor pdf.RGB(0,0,0) // red
Call pdf.DrawCircle(PosX, PosY, 64, pdf.kfmStroke)
Call pdf.DrawCircle(PosX, PosY, 48, pdf.kfmStroke)
// finish page
call pdf.EndPage
// Close file
call pdf.CloseFile
// open PDF
f.Launch
End EventHandler
Sub DrawRoundText(pdf as MyDynapdfMBS, txt as string, StartAngle as double, r as double, PosX as double, PosY as double, Mirror as Boolean)
Const pi = 3.1415926535897932384626433832795
Var Len As Integer = Len(txt)
Var width As Double = pdf.GetTextWidth(txt)
// circumference = d * pi or 2 * r * pi
Var m As New DynapdfMatrixMBS
Var alpha, w, si, co, x, y As Double
Var a As Double = StartAngle / 180.0 * pi
Var g As Double = 0.0
Var character As String = Left(txt,1)
w = pdf.GetTextWidth(character)
// We change the rotating angle, so we rotate character in the center
// We subtract it back later with WriteAngleText()
g = w / r * 0.5
If Mirror Then
a = a - g
else
a = a + g
End If
For i As Integer = 1 To Len
// calculate length of character
character = Mid(txt,i,1)
w = pdf.GetTextWidth(character)
si = Sin(a)
co = Cos(a)
Dim dw As Double = w / r
If Mirror Then
a = a - dw
Else
a = a + dw // Radians
End If
// we rotate the coordinate system at center of circle
m.a = co
m.b = si
m.c = -si
m.d = co
m.x = PosX
m.y = PosY
x = 0.0
y = 0.0
If mirror Then
x = -r - 2
alpha = ((a+dw/2) * 180.0 / pi) + 90.0
Else
x = -r - 8 - 2
alpha = ((a-dw/2) * 180.0 / pi) - 90.0
End If
// apply transformation to position
m.Transform(x, y)
Call pdf.WriteAngleText(character, alpha, x, y, 0.0, 0.0)
#If False Then // show lines
Dim x2 As Double = -r - 20
Dim y2 As Double = 0
m.Transform(x2, y2)
Call pdf.MoveTo(x,y)
Call pdf.LineTo(x2, y2)
Call pdf.StrokePath
#EndIf
Next
End Sub
End Class
Class MyDynaPDFMBS Inherits DynaPDFMBS
EventHandler Function Error(ErrorCode as integer, ErrorMessage as string, ErrorType as integer) As integer
// output all messages on the console:
System.DebugLog str(ErrorCode)+": "+ErrorMessage
// and display dialog:
Dim d as New MessageDialog //declare the MessageDialog object
Dim b as MessageDialogButton //for handling the result
d.icon=MessageDialog.GraphicCaution //display warning icon
d.ActionButton.Caption="Continue"
d.CancelButton.Visible=True //show the Cancel button
// a warning or an error?
if BitAnd(ErrorType, me.kE_WARNING) = me.kE_WARNING then
// if user decided to ignore, we'll ignore
if IgnoreWarnings then Return 0
d.Message="A warning occurred while processing your PDF code."
// we add a third button to display all warnings
d.AlternateActionButton.Caption = "Ignore warnings"
d.AlternateActionButton.Visible = true
else
d.Message="An error occurred while processing your PDF code."
end if
d.Explanation = str(ErrorCode)+": "+ErrorMessage
b=d.ShowModal //display the dialog
Select Case b //determine which button was pressed.
Case d.ActionButton
Return 0 // ignore
Case d.AlternateActionButton
IgnoreWarnings = true
Return 0 // ignore
Case d.CancelButton
Return -1 // stop
End select
End EventHandler
Property IgnoreWarnings As Boolean
End Class
Sign
End Sign
End Project
See also:
- /DynaPDF/Create PDF in memory
- /DynaPDF/Create PDF with Angle Rectangles
- /DynaPDF/Create PDF with bezier curve
- /DynaPDF/Create PDF with Colors
- /DynaPDF/Create PDF with Dashed Line
- /DynaPDF/Create PDF with DPart Metadata
- /DynaPDF/Create PDF with Line
- /DynaPDF/Create PDF with Picture file
- /DynaPDF/Create PDF with Round Rectangles
- /DynaPDF/Create PDF with Trace
Download this example: Create PDF with Circle Text.zip
The items on this page are in the following plugins: MBS DynaPDF Plugin.
