DynamicPDF™ Generator v3.0 for COM/ActiveX offers a Table page element to help you format content within your PDF pages. The table gives you the ability to add text as well as any page elements to each cell. Table also gives you the ability to control the flow of data between sections and pages. This topic explains how to use the table page element and provides examples on how to use the features listed above.

General Explanation

A table consists of one or more columns and one or more rows. Each row contains one or more cells. A cell can contain plain text or any Page element (we will look at adding other page elements to the table in the Adding Page Elements to Cells topic). Formatting of the text (background color, font, font size, text color and alignment) in each cell is handled in a hierarchical manner. Specifically, the formatting specified within cell takes precedence over the formatting specified within a row which in turn takes precedence over formatting specified within a table. For example, if you want the entire table to contain a certain format, then you could set all the formatting information on the table and every cell in every row would contain the appropriate formatting. If you want a row to contain some formatting different than the rest of the table then you can specify the text format on the row and every cell in that row will contain the particular formatting. Finally, if you want a cell to contain a different formatting than the rest of the row then you can specify the formatting on the individual cell. Note that the Column class contains no formatting information. Understanding this hierarchy will help you easily format any cell within the table as needed.

Simple Example

To create a table that will appear on the PDF you should first instantiate a Table class. You will need to specify the starting x and y coordinate to place the table on the page as well as a height and width. This height and width should be the amount of vertical or horizontal space you have for the table on a particular page. You do not need to try and guess the height and width of your final table here. Also, any formatting that you want to be the default for the entire table should be specified here.

The first thing you should do to the table is define the width of your columns for the table. Remember that once set, column widths are read-only and can not be changed.

Once the columns are defined, then you can populate the table with data. This is done first by adding a row to the table and then adding cells to that row. You can add fewer cells to the row than the existing number of columns in the table but you can never add more cells than columns. Cells can also span multiple columns. The key here is that the sum of all the column spans for all the cells in a row must be less than or equal to the total number of columns in that table.

As you are adding your rows to the table you can set a particular height for that row. This height will be the minimum height for the row. If needed, the height will automatically expand to fit the largest element (either text or any page element that implements IArea) in that row. Take a look at the third row in the example below.

[ASP - VBScript]
<!-- METADATA TYPE="typelib" UUID="{DF9225FE-94A4-490D-8CAD-E8366CE621D3}"-->
<%
    Option Explicit
    Dim MyDocument
    Dim MyTable
    Dim MyPage
    Set MyDocument = Server.CreateObject( "DynamicPDF.Document" )
    Set MyPage = MyDocument.AddPage()
    Set MyTable = MyPage.AddTable( 0, 0, 600, 600 )
    ' Add columns to the table
    MyTable.AddColumn ( 150 )
    MyTable.AddColumn ( 90 )
    MyTable.AddColumn ( 90 )
    MyTable.AddColumn ( 90 )
    ' Add rows to the table and add cells to the rows.The values 000000 and 808080 represent black and Gray Color
    Dim MyRow1
    Set MyRow1 = MyTable.AddRow( DPDF_Font_HelveticaBold, 16, "000000", "808080" )
    MyRow1.Align = DPDF_Align_Center
    MyRow1.VAlign = DPDF_VAlign_Center
    MyRow1.AddCell ( "Header 1" )
    MyRow1.AddCell ( "Header 2" )
    MyRow1.AddCell ( "Header 3" )
    MyRow1.AddCell ( "Header 4" )
    Dim MyRow2
    Dim MyCell1
    Set MyRow2 = MyTable.AddRow()
    Set MyCell1 = MyRow2.AddCell ( "Rowheader 1", DPDF_Font_HelveticaBold, 16, "000000", "808080", 1 )
    MyCell1.Align = DPDF_Align_Center
    MyCell1.VAlign = DPDF_VAlign_Center
    MyRow2.AddCell ( "Item 1" )
    MyRow2.AddCell ( "Item 2" )
    MyRow2.AddCell ( "Item 3" )
    Dim MyRow3        
    Dim MyCell2
    Set MyRow3 = MyTable.AddRow()
    Set MyCell2 = MyRow3.AddCell( "Rowheader 2", DPDF_Font_HelveticaBold, 16, "000000", "808080", 1 )
    MyCell2.Align = DPDF_Align_Center
    MyCell2.VAlign = DPDF_VAlign_Center
    MyRow3.AddCell ( "Item 4" )
    MyRow3.AddCell ( "Item 5, this item is much longer than the rest so that you" + _
    "can see that each row will automatically expand to fit to the height of" + _
    " the largest element in that row." )
    MyRow3.AddCell ( "Item 6" )
    Dim MyRow4     
    Dim MyCell3
    Set MyRow4 = MyTable.AddRow()
    Set MyCell3 = MyRow4.AddCell( "Rowheader 3", DPDF_Font_HelveticaBold, 16, "000000", "808080", 1 )
    MyCell3.Align = DPDF_Align_Center
    MyCell3.VAlign = DPDF_VAlign_Center
    MyRow4.AddCell ( "Item 7" )
    MyRow4.AddCell ( "Item 8" )
    MyRow4.AddCell ( "Item 9" )
    MyDocument.DrawToWeb
    Set MyPage = Nothing
    Set MyDocument = Nothing
%> 

In This Section

Adding Page Elements to Cells
Explains how to add page elements to a tables cell.
Table Continuation
Explains how to span a table across multiple pages or columns.

See Also 

Table Class | Programming with Generator for COM-ActiveX