This example shows how to draw a single page table. ABCpdf does not provide table drawing routines itself so this example uses a Table Class to position the table elements.

 

   

Setup
 

We start by creating our document object and reading the data for our table. For the purposes of this example, we'll assume that our data is in a standard tab delimited format.

'... read the text
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(Server.MapPath("text6.txt"), 1)
theText = f.ReadAll()
Set theDoc = Server.CreateObject("ABCpdf12.Doc")
' set up document
theDoc.FontSize = 16
theDoc.Rect.Inset 20, 20

 

   

Rotate
 

We create a new table object and focus on our document. Focusing tells the table what rectangle it can occupy (it takes the current document rectangle) and how many columns of data it should be prepared for.

Columns are assigned relative widths and expand horizontally to fit the table rectangle. Here, we're specifying five columns and assigning the first column double width. So if our rectangle width is 600, the first column will be 200 wide and the second and subsequent columns will be 100 wide.

Set theTable = New Table
' focus the table on the document
theTable.Focus theDoc, 5
' first column has double width
theTable.Width(0) = 2

 

   

Add
 

We iterate through the table data adding rows and columns as we go. The first column of each row we draw right aligned - the others we draw left aligned. We frame the first and last rows, and we shade alternating rows using a light gray color. Finally, we save the document.

theRows = Split(theText, vbCrLf)
For i = 0 To UBound(theRows)
  ' add in new row
  theTable.NextRow
  theCols = Split(theRows(i), vbTab)
  ' add in columns
  For j = 0 To UBound(theCols)
    ' all but first column right aligned
    theDoc.HPos = 0
    If j > 0 Then theDoc.HPos = 1
    ' add the content to the cell
    theTable.NextCell
    theTable.AddText theCols(j)
  Next
  ' underline first row
  ' underline and overline last row
  ' shade every other row
  theTable.SelectRow theTable.Row
  If i = 0 Then theTable.Frame False, True, False, False
  If i = UBound(theRows) Then theTable.Frame True, True, False, False
  If i Mod 2 = 1 Then theTable.Fill "220 220 220"
Next
theDoc.Flatten
theDoc.Save "c:\mypdfs\table1.pdf"

 

   

Results
 

Using the following input data:

Planet Distance From Sun (miles) Diameter (miles) Year Length (days) Day Length (days)
Mercury 36,000,000 3,030 88 58.00
Venus 67,000,000 7,520 225 225.00
Earth 93,000,000 7,925 365 1.00
Mars 142,000,000 4,210 687 1.00
Jupiter 484,000,000 88,730 4,344 0.40
Saturn 888,000,000 74,975 10,768 0.40
Uranus 1,800,000,000 31,760 30,660 0.70
Neptune 2,800,000,000 30,600 60,150 0.65
Pluto 3,600,000,000 1,410 90,520 0.25

We get the following output.


table1.pdf