Table From API Module
Module to create tables on a PDF page, based on API definition.
This module describes the functions and structures that allow you to define tables on a PDF page, based on an API definition.
With HOOPS Publish API, a table is defined on three levels: the cell, the row, and the table. Obviously a table contains a set of rows, and a row contains a set of cells. Then the style applied can be defined at cell level, at row level, or at table level.
For this, use the function A3DPDFTableCellDescCreate() to create cells. Use the function A3DPDFTableRowDescCreate() to create a row, the cells included being specified with m_ppCells member. Finally use the function A3DPDFTableCreateFromDesc() to create the table, the rows being included with m_ppRows member. Then, the table is positioned on the PDF page using the function A3DPDFPageInsertTable().
As an example, the following simple table
Name | City | Age
- Bob | Seattle | 35
- Sandy | New York | 32
is defined with HOOPS Publish API by creating three rows of three cells each. Two different styles are specified: one for the first (header) row and one for second and third row.
The styles are defined with code such as
A3DPDFTableStyleData stylerow0 = A3D_MAKE_DATA(A3DPDFTableStyleData);
outStyle.m_iFontSize = fontSize;
outStyle.m_pcFontName = "Helvetica";
outStyle.m_eHorizAlignment = kA3DPDFTableAlignHCentered
outStyle.m_iRowHeight = 20;
outStyle.m_iColumnWidth = 70;
The cells are defined with code such as
std::vector<A3DPDFTableCellDesc*> aCells;
A3DPDFTableCellDesc* pTableCellDesc;
A3DPDFTableCellDescData sTableCellDescData = A3D_MAKE_DATA(A3DPDFTableCellDescData);
sTableCellDescData.m_pcCellString = "Bob";
A3DPDFTableCellDescCreate(&sTableCellDescData, &pTableCellDesc);
aCells.push_back(pTableCellDesc);
The rows are defined with code such as
std::vector<A3DPDFTableRowDesc*> aRows;
A3DPDFTableRowDesc* pTableRowDesc;
A3DPDFTableRowDescData sTableRowDescData = A3D_MAKE_DATA(A3DPDFTableRowDescData);
sTableRowDescData.m_ppCells = (A3DPDFTableCellDesc**)malloc(aCells.size() * sizeof(A3DPDFTableCellDesc**));
for (size_t i = 0; i < aCells.size(); i++)
sTableRowDescData.m_ppCells[i] = aCells[i];
sTableRowDescData.m_pStyle = &stylerow0;
sTableRowDescData.m_iNumberOfCells = static_cast<A3DUns32>(aCells.size());
A3DPDFTableRowDescCreate(&sTableRowDescData, &pTableRowDesc);
aRows.push_back(pTableRowDesc);
then the table is defined with:
A3DPDFTableDescData sTableDescData = A3D_MAKE_DATA(A3DPDFTableDescData);
sTableDescData.m_ppRows = (A3DPDFTableRowDesc**)malloc(aRows.size() * A3DUns32(sizeof(A3DPDFTableRowDesc*)));
sTableDescData.m_iNumberOfRows = static_cast<A3DUns32>(aRows.size());
for (size_t i = 0; i < aRows.size(); i++)
sTableDescData.m_ppRows[i] = aRows[i];
A3DPDFTableCreateFromDesc(pDoc, &sTableDescData, &pTable);
A code example is provided in the package to demonstrate the creation of a Table with these functions. Please see samples/publishing/DemoFunctionalities.
Functions