Platforms to show: All Mac Windows Linux Cross-Platform
/DynaPDF/DynaPDF Graphics/Reporting/List Of Products Preview
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 Preview
This example is the version from Fri, 2nd May 2019.
Project "List Of Products Preview.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 = True 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
ReportPreviewContainer1.ShowReport(rpt, rs)
End If
End EventHandler
End Control
Control Label1 Inherits Label
ControlInstance Label1 Inherits Label
End Control
Control ReportPreviewContainer1 Inherits ReportPreviewContainer
ControlInstance ReportPreviewContainer1 Inherits ReportPreviewContainer
End Control
Private Function GetDBFile() As FolderItem
Dim rscDB As Xojo.IO.FolderItem = Xojo.IO.SpecialFolder.GetResource("Orders.sqlite")
Dim dbFile As New FolderItem(rscDB.Path, FolderItem.PathTypeNative)
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 ReportPreviewContainer Inherits ContainerControl
Control ReportCanvas Inherits Canvas
ControlInstance ReportCanvas Inherits Canvas
EventHandler Function MouseDown(X As Integer, Y As Integer) As Boolean
mZoomed = Not mZoomed
ReportCanvas.Invalidate(False)
Return True
End EventHandler
EventHandler Sub MouseEnter()
If mZoomed Then
Me.MouseCursor = System.Cursors.MagnifySmaller
Else
Me.MouseCursor = System.Cursors.MagnifyLarger
End If
End EventHandler
EventHandler Function MouseWheel(X As Integer, Y As Integer, deltaX as Integer, deltaY as Integer) As Boolean
ReportScrollbar.Value = ReportScrollbar.Value + deltaY
End EventHandler
EventHandler Sub Paint(g As Graphics, areas() As REALbasic.Rect)
If mReportDocument <> Nil Then
// White report background
g.ForeColor = &cffffff
g.FillRect(0, 0, g.Width, g.Height)
// Draw current page of report
Dim page As Picture = mReportDocument.Page(mCurrentPage)
If mZoomed Then
g.DrawPicture(page, 0, 0, Me.Width, Me.Height, 0, ReportScrollbar.Value, Me.Width \ 2, Me.Height \ 2)
Else
g.DrawPicture(page, 0, 0, Me.Width, Me.Height, 0, ReportScrollbar.Value, Me.Width, Me.Height)
End If
End If
End EventHandler
End Control
Control PrintButton Inherits BevelButton
ControlInstance PrintButton Inherits BevelButton
EventHandler Sub Action()
PrintReport
End EventHandler
End Control
Control PreviousButton Inherits BevelButton
ControlInstance PreviousButton Inherits BevelButton
EventHandler Sub Action()
mCurrentPage = mCurrentPage - 1
If mCurrentPage < 1 Then mCurrentPage = 1
ShowPage
End EventHandler
End Control
Control NextButton Inherits BevelButton
ControlInstance NextButton Inherits BevelButton
EventHandler Sub Action()
mCurrentPage = mCurrentPage + 1
If mCurrentPage > mReportDocument.PageCount Then mCurrentPage = mReportDocument.PageCount
ShowPage
End EventHandler
End Control
Control ReportScrollbar Inherits ScrollBar
ControlInstance ReportScrollbar Inherits ScrollBar
EventHandler Function MouseWheel(X As Integer, Y As Integer, deltaX as Integer, deltaY as Integer) As Boolean
Me.Value = Me.Value + deltaY
Return True
End EventHandler
EventHandler Sub ValueChanged()
ReportCanvas.Invalidate(False)
End EventHandler
End Control
Control PDFButton Inherits BevelButton
ControlInstance PDFButton Inherits BevelButton
EventHandler Sub Action()
PDFReport
End EventHandler
End Control
Private Sub PDFReport()
mReport = New ListOfProducts
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 ps As New PrinterSetup
// make sure the page size for pdf is the same as in ps
Call pdf.SetPageWidth(ps.PageWidth)
Call pdf.SetPageHeight(ps.PageHeight)
Dim g As Graphics = pdf.PageGraphics
// set the resolution to 300 DPI for printing
'ps.MaxHorizontalResolution = 300
'ps.MaxVerticalResolution = 300
// if the report runs successfully
If mReport.Run(mData, ps) Then
mReport.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 Sub
Private Sub PrintReport()
mReport = New ListOfProducts
Dim ps As New PrinterSetup
// set the resolution to 300 DPI for printing
ps.MaxHorizontalResolution = 300
ps.MaxVerticalResolution = 300
If ps.PageSetupDialog Then
Dim g As Graphics
g = OpenPrinterDialog(ps, Nil)
If g <> Nil Then
// if the report runs successfully
If mReport.Run(mData, ps) Then
mReport.Document.Print(g)
End If
End If
End If
End Sub
Private Sub ShowPage()
ReportScrollbar.Maximum = mReportDocument.Page(mCurrentPage).Height - ReportCanvas.Height
ReportScrollbar.Value = 0
ReportCanvas.Invalidate(False)
End Sub
Sub ShowReport(rpt As Report, data As RecordSet)
// Save for use when printing
mReport = rpt
mData = data
Dim ps As New PrinterSetup
If rpt.Run(data, ps) Then
If rpt.Document <> Nil Then
mReportDocument = rpt.Document
mCurrentPage = 1
ShowPage
End If
End If
data.MoveFirst
PrintButton.Enabled = True
PDFButton.Enabled = True
End Sub
Property Private mCurrentPage As Integer
Property Private mData As RecordSet
Property Private mReport As Report
Property Private mReportDocument As Reports.RBReportDocument
Property Private mZoomed As Boolean
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/List Of Orders with Background
- /DynaPDF/DynaPDF Graphics/Reporting/List Of Products
- /DynaPDF/DynaPDF Graphics/VectorGraphics Alignments
- /DynaPDF/DynaPDF Makros
- /DynaPDF/DynaPDF Merge 2 to 1
- /DynaPDF/DynaPDF transparent images/DynaPDF transparent images
- /DynaPDF/DynaPDF transparent images/DynaPDF transparent images console
The items on this page are in the following plugins: MBS DynaPDF Plugin.