Platforms to show: All Mac Windows Linux Cross-Platform
/DynaPDF/DynaPDF Graphics/VectorGraphics
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/DynaPDF Graphics/VectorGraphics
This example is the version from Thu, 27th Nov 2019.
Project "VectorGraphics.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class MainWindow Inherits Window
Control VectorCanvas Inherits Canvas
ControlInstance VectorCanvas Inherits Canvas
EventHandler Sub Paint(g As Graphics, areas() As REALbasic.Rect)
g.DrawObject(group, 100, 100)
'mSavePicture = New Picture(Me.Width, Me.Height, 32)
'mSavePicture.Graphics.DrawObject(group, 100, 100)
'g.DrawPicture(mSavePicture, 0, 0)
End EventHandler
End Control
EventHandler Sub Open()
BuildGroup
MakePDF
End EventHandler
Sub BuildGroup()
Dim group As New Group2D
Dim z As New RectShape
z.Width = 1
z.Height = 1
z.FillColor = RGB(255, 0, 0)
z.Fill = 100
group.Append(z)
If True Then
Dim r As New RoundRectShape
r.Width = 120
r.Height = 120
r.Border = 100
r.BorderColor = RGB(0,0,0) // black
r.FillColor = RGB(255,102,102)
r.CornerHeight = 15
r.CornerWidth = 15
r.BorderWidth = 2.5
group.Append(r)
Dim s As New RoundRectShape
s.Width = 120
s.Height = 120
s.Border = 100
s.BorderColor = RGB(0,0,0) // black
s.FillColor = RGB(255,102,102)
s.CornerHeight = 15
s.CornerWidth = 15
s.BorderWidth = 2.5
s.X = r.X + 20
s.Y = r.Y + 20
group.Append(s)
Dim rr As New RectShape
rr.Width = 120
rr.Height = 120
rr.Border = 50
rr.BorderColor = RGB(0,0,0) // black
rr.FillColor = RGB(102,102, 255)
rr.BorderWidth = 5
rr.Fill = 50
rr.X = s.X + 20
rr.Y = s.Y + 20
group.Append(rr)
End If
If True Then
Dim p As Picture
p = New Picture(240, 200)
p.Graphics.ForeColor = &cFF0000
p.Graphics.FillOval(0, 0, 240, 200)
Dim px As New PixmapShape(p)
px.Rotation = 45 / 57.2958 // 45 Degrees in radians
px.x = 200
px.y = 200
group.Append(px)
Dim o As New OvalShape
o.Width = 60
o.Height = 120
o.FillColor = RGB(127, 127, 255)
o.x = px.x
o.y = px.y
group.Append(o)
End If
If True Then
Dim s As New StringShape
s.Text = "Hello World"
s.TextFont = "Helvetica"
s.Bold = True
s.Rotation = 3.14159 / 2 // (radians, 90 degrees = pi/2)
s.X = 0
s.Y = 200
group.Append(s)
End If
If True Then
Dim s As New StringShape
s.X = 20
s.Text = "Hello World"
s.HorizontalAlignment = StringShape.Alignment.Left
s.x = 200
s.y = 0
group.Append(s)
End If
If True Then
Dim a As New ArcShape
a.ArcAngle = 1.57
a.StartAngle = -1.57
a.FillColor = RGB(255, 0, 127)
a.x = 0
a.y = 300
group.Append(a)
Dim aa As New ArcShape
aa.ArcAngle = 1.57
aa.StartAngle = 3.14
aa.FillColor = RGB(0, 255, 127)
aa.x = 0
aa.y = 300
group.Append(aa)
End If
If false Then
Dim c As New CurveShape
c.ControlX(0) = 120
c.ControlY(0) = -40
c.Order = 1
c.X = 10
c.Y = 100
c.X2 = 250
c.Y2 = 100
'Dim g As New Group2D
'g.x = 200
'g.y = 300
'g.Append c
group.Append(c)
End If
If True Then
// ice cone
Dim fx As New FigureShape
fx.AddLine(0, 100, 50, 0)
fx.AddLine(50, 0, -50, 0)
fx.Border = 100 // opaque border
fx.BorderColor = &cFF0000 // red border
fx.FillColor = &cFFFF00 // yellow interior
fx.x = 0
fx.y = 300
group.Append fx
End If
Self.group = group
End Sub
Sub MakePDF()
Dim pdf As New MyDynapdfMBS
Dim f1 As FolderItem = SpecialFolder.Desktop.Child("DynaPDF VectorGraphics.pdf")
Dim f2 As FolderItem = SpecialFolder.Desktop.Child("DynaPDF VectorGraphics.png")
Dim f3 As FolderItem = SpecialFolder.Desktop.Child("DynaPDF VectorGraphics Rendered.png")
'pdf.SetLicenseKey "Starter" // For this example you can use a Starter, Lite, Pro or Enterprise License
If Not pdf.CreateNewPDF(f1) Then
Return
End If
Call pdf.Append
Dim g As Graphics = pdf.PageGraphics
g.DrawObject group, 100, 100
// for debugging, show temp picture
Dim p As Picture = pdf.PageGraphicsPicture
p.Save(f2, p.SaveAsPNG)
Call pdf.EndPage
if pdf.HasPro then
Call pdf.RenderPageToImage(1, f3, 72, 0, 0, pdf.krfDefault, pdf.kpxfRGB, pdf.kcfFlate, pdf.kifmPNG)
End If
Call pdf.CloseFile
f1.Launch True
End Sub
Property group As Group2D
End Class
MenuBar MainMenuBar
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
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
EventHandler Function PageBreak(LastPosX as double, LastPosY as double, PageBreak as boolean) As integer
PageBreak = true
Return -1 // stop
End EventHandler
Property IgnoreWarnings As Boolean
Property PageBreak As Boolean
End Class
End Project
See also:
- /DynaPDF/DynaPDF Database Invoice Example
- /DynaPDF/DynaPDF Graphics/DynaPDF Graphics
- /DynaPDF/DynaPDF Graphics/DynaPDF Graphics Desktop
- /DynaPDF/DynaPDF Graphics/Reporting/List Of Orders with Background
- /DynaPDF/DynaPDF Graphics/Reporting/List Of Products Preview
- /DynaPDF/DynaPDF Graphics/Reporting/ListBoxReport
- /DynaPDF/DynaPDF Graphics/VectorGraphics Alignments
- /DynaPDF/DynaPDF PDF Viewer
- /DynaPDF/DynaPDF Transparency Color Test
- /DynaPDF/DynaPDF transparent images/DynaPDF transparent images
The items on this page are in the following plugins: MBS DynaPDF Plugin.
