Platforms to show: All Mac Windows Linux Cross-Platform
/DynaPDF/DynaPDF Graphics/VectorGraphics Alignments
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 Alignments
This example is the version from Tue, 4th May 2020.
Project "VectorGraphics Alignments.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 r As New RectShape
r.x = 0
r.y = 0
r.Width = 1000
r.Height = 1
r.FillColor = &c000000
group.Append r
For y As Integer = 0 To 5
#If XojoVersion < 2019.02
Dim s As New StringShape
s.HorizontalAlignment = StringShape.Alignment.Center
s.VerticalAlignment = CType(y, StringShape.Alignment)
s.Text = "Vertical "+Str(y)
s.TextFont = "Helvetica"
#Else
// since Xojo 2019r2 we have TextShape, which is a renamed StringShape
Dim s As New TextShape
s.HorizontalAlignment = TextShape.Alignment.Center
s.VerticalAlignment = CType(y, TextShape.Alignment)
s.Value = "Vertical "+Str(y)
s.FontName = "Helvetica"
#EndIf
s.Bold = True
s.X = y * 80
s.Y = 0
group.Append(s)
Next
r= New RectShape
r.x = 200
r.y = 200
r.Width = 1
r.Height = 1000
r.FillColor = &c000000
group.Append r
For y As Integer = 0 To 5
#If XojoVersion < 2019.02
Dim s As New StringShape
s.Text = "Horizontal "+Str(y)
s.TextFont = "Helvetica"
s.HorizontalAlignment = CType(y, StringShape.Alignment)
s.VerticalAlignment = StringShape.Alignment.Center
#Else
Dim s As New TextShape
s.Value = "Horizontal "+Str(y)
s.FontName = "Helvetica"
s.HorizontalAlignment = CType(y, TextShape.Alignment)
s.VerticalAlignment = TextShape.Alignment.Center
#EndIf
s.Bold = True
s.X = 200
s.Y = y * 80+200
group.Append(s)
Next
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/Create numbered pages
- /DynaPDF/DynaPDF Graphics/DynaPDF Graphics
- /DynaPDF/DynaPDF Graphics/Reporting/GasReport/GasReport
- /DynaPDF/DynaPDF Graphics/Reporting/List Of Orders
- /DynaPDF/DynaPDF Graphics/Reporting/List Of Products
- /DynaPDF/DynaPDF Graphics/Reporting/List Of Products Preview
- /DynaPDF/DynaPDF Graphics/Reporting/ListBoxReport
- /DynaPDF/DynaPDF Merge 2 to 1
- /DynaPDF/DynaPDF transparent images/DynaPDF transparent images console
The items on this page are in the following plugins: MBS DynaPDF Plugin.