Example: /DynaPDF/Create PDF with Circle Text

Online Documentation   -   Statistics   -   FAQ   -   Plugin Parts (All, Dependencies)   -   Class hierarchy

New in Version 22.2 22.3 22.4 22.5 23.0 23.1 23.2 23.3 23.4 23.5 24.0 24.1

The list of the   topics,   classes,   interfaces,   controls,   modules,   global methods by category,   global methods by name,   screenshots,   licenses   and   examples.

Platforms to show: All Mac Windows Linux Cross-Platform

/DynaPDF/Create PDF with Circle Text


Required plugins for this example: MBS DynaPDF Plugin

You find this example project in your Plugins Download as a Xojo project file within the examples folder: /DynaPDF/Create PDF with Circle Text

This example is the version from Sat, 24th Feb 2023.

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) // finish page call pdf.EndPage // Close file call pdf.CloseFile // open PDF f.Launch End EventHandler
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
End Project

See also:

The items on this page are in the following plugins: MBS DynaPDF Plugin.


💬 Ask a question or report a problem