Platforms to show: All Mac Windows Linux Cross-Platform
Required plugins for this example: MBS DynaPDF Plugin
Last modified Fri, 19th Feb 2026.
You find this example project in your MBS Xojo Plugin download as a Xojo project file within the examples folder: /DynaPDF/Create PDF with Line
Download this example: Create PDF with Line.zip
Project "Create PDF with Line.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 Line.pdf")
pdf.SetLicenseKey "Starter" // For this example you can use a Starter, Lite, Pro or Enterprise License
// Create a new PDF
call pdf.CreateNewPDF f
// We want to use top-down coordinates
call pdf.SetPageCoords pdf.kpcTopDown
// Add a page
call pdf.Append
// black
call pdf.SetStrokeColor 0
// line down
call pdf.MoveTo(100,100)
call pdf.LineTo(200,200)
call pdf.StrokePath
// line up
call pdf.MoveTo(200,200)
call pdf.LineTo(300,100)
call pdf.StrokePath
// blue Rectangle
Call pdf.SetFillColor pdf.RGB(0, 0, 230)
Call pdf.Rectangle(100, 300, 300, 20, pdf.kfmFill)
call pdf.SetFont("Helvetica", 0, 12)
Call pdf.SetFillColor pdf.RGB(255, 255, 255)
Call pdf.SetStrokeColor pdf.RGB(255, 255, 255)
call pdf.WriteText 105, 303, "Hello World"
// draw some text and a rectangle around
Call pdf.SetFont("Helvetica", 0, 12)
Call pdf.SetFillColor 0 // black
Call pdf.SetStrokeColor 0
Var tx As Integer = 100
Var ty As Integer = 400
Var tw As Integer = 300
Var th As Integer = 100
Var TText As String = "Hello World"
var h as integer = pdf.GetFTextHeight(pdf.ktaLeft, TText)
Call pdf.WriteFTextEx tx, ty, tw, th, pdf.ktaLeft, TText
Var w As Integer = pdf.GetTextWidth(TText)
If h > 12 Then // for one line, we use w, otherwise tw
w = tw
end if
Call pdf.Rectangle(tx, ty, w+2, h+3, pdf.kfmStroke)
// end page
call pdf.EndPage
// Close page
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
Sign
End Sign
End Project
See also:
- /DynaPDF/Create PDF with Angle Rectangles
- /DynaPDF/Create PDF with Angle Text
- /DynaPDF/Create PDF with Arabic and Ligatures
- /DynaPDF/Create PDF with centimeters
- /DynaPDF/Create PDF with demo string
- /DynaPDF/Create PDF with Highlight
- /DynaPDF/Create PDF with japanese font
- /DynaPDF/Create PDF with object2d
- /DynaPDF/Create PDF with sum form field
- /DynaPDF/Create PDF with text block2
Download this example: Create PDF with Line.zip
The items on this page are in the following plugins: MBS DynaPDF Plugin.