Platforms to show: All Mac Windows Linux Cross-Platform

/DynaPDF/Tables/older examples/TablePDF single page

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 single page

This example is the version from Wed, 14th Sep 2021.

Project "TablePDF single page.xojo_binary_project"
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 dim outfile as FolderItem = SpecialFolder.Desktop.Child("TablePDF single page.pdf") call pdf.CreateNewPDF(nil) // the output file is created later call pdf.SetDocInfo pdf.kdiCreator, "Xojo 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.NativePath 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 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.kcpUnicode 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.kcpUnicode 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
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:

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

The biggest plugin in space...