Platforms to show: All Mac Windows Linux Cross-Platform
/DynaPDF/DynaPDF Graphics/DynaPDF Graphics
Required plugins for this example: MBS DynaPDF Plugin, MBS Main Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /DynaPDF/DynaPDF Graphics/DynaPDF Graphics
This example is the version from Thu, 27th Nov 2019.
Project "DynaPDF Graphics.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class Window1 Inherits Window
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action()
Dim g As Graphics=OpenPrinterDialog
if g=nil then
Return
end if
draw g
End EventHandler
End Control
Control PushButton2 Inherits PushButton
ControlInstance PushButton2 Inherits PushButton
EventHandler Sub Action()
Dim pdf As New MyDynapdfMBS
Dim f1 As FolderItem = SpecialFolder.Desktop.Child("DynaPDF Graphics.pdf")
Dim f2 As FolderItem = SpecialFolder.Desktop.Child("DynaPDF Graphics.png")
Dim f3 As FolderItem = SpecialFolder.Desktop.Child("DynaPDF Graphics 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
draw g, pdf
// 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, 150, 0, 0, pdf.krfDefault, pdf.kpxfRGB, pdf.kcfFlate, pdf.kifmPNG)
End If
Call pdf.CloseFile
f1.Launch True
End EventHandler
End Control
Control EditField1 Inherits TextArea
ControlInstance EditField1 Inherits TextArea
End Control
Control Canvas1 Inherits Canvas
ControlInstance Canvas1 Inherits Canvas
EventHandler Sub Paint(g As Graphics, areas() As REALbasic.Rect)
draw g
End EventHandler
End Control
Sub draw(g as graphics, pdf as DynaPDFMBS = nil)
// this is normal code as you would use with graphics class anyway
// but we use GraphicsWrapper which can be DynaPDFGraphics, too.
// so graphics can go to printer, window, picture or PDF!
g.ForeColor=&c777777
g.DrawRect 0,0,g.Width-1,g.Height-1
g.ForeColor=&cFF0000
g.FillRect 100,100,200,200
g.DrawLine 0,0,100,100
g.ForeColor=&c000000
g.DrawString "Hello",150,150
g.DrawLine 100,100,200,200
g.ForeColor=&c00FF00
g.FillOval 100,0,100,100
g.ForeColor=&c0000FF
g.DrawOval 100,0,100,100
g.ForeColor=&cFFFF00
g.FillRect 0,100,100,100
g.ForeColor=&c000000
g.DrawRect 0,100,100,100
g.ForeColor=&c00FF00
g.FillRoundRect 0,250,100,100,20,20
g.ForeColor=&c000000
g.DrawRoundRect 0,250,100,100,20,20
Dim Points(6) as Integer
Points(1)=10 //X of Point 1
Points(2)=10 //Y of Point 1
Points(3)=75 //X of Point 2
Points(4)=30 //Y of Point 2
Points(5)=10 //X of Point 3
Points(6)=125 //Y of Point 3
g.ForeColor= RGB(100,200,255)
g.FillPolygon Points
g.ForeColor=&c000000
g.DrawPolygon Points
g.TextFont = "Times"
g.TextSize = 12
g.DrawString "Hello World", 200, 100
g.Bold = True
g.DrawString "Bold", 300, 100
g.Bold = False
g.Italic = True
g.DrawString "Italic", 300, 120
g.Italic = False
g.Underline = True
g.DrawString "Underlined", 300, 140
g.Underline = False
g.DrawString "Just a test with wrapping", 300, 160, 100
g.DrawString "Just a test with condensed", 300, 200, 100, true
// test picture drawing
dim logo as Picture = LogoMBS(200)
g.DrawPicture logo, 200, 500
g.DrawPicture logo, 50, 500, 100, 200, 50, 50, 100, 100
// set a pixel
g.Pixel(400,400)=&cFFFFFF
// StyledTextPrinter is not supported for DynaPDF's graphics object
If pdf = Nil Then
Dim stp As StyledTextPrinter = EditField1.StyledTextPrinter(g, 200)
stp.DrawBlock 200,500,250
Else
Call pdf.WriteStyledTextEx(200, 500, 200, 250, pdf.ktaLeft, EditField1)
End If
End Sub
End Class
MenuBar MenuBar1
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 iOS
- /DynaPDF/DynaPDF Graphics/ListBoxReport
- /DynaPDF/DynaPDF Graphics/Reporting/List Of Orders
- /DynaPDF/DynaPDF Graphics/VectorGraphics
- /DynaPDF/DynaPDF Graphics/VectorGraphics Alignments
- /DynaPDF/DynaPDF PDF Viewer
- /DynaPDF/DynaPDF Transparency Color Test
- /DynaPDF/DynaPDF transparent images/DynaPDF transparent images console
The items on this page are in the following plugins: MBS DynaPDF Plugin.