Platforms to show: All Mac Windows Linux Cross-Platform
/DynaPDF/DynaPDF Graphics/Reporting/List Of Products
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/Reporting/List Of Products
This example is the version from Fri, 2nd May 2019.
Project "List Of Products.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class MainWindow Inherits Window
Control RunReportButton Inherits PushButton
ControlInstance RunReportButton Inherits PushButton
EventHandler Sub Action()
Dim ordersDB As New SQLiteDatabase
// Set Database File
ordersDB.DatabaseFile = GetDBFile
// Connect to the database
If ordersDB.databaseFile.Exists Then
// The database file already exists, so we want to connect to it.
If ordersDB.Connect = False Then
// there was an error connecting to the database
MsgBox("Database Error: " + Str(ordersDB.ErrorCode) + EndOfLine + EndOfLine + OrdersDB.ErrorMessage)
Return
End If
Else
MsgBox("Database not found.")
Return
End If
// Build the SQL statement that will be used to select the records
Dim sql As String = "SELECT * FROM Products"
Dim rpt As New ListOfProducts
// Now we select the records from the database and add them to the list.
Dim rs As RecordSet
rs = ordersDB.SQLSelect(sql)
If rs = Nil Then
Beep
MsgBox("No records found to print.")
Else
Dim ps As New PrinterSetup
// Text is larger in 64-bit when the Max resolutions are not specified,
// but remains tiny when set to -1, which is supposed to select
// the max resolution available for the print device.
// ps.MaxHorizontalResolution = -1 ' text still tiny
// ps.MaxVerticalResolution = -1 ' text still tiny
If ps.PageSetupDialog Then
Dim g As Graphics
g = OpenPrinterDialog(ps, Nil)
If g <> Nil Then
// if the report runs successfully
If rpt.Run(rs, ps) Then
rpt.Document.Print(g)
End If
End If
End If
End If
End EventHandler
End Control
Control Label1 Inherits Label
ControlInstance Label1 Inherits Label
End Control
Control RunReportButton1 Inherits PushButton
ControlInstance RunReportButton1 Inherits PushButton
EventHandler Sub Action()
Dim ordersDB As New SQLiteDatabase
// Set Database File
ordersDB.DatabaseFile = GetDBFile
// Connect to the database
If ordersDB.databaseFile.Exists Then
// The database file already exists, so we want to connect to it.
If ordersDB.Connect = False Then
// there was an error connecting to the database
MsgBox("Database Error: " + Str(ordersDB.ErrorCode) + EndOfLine + EndOfLine + OrdersDB.ErrorMessage)
Return
End If
Else
MsgBox("Database not found.")
Return
End If
// Build the SQL statement that will be used to select the records
Dim sql As String = "SELECT * FROM Products"
Dim rpt As New ListOfProducts
// Now we select the records from the database and add them to the list.
Dim rs As RecordSet
rs = ordersDB.SQLSelect(sql)
If rs = Nil Then
Beep
MsgBox("No records found to print.")
Else
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
Dim ps As New PrinterSetup
// Text is larger in 64-bit when the Max resolutions are not specified,
// but remains tiny when set to -1, which is supposed to select
// the max resolution available for the print device.
// ps.MaxHorizontalResolution = -1 ' text still tiny
// ps.MaxVerticalResolution = -1 ' text still tiny
// if the report runs successfully
If rpt.Run(rs, ps) Then
rpt.Document.Print(g)
End If
// for debugging, show temp picture
Dim p As Picture = pdf.PageGraphicsPicture
p.Save(f2, p.SaveAsPNG)
Call pdf.EndPage
Call pdf.RenderPageToImage(1, f3, 150, 0, 0, pdf.krfDefault, pdf.kpxfRGB, pdf.kcfFlate, pdf.kifmPNG)
Call pdf.CloseFile
f1.Launch True
End If
End EventHandler
End Control
Private Function GetDBFile() As FolderItem
Dim dbFile As FolderItem = SpecialFolder.GetResource("Orders.sqlite")
Return dbFile
End Function
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 ListOfProducts Inherits Report
Control Label1 Inherits ReportLabel
ControlInstance Label1 Inherits ReportLabel
End Control
Control Label2 Inherits ReportLabel
ControlInstance Label2 Inherits ReportLabel
End Control
Control Label3 Inherits ReportLabel
ControlInstance Label3 Inherits ReportLabel
End Control
Control Label4 Inherits ReportLabel
ControlInstance Label4 Inherits ReportLabel
End Control
Control Field1 Inherits ReportField
ControlInstance Field1 Inherits ReportField
End Control
Control Field2 Inherits ReportField
ControlInstance Field2 Inherits ReportField
End Control
Control Field3 Inherits ReportField
ControlInstance Field3 Inherits ReportField
End Control
Control Picture1 Inherits ReportPicture
ControlInstance Picture1 Inherits ReportPicture
End Control
ReportSection Body
ReportSection PageFooter
ReportSection PageHeader
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
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/ListBoxReport
- /DynaPDF/DynaPDF Graphics/Reporting/GasReport/GasReport
- /DynaPDF/DynaPDF Graphics/Reporting/List Of Orders
- /DynaPDF/DynaPDF Graphics/Reporting/List Of Orders with Background
- /DynaPDF/DynaPDF Graphics/VectorGraphics
- /DynaPDF/DynaPDF Merge 2 to 1
- /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.