MBS REALbasic Plugin Tutorial Videos
TablePDF Source
Class App
Inherits Application
// Constants
Const kFileQuitShortcut = Ctrl+Q
Const kFileQuit = E&xit
Const kEditClear = &Delete
End Class
Class Window1
Inherits Window
// Controls
ControlInstance
Sub Open() Handles Event
me.ColumnAlignment(0)=me.AlignCenter
me.ColumnAlignment(2)=me.AlignRight
End Sub
End ControlInstance
// Event implementations
Sub Open()
dim pdf as new MyDynaPDF
dim outfile as FolderItem=GetFolderItem("table.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 Sub
// Methods
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
redim columnwidths(list.ColumnCount)
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
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
call pdf.SetColors 0
for i as integer=1 to list.ListCount
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 list.ColumnCount-1
call pdf.MoveTo ex,y
call pdf.LineTo ex,y+height
ex=ex+columnwidths(i)+1
next
call pdf.StrokePath
dim font as string = list.TextFont
if font="System" then font="Times"
dim size as integer = list.TextSize
if size=0 then size=12
call pdf.SetFont font,pdf.kfsNone, size, true, pdf.kcp1252
for cy as integer=0 to list.ListCount-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(cy,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(cy,cx)
else
call pdf.SetTextRect ex+3,y+23+cy*21, columnwidths(cx),21
call pdf.WriteFText pdf.ktaLeft, list.Cell(cy,cx)
end if
ex=ex+columnwidths(cx)+1
next
next
call pdf.setfont font, pdf.kfsBold, size, true, pdf.kcp1252
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
End Sub
End Class
Class MyDynaPDF
Inherits DynaPDFMBS
// Event implementations
Function Error(ErrorCode as integer, ErrorMessage as string, ErrorType as integer) As integer
MsgBox ErrorMessage
End Function
End Class
Links
MBS Realbasic tutorial videos - Pfarrgemeinde Ministranten Nickenich