Platforms to show: All Mac Windows Linux Cross-Platform

/DynaPDF/Tables/Invoice with tables/DynaPDF Database Invoice Example with Tables


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/Tables/Invoice with tables/DynaPDF Database Invoice Example with Tables

Download this example: DynaPDF Database Invoice Example with Tables.zip

Project "DynaPDF Database Invoice Example with Tables.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
EventHandler Sub Open() InitCustomer InitArticles CreateInvoices quit End EventHandler
Sub CreateInvoices() const NUM_PAGES = 1000 dim r as new random dim pdf as new MyDynaPDFMBS dim ofile as FolderItem = SpecialFolder.Desktop.Child("DynaPDF Database Invoice Example.pdf") dim ifile as FolderItem = FindFile("invoice table template.pdf") 'pdf.TraceFile = SpecialFolder.Desktop.Child("test.log") call pdf.CreateNewPDF(ofile) call pdf.SetImportFlags( Bitwiseor(pdf.kifImportAll, pdf.kifImportAsPage)) call pdf.OpenImportFile(ifile, pdf.kptOpen, "") dim tmpl as integer = pdf.ImportPage(1) call pdf.CloseImportFile for i as integer = 1 to NUM_PAGES call pdf.Append // Statischer Hintergrund call pdf.PlaceTemplateEx(tmpl, 0.0, 0.0, 0.0, 0.0) // Rechnung mit Daten füllen dim idx as integer = r.InRange(0,UBound(Customers)) FillPage(PDF, Customers(idx)) call pdf.EndPage next // Seitennummern einfügen dim pageCount as integer = pdf.GetPageCount for i as integer = 1 to NUM_PAGES call pdf.EditPage(i) call pdf.SetFont("Arial", pdf.kfsRegular, 8.0, true, pdf.kcpUnicode) call pdf.WriteText(466.0, 681.5, str(i)+" von "+str(pageCount)) call pdf.EndPage next call pdf.CloseFile ofile.Launch(true) End Sub
Sub FillPage(pdf as DynaPDFMBS, record as Customer) dim sum as Double = 0.0 dim tax as Double = 0.0 dim x as double = 56.0 dim y as double = 176 Call pdf.SetPageCoords(pdf.kpcTopDown) call pdf.SetFont("Arial", pdf.kfsRegular, 12.0, true, pdf.kcpUnicode) // write address in one block with 15 point line height Var b As String = "\LD[15]"+_ Record.Company + EndOfLine + _ Record.Street + EndOfLine + _ Record.Zip + " "+Record.City call pdf.WriteFTextEx(x, y, 200.0, -1.0, pdf.ktaLeft, b) dim d as new date // Header data x = 466.0 y = 143 call pdf.ChangeFontSize(8.0) // date call pdf.WriteText(x, y, d.ShortDate) // customer number call pdf.WriteText(x, y + 27.5, str(Record.CustomerNr)) // order number call pdf.WriteText(x, y + 39.0, Record.OrderNr) // tax ID call pdf.WriteText(x, y + 50.0, Record.TaxID) x = 56.0 // invoice number dim r as new random call pdf.ChangeFontSize(14.0) call pdf.WriteText(x + 90.0, 318, str(r.InRange(1,1000000))) Call pdf.SetPageCoords(pdf.kpcTopDown) // create table const ColumnCount = 6 Const RowCount = 3 Dim tbl As DynaPDFTableMBS = pdf.CreateTable(RowCount, ColumnCount, 500.0, 10.0) 'Call tbl.SetBorderWidth(-1, -1, 1.0, 1.0, 1.0, 1.0) 'Call tbl.SetGridWidth( 1.0, 1.0) 'Call tbl.SetGridHorizontalColor(100, 100, 100) 'Call tbl.SetGridVerticalColor(100, 100, 100) Call tbl.SetBorderColor(-1, -1, 100, 100, 100) Call tbl.SetCellPadding(-1, -1, 2, 2, 2, 2) // add header row Dim rowNum As Integer = tbl.AddRow Call tbl.SetFlags rowNum, -1, tbl.ktfHeaderRow Call tbl.SetCellText rowNum, 0, pdf.ktaCenter, tbl.kcoTop, "Pos." Call tbl.SetCellText rowNum, 1, pdf.ktaCenter, tbl.kcoTop, "Article" Call tbl.SetCellText rowNum, 2, pdf.ktaCenter, tbl.kcoTop, "Description" Call tbl.SetCellText rowNum, 3, pdf.ktaCenter, tbl.kcoTop, "Quantity" Call tbl.SetCellText rowNum, 4, pdf.ktaCenter, tbl.kcoTop, "Price" Call tbl.SetCellText rowNum, 5, pdf.ktaCenter, tbl.kcoTop, "Total" // font for all Call tbl.SetFont(-1, -1, "Helvetica", 0) Call tbl.SetFontSize(-1, -1, 12) // header in bold Call tbl.SetFont(rowNum, -1, "Helvetica", pdf.kfsBold) Call tbl.SetFontSize(rowNum, -1, 15) // thick line below header Call tbl.SetBorderWidth(rowNum, -1, 0, 0, 0, 2) // column widths Call tbl.SetColWidth(0, 50, true) Call tbl.SetColWidth(1, 60, True) Call tbl.SetColWidth(2, 220, True) Call tbl.SetColWidth(3, 70, True) Call tbl.SetColWidth(4, 60, True) Call tbl.SetColWidth(5, 60, True) Var price As Double var num, pos as integer // now fill all the cells Dim count As Integer = r.InRange(1,10) For i As Integer = 0 To count Dim a As Article = Articles(r.InRange(0, UBound(Articles))) var Quantity as integer = r.InRange(1, 20) rowNum = tbl.AddRow pos = pos + 1 price = (Quantity * a.SinglePrice) Sum = sum + price Call tbl.SetCellText rowNum, 0, pdf.ktaRight, tbl.kcoTop, Str(pos) Call tbl.SetCellText rowNum, 1, pdf.ktaRight, tbl.kcoTop, Str(a.ArtNr) Call tbl.SetCellText rowNum, 2, pdf.ktaLeft, tbl.kcoTop, A.Description Call tbl.SetCellText rowNum, 3, pdf.ktaRight, tbl.kcoTop, Str(Quantity) Call tbl.SetCellText rowNum, 4, pdf.ktaRight, tbl.kcoTop, Format(a.SinglePrice, "0.00")+" €" Call tbl.SetCellText rowNum, 5, pdf.ktaRight, tbl.kcoTop, Format(price, "0.00")+" €" num = num + 1 Next // footer rowNum = tbl.AddRow Call tbl.SetCellText rowNum, 4, pdf.ktaRight, tbl.kcoTop, "Sum" Call tbl.SetCellText rowNum, 5, pdf.ktaRight, tbl.kcoTop, Format(sum, "0.00")+" €" Call tbl.SetBorderWidth(rowNum, -1, 0, 2, 0, 0) tax = sum * 0.19 rowNum = tbl.AddRow Call tbl.SetCellText rowNum, 4, pdf.ktaRight, tbl.kcoTop, "Tax" Call tbl.SetCellText rowNum, 5, pdf.ktaRight, tbl.kcoTop, Format(tax, "0.00")+" €" rowNum = tbl.AddRow Call tbl.SetCellText rowNum, 4, pdf.ktaRight, tbl.kcoTop, "Total" Call tbl.SetCellText rowNum, 5, pdf.ktaRight, tbl.kcoTop, Format(tax+sum, "0.00")+" €" Call tbl.SetBorderWidth(rowNum, 5, 0, 2, 0, 0) Call tbl.SetBorderWidth(rowNum, 4, 0, 2, 0, 0) // Draw the table now Call tbl.DrawTable(50.0, 400.0, 742.0 - 350) While tbl.HaveMore Call pdf.EndPage Call pdf.Append Call tbl.DrawTable(50.0, 50.0, 742.0) Wend Return y = y - 2.0 call pdf.MoveTo(x, y) call pdf.LineTo(x + 483.0, y) call pdf.StrokePath call pdf.WriteText(x + 5.0, y - 10.0, "Nettobetrag") call pdf.WriteFTextEx(x, y, 483.0, -1.0, pdf.ktaRight, Format(sum, "0.00")+" €") y = y - 14.0 call pdf.MoveTo(x, y) call pdf.LineTo(x + 483.0, y) call pdf.StrokePath call pdf.WriteText(x + 5.0, y - 10.0, "Umsatzsteuer 19%") tax = sum * 0.19 call pdf.WriteFTextEx(x, y, 483.0, -1.0, pdf.ktaRight, Format(tax, "0.00")+" €") y = y - 14.0 call pdf.MoveTo(x, y) call pdf.LineTo(x + 483.0, y) call pdf.StrokePath call pdf.SetFont("Arial", pdf.kfsBold, 12.0, true, pdf.kcpUnicode) call pdf.WriteText(x + 5.0, y - 13.0, "Gesamtbetrag") call pdf.WriteFTextEx(x, y - 1.0, 483.0, -1.0, pdf.ktaRight, Format(tax+sum, "0.00")) y = y - 18.0 call pdf.MoveTo(x, y) call pdf.LineTo(x + 483.0, y) y = y - 2.0 call pdf.MoveTo(x, y) call pdf.LineTo(x + 483.0, y) call pdf.StrokePath End Sub
Function FindFile(name as string) As FolderItem // Look for file in parent folders from executable on dim parent as FolderItem = app.ExecutableFile.Parent while parent<>Nil dim file as FolderItem = parent.Child(name) if file<>Nil and file.Exists then Return file end if parent = parent.Parent wend End Function
Sub InitArticles() Articles.Append new Article(3224567, "Brathänchen (800g)", 12.49) Articles.Append new Article(5678321, "200g Aufschnitt", 1.98) Articles.Append new Article(4559021, "Bratwurst 10er Pack", 4.49) Articles.Append new Article(5679803, "1 Kg Handwaschpaste Deluxe", 8.22) Articles.Append new Article(5447891, "Zahnpasta Erdber Geschmack", 0.99) Articles.Append new Article(2342389, "500g Ravioli", 1.78) Articles.Append new Article(1227432, "Mülleimer klein", 21.22) Articles.Append New Article(4534545, "Waschmittel", 12.30) Articles.Append New Article(3145314, "Bausteine", 10.99) Articles.Append New Article(4151345, "Papier A4", 3.99) Articles.Append New Article(1541551, "DVD Set", 21.99) End Sub
Sub InitCustomer() customers.Append new Customer("Gesellschaft für Entwicklung und Ökologie des deutschen Nahrungsmittelwesens",_ "Frau Stefan",_ "Raketenstraße 2",_ "38462",_ "Ravensberg",_ 100003457,_ "-",_ "-") customers.Append new Customer("Rewe",_ "Herr Walter von Straußenberg",_ "Am kleinen Wäldchen 123",_ "56890",_ "Bad Berleburg",_ 100003434,_ "-",_ "-") customers.Append new Customer("Hit",_ "Frau Ingrid Wolter",_ "Lüdenscheider Straße 433",_ "58515",_ "Lüdenscheid",_ 100002447,_ "-",_ "-") customers.Append new Customer("Kaufpark",_ "Herr Gerald Ostheim",_ "Heedfelder Straße 33",_ "43312",_ "Wuppertal",_ 100005632,_ "-",_ "-") customers.Append new Customer("Aldi",_ "Frau Sabine Schnellstadt",_ "Bredde 36",_ "98834",_ "München",_ 100003129,_ "-",_ "-") customers.Append new Customer("Lidle",_ "Herr Manfred Klein",_ "Am Park 2",_ "67890",_ "Frankfurt am Main",_ 100009001,_ "-",_ "-") End Sub
Property Articles() As Article
Property Customers() As Customer
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&Ablage"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Bearbeiten"
MenuItem EditUndo = "&Rückgängig"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "&Ausschneiden"
MenuItem EditCopy = "&Kopieren"
MenuItem EditPaste = "&Einfügen"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "&Alles auswählen"
End MenuBar
Class Window1 Inherits Window
End Class
Class Customer
Sub Constructor(pCompany as string, pContactPerson as string, pStreet as string, pZip as string, pCity as string, pCustomerNr as integer, pOrderNr as string, pTaxID as string) city = pCity company = pCompany ContactPerson = pContactPerson CustomerNr = pCustomerNr OrderNr = pOrderNr Street = pStreet TaxID = pTaxID Zip = pZip End Sub
Property City As String
Property Company As string
Property ContactPerson As string
Property CustomerNr As Integer
Property OrderNr As string
Property Street As String
Property TaxID As string
Property Zip As String
End Class
Class Article
Sub Constructor(pArtNr as integer, pDescription as string, pSinglePrice as double) ArtNr = pArtNr Description = pDescription SinglePrice = pSinglePrice End Sub
Property ArtNr As Integer
Property Description As String
Property SinglePrice As Double
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

Download this example: DynaPDF Database Invoice Example with Tables.zip

The items on this page are in the following plugins: MBS DynaPDF Plugin.


The biggest plugin in space...