AddTable
IPDFDocument4 :: Tables

See Also Example
Collapse All

This method adds a table into the PDF document's tables collection and returns the index of the added table.

Syntax

LONG AddTable (
LONG nColumn,
LONG nRow,
LONG defaultFont,
FLOAT defaultFontSize
)
Parameters
nColumn
Number of columns

nRow
Number of rows

defaultFont
Default font

defaultFontSize
Default font size

Return value
Index of the table

Example

Adding a table into the PDF document

Delphi
[copy to clipboard]
{ PDF object is supposed to be created }

{*** VAR section 
var
  fnt, fntBold, n, tbl, i, col, row: LongInt;
  txt: String;
***}

{*** add 2 fonts: for header and for table's body }
fnt := PDF.AddBuiltInFont(BuiltInFont.bfHelvetica, false, false);
fntBold := PDF.AddBuiltInFont(BuiltInFont.bfHelveticaBold, false, false);

{*** add a table 10x10 }
n := 10;
tbl := PDF.AddTable(n, n, fnt, 12.0f);

{*** set rows and columns sizes }
for i := 0 to n-1 do
begin
  PDF.SetTableColumnSize(tbl, i, 40);
  PDF.SetTableRowSize(tbl, i, 20);
end;

{*** set font and size for upper row and leftmost column }
PDF.SetColumnTableFont(tbl, 0, fntBold);
PDF.SetRowTableFont(tbl, 0, fntBold);
PDF.SetColumnTableFontSize(tbl, 0, 14);
PDF.SetRowTableFontSize(tbl, 0, 14);

{*** fill table with some text data }
for col := 0 to n-1 do
begin
  for row := 0 to n-1 do
  begin
    txt := IntToStr(((col+1) * (row+1)));
    PDF.SetCellTableText(tbl, col, row, txt);
    
    if (col = 0) and (row = 0) then
      PDF.SetCellTableTextAlign(tbl, col, row, TextAlign.taCenter);
    else
        PDF.SetCellTableTextAlign(tbl, col, row, TextAlign.taRight);
  end;
end;

{*** draw the table }
PDF.UseFont(fnt, 14);
PDF.ShowTextAt(130, 45, 'Here is a multiplication table:');
PDF.ShowTable(tbl, 10, 60, 1, 1);

{*** save the PDF file to disk }
PDF.SaveToFile('table.pdf', true);
C/C++
[copy to clipboard]
// PDF object is supposed to be created

//*** add 2 fonts: for header and for table's body
long fnt = PDF->AddBuiltInFont(bfHelvetica, FALSE, FALSE);
long fntBold = PDF->AddBuiltInFont(bfHelveticaBold, FALSE, FALSE);

//*** add a table 10x10
long n = 10;
long tbl = PDF->AddTable(n, n, fnt, 12.0f);

//*** set rows and columns sizes
for(long i = 0; i < n; i++)
{
  PDF->SetTableColumnSize(tbl, i, 40);
  PDF->SetTableRowSize(tbl, i, 20);
}

//*** set font and size for upper row and leftmost column
PDF->SetColumnTableFont(tbl, 0, fntBold);
PDF->SetRowTableFont(tbl, 0, fntBold);
PDF->SetColumnTableFontSize(tbl, 0, 14.0f);
PDF->SetRowTableFontSize(tbl, 0, 14.0f);

//*** fill table with some text data
for(long col = 0; col < n; col++)
{
  for(long row = 0; row < n; row++)
  {
    wchar_t buf[10];
    memset(buf, 0, sizeof(wchar_t));
    swprintf(buf, 10, L"%d", (col+1) * (row+1));
    CComBSTR txt = buf;
    PDF->SetCellTableText(tbl, col, row, txt);
    
    if(col == 0 || row == 0)
      PDF->SetCellTableTextAlign(tbl, col, row, taCenter);
    else
        PDF->SetCellTableTextAlign(tbl, col, row, taRight);
  }
}

//*** draw the table
PDF->UseFont(fnt, 14.0f);
PDF->ShowTextAt(130, 45, "Here is a multiplication table:");
PDF->ShowTable(tbl, 10, 60, 1, 1);

//*** save the PDF file to disk
PDF->SaveToFile("table.pdf", TRUE);
C#
[copy to clipboard]
// PDF object is supposed to be created

//*** add 2 fonts: for header and for table's body
long fnt = PDF.AddBuiltInFont(BuiltInFont.bfHelvetica, false, false);
long fntBold = PDF.AddBuiltInFont(BuiltInFont.bfHelveticaBold, false, false);

//*** add a table 10x10
long n = 10;
long tbl = PDF.AddTable(n, n, fnt, 12.0f);

//*** set rows and columns sizes
for(long i = 0; i < n; i++)
{
  PDF.SetTableColumnSize(tbl, i, 40);
  PDF.SetTableRowSize(tbl, i, 20);
}

//*** set font and size for upper row and leftmost column
PDF.SetColumnTableFont(tbl, 0, fntBold);
PDF.SetRowTableFont(tbl, 0, fntBold);
PDF.SetColumnTableFontSize(tbl, 0, 14.0f);
PDF.SetRowTableFontSize(tbl, 0, 14.0f);

//*** fill table with some text data
for(long col = 0; col < n; col++)
{
  for(long row = 0; row < n; row++)
  {
    string txt = ((col+1) * (row+1)).ToString();
    PDF.SetCellTableText(tbl, col, row, txt);
    
    if(col == 0 || row == 0)
      PDF.SetCellTableTextAlign(tbl, col, row, TextAlign.taCenter);
    else
        PDF.SetCellTableTextAlign(tbl, col, row, TextAlign.taRight);
  }
}

//*** draw the table
PDF.UseFont(fnt, 14.0f);
PDF.ShowTextAt(130, 45, "Here is a multiplication table:");
PDF.ShowTable(tbl, 10, 60, 1, 1);

//*** save the PDF file to disk
PDF.SaveToFile("table.pdf", true);
Visual Basic
[copy to clipboard]
' PDF object is supposed to be created

'*** constants defenition
bfHelvetica = 1
bfHelveticaBold = 5
taCenter = 1
taRight = 2

'*** add 2 fonts: for header and for table's body
fnt = PDF.AddBuiltInFont(bfHelvetica, False, False)
fntBold = PDF.AddBuiltInFont(bfHelveticaBold, False, False)

'*** add a table 10x10
n = 10
tbl = PDF.AddTable(n, n, fnt, 12)

'*** set rows and columns sizes
for i = 0 To n
  PDF.SetTableColumnSize tbl, i, 40
  PDF.SetTableRowSize tbl, i, 20
next

'*** set font and size for upper row and leftmost column
PDF.SetColumnTableFont tbl, 0, fntBold
PDF.SetRowTableFont tbl, 0, fntBold
PDF.SetColumnTableFontSize tbl, 0, 14
PDF.SetRowTableFontSize tbl, 0, 14

'*** fill table with some text data
for col = 0 To n
  for row = 0 To n
    txt = "" & ((col+1) * (rwo+1)) & " "
    PDF.SetCellTableText tbl, col, row, txt
    
    if col=0 OR row=0 Then
      PDF.SetCellTableTextAlign tbl, col, row, taCenter
    else
        PDF.SetCellTableTextAlign tbl, col, row, taRight
    end if

  next
next

'*** draw the table
PDF.UseFont fnt, 14
PDF.ShowTextAt 130, 45, "Here is a multiplication table:"
PDF.ShowTable tbl, 10, 60, 1, 1

'*** save the PDF file to disk
PDF.SaveToFile "table.pdf", true

See Also

Reference