Components All New MacOS Windows Linux iOS
Examples Mac & Win Server Client Guides Statistic FMM Blog Deprecated Old

DynaPDF.Table.Create

Creates a new table object.

Component Version macOS Windows Linux Server iOS SDK
DynaPDF 3.5 ✅ Yes ✅ Yes ✅ Yes ✅ Yes ✅ Yes
MBS( "DynaPDF.Table.Create"; PDF; AllocRows; NumCols; Width; DefRowHeight )   More

Parameters

Parameter Description Example
PDF The PDF reference returned from DynaPDF.New. $pdf
AllocRows The number of rows to preallocate. 10
NumCols The number of columns. 5
Width The width of table. 500
DefRowHeight The default row height for a new row. 30

Result

Returns table identifier or error.

Description

Creates a new table object.
The parameter AllocRows specifies the number of rows which should be pre-allocated. The value should be large enough to avoid unnecessary memory reallocations. Note that this is just the size of the array that holds the rows which will be added later. Unused rows require 4 or 8 bytes memory (32 bit / 64 bit).
The default row height is used if the parameter Height of AddRow() or AddRows() is set to a negative value.
The widths of the columns is set to the table width divided by the number of columns (Width / NumCols).
The table must be deleted with DynaPDF.Table.Release when finish to avoid a memory leak.
DynaPDF table reference numbers are starting at 21000 and counting up for each new table.

Examples

Create table with 10 preallocated rows, 2 columns, 500 point width and 10 point default row height:

MBS("DynaPDF.Table.Create"; $pdf; 10; 2; 500; 10)

Create table and set some properties:

Set Variable [$table; Value:MBS("DynaPDF.Table.Create"; $pdf; 10; 2; 500; 10)]
Set Variable [$r; Value:MBS("DynaPDF.Table.SetBorderWidth"; $table; -1; -1; 1; 1; 1; 1)]
Set Variable [$r; Value:MBS("DynaPDF.Table.SetRGBColor"; $table; -1; -1; "BorderColor"; 255; 255; 255)]
Set Variable [$r; Value:MBS("DynaPDF.Table.SetRGBColor"; $table; -1; -1; "GridHorzColor"; 255; 255; 255)]
Set Variable [$r; Value:MBS("DynaPDF.Table.SetRGBColor"; $table; -1; -1; "GridVertColor"; 255; 255; 255)]
Set Variable [$r; Value:MBS("DynaPDF.Table.SetRGBColor"; $table; -1; -1; "TextColor"; 0; 0; 0)]
Set Variable [$r; Value:MBS("DynaPDF.Table.SetGridWidth"; $table; 10; 10)]
Set Variable [$r; Value:MBS("DynaPDF.Table.SetColWidth"; $table; 0; 200;1)]
Set Variable [$r; Value:MBS("DynaPDF.Table.SetColWidth"; $table; 1; 300;1)]
Set Variable [$r; Value:MBS("DynaPDF.Table.SetFont"; $table; -1; -1; "Helvetica"; 0; 1; "unicode")]
Set Variable [$r; Value:MBS("DynaPDF.Table.SetFontSize"; $table; -1; -1; 10)]

Complete example using a simple table on one page:

# Initialize DynaPDF if needed
If [ MBS("DynaPDF.IsInitialized") ≠ 1 ]
    Perform Script [ “InitDynaPDF” ]
End If

# Clear current PDF document
Set Variable [ $pdf; Value:MBS("DynaPDF.New") ]
# coordinates top down instead the default Bottom Up
Set Variable [ $r; Value:MBS("DynaPDF.SetPageCoords"; $pdf; "TopDown") ]

# Create Table
Set Variable [ $table; Value:MBS("DynaPDF.Table.Create"; $pdf; 3; 3; 500; 100) ]
Set Variable [ $r; Value:MBS("DynaPDF.Table.SetBorderWidth"; $table; -1; -1; 1; 1; 1; 1) ]
Set Variable [ $r; Value:MBS("DynaPDF.Table.SetGridWidth"; $table; 1; 1) ]

# Add Rows
Set Variable [ $text; Value:"The cell alignment can be set for text, images, and templates..." ]
Set Variable [ $rowNum; Value:MBS("DynaPDF.Table.AddRow"; $table) ]
Set Variable [ $r; Value:MBS("DynaPDF.Table.SetCellText"; $table; $rowNum; 0; "left"; "top"; $text) ]
Set Variable [ $r; Value:MBS("DynaPDF.Table.SetCellText"; $table; $rowNum; 1; "center"; "top"; $text) ]
Set Variable [ $r; Value:MBS("DynaPDF.Table.SetCellText"; $table; $rowNum; 2; "right"; "top"; $text) ]
Set Variable [ $rowNum; Value:MBS("DynaPDF.Table.AddRow"; $table) ]
Set Variable [ $r; Value:MBS("DynaPDF.Table.SetCellText"; $table; $rowNum; 0; "left"; "center"; $text) ]
Set Variable [ $r; Value:MBS("DynaPDF.Table.SetCellText"; $table; $rowNum; 1; "center"; "center"; $text) ]
Set Variable [ $r; Value:MBS("DynaPDF.Table.SetCellText"; $table; $rowNum; 2; "right"; "center"; $text) ]
Set Variable [ $rowNum; Value:MBS("DynaPDF.Table.AddRow"; $table) ]
Set Variable [ $r; Value:MBS("DynaPDF.Table.SetCellText"; $table; $rowNum; 0; "left"; "bottom"; $text) ]
Set Variable [ $r; Value:MBS("DynaPDF.Table.SetCellText"; $table; $rowNum; 1; "center"; "bottom"; $text) ]
Set Variable [ $r; Value:MBS("DynaPDF.Table.SetCellText"; $table; $rowNum; 2; "right"; "bottom"; $text) ]

# Draw Table (just one page without loop)
Set Variable [ $r; Value:MBS("DynaPDF.AppendPage"; $pdf) ]
Set Variable [ $r; Value:MBS("DynaPDF.Table.Draw"; $table; 50; 50; 742) ]
Set Variable [ $r; Value:MBS("DynaPDF.EndPage"; $pdf) ]

# Cleanup
Set Field [ Tables::OutputPDF; MBS("DynaPDF.Save"; $pdf) ]
Set Variable [ $r; Value:MBS("DynaPDF.Table.Release"; $table) ]
Set Variable [ $r; Value:MBS("DynaPDF.Release"; $pdf) ]

Create table for foot notes:

Set Variable [ $FootNotes ; Value: MyTable::FootNotes ]
If [ Length ( $FootNotes ) > 0 ]
    #
    # Create footnotes Table
    Set Variable [ $table ; Value: MBS("DynaPDF.Table.Create"; $pdf; 5; 2; 240; 20) ]
    # default font for cells
    Set Variable [ $r ; Value: MBS("DynaPDF.Table.SetFontSize"; $table; -1; -1; 12) ]
    Set Variable [ $r ; Value: MBS("DynaPDF.Table.SetFont"; $table; -1; -1; "Helvetica"; 0; 1; "unicode") ]
    # no border
    Set Variable [ $r ; Value: MBS("DynaPDF.Table.SetBorderWidth"; $table; -1; -1; 0; 0; 0; 0) ]
    # but a bit of spacing inside cells
    Set Variable [ $r ; Value: MBS("DynaPDF.Table.SetCellSpacing"; $table; -1; -1; 1; 1; 1; 1) ]
    # no grid
    Set Variable [ $r ; Value: MBS("DynaPDF.Table.SetGridWidth"; $table; 0; 0) ]
    # first column only 10pt wide
    Set Variable [ $r ; Value: MBS( "DynaPDF.Table.SetColWidth"; $Table; 0; 10; 0 ) ]
    #
    # Loop over footnote lines
    Set Variable [ $count ; Value: ValueCount ( $FootNotes) ]
    Set Variable [ $index ; Value: 1 ]
    If [ $index$count ]
        Loop
            # place a footnote in a new row
            Set Variable [ $value ; Value: GetValue($FootNotes; $index) ]
            Set Variable [ $rowNum ; Value: MBS("DynaPDF.Table.AddRow"; $table) ]
            # left the number with superscript
            Set Variable [ $r ; Value: MBS("DynaPDF.Table.SetCellText"; $table; $rowNum; 0; "left"; "top"; "\TR[4]\FS[8]" & $index & "\TR[0]\FS[12]") ]
            # right the normal text. Can wrap to multiple lines, if it is long
            Set Variable [ $r ; Value: MBS("DynaPDF.Table.SetCellText"; $table; $rowNum; 1; "left"; "top"; $value) ]
            #
            # next
            Set Variable [ $index ; Value: $index + 1 ]
            Exit Loop If [ $index > $count ]
        End Loop
    End If
    #
    # Draw Table, first get height of it
    Set Variable [ $height ; Value: MBS( "DynaPDF.Table.GetTableHeight"; $Table ) ]
    # we can position it. With height we can calculate distance from bottom to put it on the page
    Set Variable [ $r ; Value: MBS("DynaPDF.Table.Draw"; $table; 620; 20+$height; 742) ]
    # free memory
    Set Variable [ $r ; Value: MBS("DynaPDF.Table.Release"; $table) ]
End If

See also

Release notes

  • Version 13.0
    • Adjusted maximum object counts. Now DynaPDF.Table.Create can have 10000 tables at the same time in memory.
  • Version 8.4
    • Changed DynaPDF.Table.Create to automatically load font Helvetica, so you have a font defined, if you don't set one yourself.

Example Databases

Blog Entries

This function checks for a license.

Created 18th August 2014, last changed 28th May 2021


DynaPDF.Table.ClearRow - DynaPDF.Table.DeleteCol