Drawing text should primarily be used for labelling selected details of a drawing. An exception could be texts with a clear structure in the form of rows and columns - as is typical for tables, for example. Project 3 therefore presents a simple database report that was drawn using methods of the Cairo class.
In order to be able to test the project without any problems, an SQLite3 database with the database table 'contacts' in the project folder is provided as a database.
Figure 25.1.13.1: Data browser for the DB data
To realise your own projects, you will also find brief instructions on how to create an SQLite3 database in project 3 'Database report'. In this you will also find the necessary SQL instructions.
The DB report as a PDF file has a different layout for the first page - compared to all subsequent pages - but the same design for the data rows and the footer. There is only a header on the first page, in which the names of the database and the database table as well as the print date are specified:
Figure 25.1.13.1.1: DB report - 1st page
All subsequent pages look like this:
Figure 25.1.13.1.2: DB report - page 2 to k
Only a subset of all data is displayed in this DB report. The selection made is sufficient for an address list. However, if you want to display all data, you must change the SQL statements for the DB query and certainly also change the PDF layout from portrait to landscape format.
The page number is displayed in the footer under a closing line:
Figure 25.1.13.1.3: Footer
The dotted lines shown in all the images above were only used as control lines during testing and can be omitted in the finished report.
Drawing the DB report with methods of the Cairo class is based on the following considerations:
In the ExportPDF() procedure, the DB report is drawn using further procedures and functions:
Private Sub ExportPDF() Dim PDFSurface As CairoPdfSurface Dim sPfadPDFDatei, sMessage As String Dim iDataSet As Integer ' Initialisation iCWidth = PDF_WIDTH - MARGIN_LEFT - MARGIN_RIGHT '-- Content-Width (Millimeter) iCHeight = PDF_HEIGHT - MARGIN_TOP - MARGIN_BOTTOM '-- Content-Height (Millimeter) iCurrentPage = 1 '-- Page number of the current page iCurrentTableRow = 1 '-- Number of table rows on the current page fCurrentY = 0 '-- y-coordinate on the current page sPfadPDFDatei = User.Home &/ "kontakte.pdf" PDFSurface = New CairoPdfSurface(sPfadPDFDatei, PDF_WIDTH, PDF_HEIGHT) ' DIN A4 - Hochformat Cairo.Begin(PDFSurface) ' Shift of the coordinate origin - >> Left = MARGIN_LEFT, Top = MARGIN_TOP Cairo.Matrix = Cairo.Matrix.Translate(MMToPoints(MARGIN_LEFT), MMToPoints(MARGIN_TOP)) Cairo.Matrix = Cairo.Matrix.Scale(1, 1) '-- Zoom-Factor = 1 Cairo.Font.Name = FONT_NAME GetDBData() '-- Providing the DB data to be displayed (DB result) If resDBData.Count = 0 Then sMessage = "<font color='red'><center>The DB selection set is empty.</font>" sMessage &= "<hr>" sMessage &= "A DB report cannot be generated!</center>" Message.Warning(sMessage) Return Endif DrawHeader() DrawDatabaseInformation() DrawTableHeader() resDBData.MoveTo(0) '-- Set data record pointer to the first data record DrawTableRow() '-- Show data record DrawFooter() DrawBorder() '-- For testing purposes only For iDataSet = 1 To resDBData.Max '-- Draw all data records (text) of the selection set If iCurrentPage = 1 Then If iCurrentTableRow = iPage1RowMax Then iCurrentPage = 2 iCurrentTableRow = 0 fCurrentY = 0 Cairo.ShowPage() DrawBorder() '-- Only for controls in testing DrawTableHeader() DrawFooter() Endif resDBData.MoveTo(iDataSet) DrawTableRow() Inc iCurrentTableRow Else If iCurrentTableRow = iPage2RowMax Then Inc iCurrentPage iCurrentTableRow = 0 fCurrentY = 0 Cairo.ShowPage() DrawBorder() '-- Only for controls in testing DrawTableHeader() DrawFooter() Endif resDBData.MoveTo(iDataSet) DrawTableRow() Inc iCurrentTableRow Endif Next Cairo.End() Desktop.Open(sPfadPDFDatei) '-- Show DB-Report End
The complete, extensive source code for project 3 can be found in the download area in a project archive.