Xojo Conferences
MBSSep2018MunichDE
XDCMay2019MiamiUSA

Platforms to show: All Mac Windows Linux Cross-Platform

/DynaPDF/Tables/older examples/TablePDF multiple page
Function:
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/Tables/older examples/TablePDF multiple page
This example is the version from Sat, 9th Nov 2012.
Project "TablePDF multiple page.rbp"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class Window1 Inherits Window
Control Listbox1 Inherits Listbox
ControlInstance Listbox1 Inherits Listbox
EventHandler Sub Open() me.ColumnAlignment(0)=me.AlignCenter me.ColumnAlignment(2)=me.AlignRight End EventHandler
End Control
EventHandler Sub Open() dim pdf as new MyDynaPDFMBS pdf.SetLicenseKey "Starter" // For this example you can use a Starter, Lite, Pro or Enterprise License FillList dim outfile as FolderItem = SpecialFolder.Desktop.Child("TablePDF multiple page.pdf") call pdf.CreateNewPDF(nil) // the output file is created later call pdf.SetDocInfo pdf.kdiCreator, "Realbasic test application" call pdf.SetDocInfo pdf.kdiTitle, "My first table output" call pdf.SetPageCoords pdf.kpcTopDown call pdf.Append DrawListbox pdf, Listbox1, 50, 50, pdf.GetPageWidth-100 call pdf.EndPage // no error? if pdf.HaveOpenDoc then if not pdf.OpenOutputFile(outfile) then MsgBox "Can't write file to "+outfile.AbsolutePath quit end if end if call pdf.CloseFile outfile.Launch End EventHandler
Sub DrawListbox(pdf as dynapdfmbs, list as listbox, x as integer, y as integer, width as integer) dim columnwidths(-1) as integer dim height as integer = list.ListCount*21+22 dim rowsperpage as integer= (pdf.GetPageHeight-y)/21-5 // 5 rows on bottom redim columnwidths(list.ColumnCount) dim cw(-1) as string = split(List.ColumnWidths,",") dim remainingspace as integer = width-List.ColumnCount-1 dim starcount as integer for each s as string in cw if instr(s,"*")>0 then starcount=starcount+val(s) end if next for i as integer=0 to UBound(Cw) dim s as string = cw(i) dim columnwidth as integer if instr(s,"%")>0 then columnwidth=val(s)*(width-2.0)/100.0 elseif instr(s,"*")>0 then columnwidth=val(s)*remainingspace/starcount else columnwidth=val(s) end if columnwidths(i)=columnwidth remainingspace=remainingspace-columnwidth next dim rowcount as integer dim rowstodraw as integer dim currentrow as integer=0 dim font as string = list.TextFont if font="System" then font="Times" dim size as integer = list.TextSize if size=0 then size=12 while currentrow<list.ListCount-1 rowcount=list.ListCount-currentrow-1 if rowcount>rowsperpage then rowcount=rowsperpage end if DrawListboxFrame pdf, x, y, width, rowcount, list.ColumnCount, columnwidths call pdf.setfont font, pdf.kfsBold, size, true, pdf.kcp1252 dim ex as integer ex=x+1 for cx as integer=0 to list.ColumnCount-1 if list.ColumnAlignment(cx)=list.AlignCenter then call pdf.SetTextRect ex,y+2,columnwidths(cx),21 call pdf.WriteFText pdf.ktaCenter, list.Heading(cx) elseif list.ColumnAlignment(cx)=list.AlignRight then call pdf.SetTextRect ex,y+2,columnwidths(cx)-3,21 call pdf.WriteFText pdf.ktaRight, list.Heading(cx) else call pdf.SetTextRect ex+3,y+2,columnwidths(cx),21 call pdf.WriteFText pdf.ktaLeft, list.Heading(cx) end if ex=ex+columnwidths(cx)+1 next call pdf.SetFont font,pdf.kfsNone, size, true, pdf.kcp1252 for cy as integer=0 to rowcount-1 currentrow=currentrow+1 ex=x+1 for cx as integer=0 to list.ColumnCount-1 if list.ColumnAlignment(cx)=list.AlignCenter then call pdf.SetTextRect ex,y+23+cy*21,columnwidths(cx),21 call pdf.WriteFText pdf.ktaCenter, list.Cell(currentrow,cx) elseif list.ColumnAlignment(cx)=list.AlignRight then call pdf.SetTextRect ex, y+23+cy*21, columnwidths(cx)-3,21 call pdf.WriteFText pdf.ktaRight, list.Cell(currentrow,cx) else call pdf.SetTextRect ex+3,y+23+cy*21, columnwidths(cx),21 call pdf.WriteFText pdf.ktaLeft, list.Cell(currentrow,cx) end if ex=ex+columnwidths(cx)+1 next next if currentrow<list.ListCount-1 then call pdf.endpage call pdf.Append end if wend End Sub
Sub DrawListboxFrame(pdf as dynapdfmbs, x as integer, y as integer, width as integer, rowcount as integer, columncount as integer, columnwidths() as integer) dim height as integer = 22+21*rowcount call pdf.SetFillColor &hBBBBBB call pdf.SetStrokeColor 0 call pdf.Rectangle x,y,width-1, 21, pdf.kfmFill call pdf.Rectangle x,y,width-1,height,pdf.kfmStroke call pdf.SetColors 0 for i as integer=1 to rowcount call pdf.Moveto x,y+21*i call pdf.LineTo x+width-1,y+21*i next dim ex as integer=x+columnwidths(0) for i as integer=1 to columncount-1 call pdf.MoveTo ex,y call pdf.LineTo ex,y+height ex=ex+columnwidths(i)+1 next call pdf.StrokePath End Sub
Sub FillList() dim i as integer dim a,b,c as string for i=1 to 100 a=str(i) b="Item" c="$ "+Format(rnd*100000,"0") listbox1.AddRow a listbox1.Cell(listbox1.LastIndex,1)=b listbox1.Cell(listbox1.LastIndex,2)=c next End Sub
End Class
MenuBar MenuBar1
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 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
End Project

See also:

Feedback, Comments & Corrections

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





Links
MBS Xojo Chart Plugins