.. _group__a3d__pdf__tablefromapi__module:

#####################
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 :c:func:`~A3DPDFTableCellDescCreate`\ to create cells. Use the function :c:func:`~A3DPDFTableRowDescCreate`\ to create a row, the cells included being specified with ``m_ppCells``\ member. Finally use the function :c:func:`~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 :c:func:`~A3DPDFPageInsertTable`\ .

As an example, a simple table 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


::

   A3DPDFTableStyleDatastylerow0=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;
   A3DPDFTableCellDescDatasTableCellDescData=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;
   A3DPDFTableRowDescDatasTableRowDescData=A3D_MAKE_DATA(A3DPDFTableRowDescData);
   sTableRowDescData.m_ppCells=(A3DPDFTableCellDesc**)malloc(aCells.size()*sizeof(A3DPDFTableCellDesc**));
   for(size_ti=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:


::

   A3DPDFTableDescDatasTableDescData=A3D_MAKE_DATA(A3DPDFTableDescData);
   sTableDescData.m_ppRows=(A3DPDFTableRowDesc**)malloc(aRows.size()*A3DUns32(sizeof(A3DPDFTableRowDesc*)));
   sTableDescData.m_iNumberOfRows=static_cast<A3DUns32>(aRows.size());
   for(size_ti=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*\ .

**Parameters**


   **pCellDescData**\ : The cell description.

   **ppCellDesc**\ : The Table cell descriptor created.


**Returns**


   A3D_SUCCESS in case of success or an error code


.. rst-class:: kind-group kind-record

.. rubric:: Structures
   :class: kind-group-title


.. rst-class:: api-xref-list


* :c:struct:`~A3DPDFTableStyleData`
* :c:struct:`~A3DPDFTableCellDescData`
* :c:struct:`~A3DPDFTableRowDescData`
* :c:struct:`~A3DPDFTableDescData`

.. rst-class:: kind-group kind-function

.. rubric:: Functions
   :class: kind-group-title


.. rst-class:: api-xref-list


* :c:func:`~A3DPDFTableCellDescCreate`
* :c:func:`~A3DPDFTableRowDescCreate`
* :c:func:`~A3DPDFTableCreateFromDesc`

.. toctree::
   :maxdepth: 1
   :hidden:

   ../structures/A3DPDFTableStyleData
   ../structures/A3DPDFTableCellDescData
   ../structures/A3DPDFTableRowDescData
   ../structures/A3DPDFTableDescData
   ../functions/A3DPDFTableCellDescCreate
   ../functions/A3DPDFTableRowDescCreate
   ../functions/A3DPDFTableCreateFromDesc


