libhpdftbl 1.5.0
Table construction library for Haru PDF library
Loading...
Searching...
No Matches
hpdftbl.c File Reference

Main module for flexible table drawing with HPDF library. More...

#include <stdlib.h>
#include <string.h>
#include <iconv.h>
#include <hpdf.h>
#include <libgen.h>
#include <sys/stat.h>
#include "hpdftbl.h"

Data Structures

struct  line_dash_style
 Definition of a dashed line style. More...
 

Typedefs

typedef struct line_dash_style line_dash_style_t
 Definition of a dashed line style.
 

Functions

int hpdftbl_set_line_dash (hpdftbl_t t, hpdftbl_line_dashstyle_t style)
 Internal helper to set the line style. More...
 
void hpdftbl_set_anchor_top_left (hpdftbl_t tbl, const _Bool anchor)
 Switch stroking anchor point. More...
 
_Bool hpdftbl_get_anchor_top_left (hpdftbl_t tbl)
 Get stroking anchor point. More...
 
void hpdftbl_set_text_encoding (char *target, char *source)
 Determine text source encoding. More...
 
int hpdftbl_encoding_text_out (HPDF_Page page, HPDF_REAL xpos, HPDF_REAL ypos, char *text)
 Strke text with current encoding. More...
 
void HPDF_RoundedCornerRectangle (HPDF_Page page, HPDF_REAL xpos, HPDF_REAL ypos, HPDF_REAL width, HPDF_REAL height, HPDF_REAL rad)
 Draw rectangle with rounded corner. More...
 
void hpdftbl_set_bottom_vmargin_factor (hpdftbl_t t, HPDF_REAL f)
 The margin from the bottom of the cell to the baseline of the text is calculated as a fraction of the font size. The margin is calculated as: More...
 
hpdftbl_t hpdftbl_create (size_t rows, size_t cols)
 Create a new table with no title. More...
 
hpdftbl_t hpdftbl_create_title (size_t rows, size_t cols, char *title)
 Create a new table with title top row. More...
 
int hpdftbl_set_min_rowheight (hpdftbl_t t, float h)
 Set the minimum row height in the table. More...
 
int hpdftbl_set_colwidth_percent (hpdftbl_t t, size_t c, float w)
 Set column width as percentage of overall table width. More...
 
int hpdftbl_set_outer_grid_style (hpdftbl_t t, HPDF_REAL width, HPDF_RGBColor color, hpdftbl_line_dashstyle_t dashstyle)
 Set outer border grid style. More...
 
int hpdftbl_set_inner_grid_style (hpdftbl_t t, HPDF_REAL width, HPDF_RGBColor color, hpdftbl_line_dashstyle_t dashstyle)
 Set inner border grid style. More...
 
int hpdftbl_set_inner_hgrid_style (hpdftbl_t t, HPDF_REAL width, HPDF_RGBColor color, hpdftbl_line_dashstyle_t dashstyle)
 Set inner horizontal border grid style. More...
 
int hpdftbl_set_inner_vgrid_style (hpdftbl_t t, HPDF_REAL width, HPDF_RGBColor color, hpdftbl_line_dashstyle_t dashstyle)
 Set inner vertical border grid style. More...
 
int hpdftbl_set_inner_tgrid_style (hpdftbl_t t, HPDF_REAL width, HPDF_RGBColor color, hpdftbl_line_dashstyle_t dashstyle)
 Set inner horizontal top border grid style. More...
 
int hpdftbl_set_zebra (hpdftbl_t t, _Bool use, int phase)
 
int hpdftbl_set_zebra_color (hpdftbl_t t, HPDF_RGBColor z1, HPDF_RGBColor z2)
 Specify first and second color for a zebra grid table. More...
 
int hpdftbl_set_header_style (hpdftbl_t t, char *font, HPDF_REAL fsize, HPDF_RGBColor color, HPDF_RGBColor background)
 Specify style for table header row. More...
 
int hpdftbl_set_background (hpdftbl_t t, HPDF_RGBColor background)
 Set table background color. More...
 
int hpdftbl_set_header_halign (hpdftbl_t t, hpdftbl_text_align_t align)
 Set table header horizontal text align. More...
 
int hpdftbl_use_header (hpdftbl_t t, _Bool use)
 Enable/disable the interpretation of the top row as a header row. More...
 
int hpdftbl_use_labels (hpdftbl_t t, _Bool use)
 Enable/Disable the use of cell labels. More...
 
int hpdftbl_use_labelgrid (hpdftbl_t t, _Bool use)
 Shorter vertical line to mark labels. More...
 
int hpdftbl_set_tag (hpdftbl_t t, void *tag)
 Set an optional tag for the table. More...
 
int hpdftbl_destroy (hpdftbl_t t)
 Destroy a table and free all memory. More...
 
_Bool chktbl (hpdftbl_t t, size_t r, size_t c)
 Internal function. Check that a row and column are within the table. More...
 
int hpdftbl_set_cell (hpdftbl_t t, size_t r, size_t c, char *label, char *content)
 Set content for specific cell. More...
 
int hpdftbl_set_cellspan (hpdftbl_t t, size_t r, size_t c, size_t rowspan, size_t colspan)
 Set cell spanning. More...
 
int hpdftbl_clear_spanning (hpdftbl_t t)
 Clear all cell spanning. More...
 
int hpdftbl_set_labels (hpdftbl_t t, char **labels)
 Set the text for the cell labels. More...
 
int hpdftbl_set_content (hpdftbl_t t, char **content)
 Set the content for the table. More...
 
int hpdftbl_set_label_style (hpdftbl_t t, char *font, HPDF_REAL fsize, HPDF_RGBColor color, HPDF_RGBColor background)
 Set the text style for labels in the entire table. More...
 
int hpdftbl_set_content_style (hpdftbl_t t, char *font, HPDF_REAL fsize, HPDF_RGBColor color, HPDF_RGBColor background)
 Set text style for text content. More...
 
int hpdftbl_set_row_content_style (hpdftbl_t t, size_t r, char *font, HPDF_REAL fsize, HPDF_RGBColor color, HPDF_RGBColor background)
 Set the text style for an entire row of cells. More...
 
int hpdftbl_set_col_content_style (hpdftbl_t t, size_t c, char *font, HPDF_REAL fsize, HPDF_RGBColor color, HPDF_RGBColor background)
 Set the text style for an entire column of cells. More...
 
int hpdftbl_set_cell_content_style (hpdftbl_t t, size_t r, size_t c, char *font, HPDF_REAL fsize, HPDF_RGBColor color, HPDF_RGBColor background)
 Set the text style for content of specified cell. More...
 
int hpdftbl_set_title_style (hpdftbl_t t, char *font, HPDF_REAL fsize, HPDF_RGBColor color, HPDF_RGBColor background)
 Set the table title text style. More...
 
int hpdftbl_set_title (hpdftbl_t t, char *title)
 Set table title. More...
 
int hpdftbl_set_title_halign (hpdftbl_t t, hpdftbl_text_align_t align)
 Set horizontal alignment for table title. More...
 
int hpdftbl_stroke_from_data (HPDF_Doc pdf_doc, HPDF_Page pdf_page, hpdftbl_spec_t *tbl_spec, hpdftbl_theme_t *theme)
 Construct the table from a array specification. More...
 
int hpdftbl_get_last_auto_height (HPDF_REAL *height)
 Get the height calculated for the last constructed table. More...
 
int hpdftbl_setpos (hpdftbl_t t, const HPDF_REAL xpos, const HPDF_REAL ypos, const HPDF_REAL width, HPDF_REAL height)
 Set size and position for table. More...
 
int hpdftbl_stroke_pos (HPDF_Doc pdf, const HPDF_Page page, hpdftbl_t t)
 Stroke the table using the already specified size and position within the table. More...
 
int hpdftbl_stroke (HPDF_Doc pdf, const HPDF_Page page, hpdftbl_t t, const HPDF_REAL xpos, const HPDF_REAL ypos, const HPDF_REAL width, HPDF_REAL height)
 Stroke the table. More...
 
int hpdftbl_stroke_pdfdoc (HPDF_Doc pdf_doc, char *file)
 Stroke PDF document to file with check that the directory in path exists. More...
 

Variables

hpdftbl_error_handler_t hpdftbl_err_handler = NULL
 This stores a pointer to the function acting as the error handler callback.
 

Detailed Description

Main module for flexible table drawing with HPDF library.

Author
Johan Persson (johan.nosp@m.162@.nosp@m.gmail.nosp@m..com)

Copyright (C) 2022 Johan Persson

See also
LICENSE

Released under the MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Function Documentation

◆ chktbl()

_Bool chktbl ( hpdftbl_t  t,
size_t  r,
size_t  c 
)

Internal function. Check that a row and column are within the table.

Internal function. Check that a row and column are within the table

Parameters
tTable handle
rRow
cColumn
Returns
TRUE if within bounds, FALSE otherwise

Referenced by hpdftbl_set_cell(), hpdftbl_set_cell_canvas_cb(), hpdftbl_set_cell_content_cb(), hpdftbl_set_cell_content_style(), hpdftbl_set_cell_content_style_cb(), hpdftbl_set_cell_label_cb(), and hpdftbl_set_cellspan().

◆ HPDF_RoundedCornerRectangle()

void HPDF_RoundedCornerRectangle ( HPDF_Page  page,
HPDF_REAL  xpos,
HPDF_REAL  ypos,
HPDF_REAL  width,
HPDF_REAL  height,
HPDF_REAL  rad 
)

Draw rectangle with rounded corner.

Draw a rectangle with rounded corner with the current line width, color. The rectangle will not be stroked.

Parameters
pagePage handle
xposLower left x-position of rectangle
yposLower left y-position of rectangle
widthWidth of rectangle
heightHeight of rectangle
radRadius of corners

Referenced by hpdftbl_widget_slide_button().

◆ hpdftbl_clear_spanning()

int hpdftbl_clear_spanning ( hpdftbl_t  t)

Clear all cell spanning.

Reset all spanning cells to no spanning

Parameters
tTable handle
Returns
0 on success, -1 on failure
See also
hpdftbl_set_cellspan()

◆ hpdftbl_create()

hpdftbl_t hpdftbl_create ( size_t  rows,
size_t  cols 
)

Create a new table with no title.

Create a new table structure. This is the basic handler needed for most other API functions.

Parameters
rowsNumber of rows
colsNumber of columns
Returns
A handle to a table, NULL in case of OOM
Examples
tut_ex01.c, tut_ex02.c, tut_ex02_1.c, tut_ex03.c, tut_ex04.c, tut_ex09.c, tut_ex10.c, tut_ex11.c, tut_ex12.c, tut_ex15.c, tut_ex15_1.c, tut_ex20.c, tut_ex40.c, and tut_ex41.c.

◆ hpdftbl_create_title()

hpdftbl_t hpdftbl_create_title ( size_t  rows,
size_t  cols,
char *  title 
)

Create a new table with title top row.

Create a new table structure. This is the basic handler needed for most other API functions.

Parameters
rowsNumber of rows
colsNumber of columns
titleTitle of table
Returns
A handle to a table, NULL in case of OOM
Examples
example01.c, tut_ex00.c, tut_ex05.c, tut_ex06.c, tut_ex07.c, tut_ex08.c, tut_ex14.c, and tut_ex30.c.

Referenced by hpdftbl_create(), and hpdftbl_stroke_from_data().

◆ hpdftbl_destroy()

int hpdftbl_destroy ( hpdftbl_t  t)

Destroy a table and free all memory.

Destroy a table previous created with table_create(), It is the calling routines responsibility not to acceess t again.

Parameters
tHandle to table
Returns
0 on success, -1 on failure

Referenced by hpdftbl_loads(), and hpdftbl_stroke_from_data().

◆ hpdftbl_encoding_text_out()

int hpdftbl_encoding_text_out ( HPDF_Page  page,
HPDF_REAL  xpos,
HPDF_REAL  ypos,
char *  text 
)

Strke text with current encoding.

Utility function to stroke text with character encoding. It is the calling routines responsibility to enclose text in a HPDF_Page_BeginText() / HPDF_Page_EndText()

Parameters
pagePage handle
xposX coordinate
yposY coordinate
textText to print
Returns
-1 on error, 0 on success

◆ hpdftbl_get_anchor_top_left()

_Bool hpdftbl_get_anchor_top_left ( hpdftbl_t  tbl)

Get stroking anchor point.

Get anchor point for table positioning. By default the top left is used.

Parameters
tblTable handle
See also
hpdftbl_set_anchor_top_left
Returns
TRUE if anchor is top left, FALSE otherwise

◆ hpdftbl_get_last_auto_height()

int hpdftbl_get_last_auto_height ( HPDF_REAL *  height)

Get the height calculated for the last constructed table.

Get the last automatically calculated height when stroking a table. (The height will be automatically calculated if it was specified as 0)

Parameters
heightReturned height
Returns
-1 on error, 0 if successful

◆ hpdftbl_set_anchor_top_left()

void hpdftbl_set_anchor_top_left ( hpdftbl_t  tbl,
const _Bool  anchor 
)

Switch stroking anchor point.

Set anchor point for table positioning. By default the top left is used as anchor. Calling this function with FALSE can sets the anchor to bottom left instead.

Parameters
tblTable handle
anchorSet to TRUE to use top left as anchor, FALSE for bottom left

◆ hpdftbl_set_background()

int hpdftbl_set_background ( hpdftbl_t  t,
HPDF_RGBColor  background 
)

Set table background color.

Parameters
tTable handle
backgroundBackground color
Returns
0 on success, -1 on failure

◆ hpdftbl_set_bottom_vmargin_factor()

void hpdftbl_set_bottom_vmargin_factor ( hpdftbl_t  t,
HPDF_REAL  f 
)

The margin from the bottom of the cell to the baseline of the text is calculated as a fraction of the font size. The margin is calculated as:

bottom_margin = fontsize * f

The default margin is specified by the define DEFAULT_AUTO_VBOTTOM_MARGIN_FACTOR

Parameters
tTable handle
fBottom margin factor

Referenced by hpdftbl_apply_theme().

◆ hpdftbl_set_cell()

int hpdftbl_set_cell ( hpdftbl_t  t,
size_t  r,
size_t  c,
char *  label,
char *  content 
)

Set content for specific cell.

Set label and content for a specific cell. If the specified cell is part of another cells spanning an error occurs (returns -1),

Parameters
tTable handle
rRow
cColumn
labelLabel
contentText content
Returns
-1 on error, 0 if successful
Examples
tut_ex01.c, and tut_ex03.c.

Referenced by hpdftbl_stroke_from_data().

◆ hpdftbl_set_cell_content_style()

int hpdftbl_set_cell_content_style ( hpdftbl_t  t,
size_t  r,
size_t  c,
char *  font,
HPDF_REAL  fsize,
HPDF_RGBColor  color,
HPDF_RGBColor  background 
)

Set the text style for content of specified cell.

SSet the font style for content of specified cell. This will override the global cell content setting.

Parameters
tTable handle
rCell row
cCell column
fontFont name
fsizeFont size
colorColor
backgroundBackground color
Returns
0 on success, -1 on failure
See also
hpdftbl_set_content_style()
hpdftbl_set_cell_content_style_cb()
Examples
example01.c.

Referenced by hpdftbl_set_col_content_style(), and hpdftbl_set_row_content_style().

◆ hpdftbl_set_cellspan()

int hpdftbl_set_cellspan ( hpdftbl_t  t,
size_t  r,
size_t  c,
size_t  rowspan,
size_t  colspan 
)

Set cell spanning.

Set row and column spanning for a cell, an expanded cell is referenced via the position of it's top-left cell

Parameters
tTable handle
rRow
cColumn
rowspanRow span
colspanColumn span
Returns
-1 on error, 0 if successful
See also
hpdftbl_clear_spanning()
Examples
example01.c, tut_ex07.c, tut_ex08.c, tut_ex40.c, and tut_ex41.c.

Referenced by hpdftbl_stroke_from_data().

◆ hpdftbl_set_col_content_style()

int hpdftbl_set_col_content_style ( hpdftbl_t  t,
size_t  c,
char *  font,
HPDF_REAL  fsize,
HPDF_RGBColor  color,
HPDF_RGBColor  background 
)

Set the text style for an entire column of cells.

Set font options for the specified column of cells. This will override the global cell content setting.

Parameters
tTable handle
cColumn to affect
fontFont name
fsizeFont size
colorColor
backgroundBackground color
Returns
0 on success, -1 on failure
See also
hpdftbl_set_content_style()
hpdftbl_set_cell_content_style_cb()

◆ hpdftbl_set_colwidth_percent()

int hpdftbl_set_colwidth_percent ( hpdftbl_t  t,
size_t  c,
float  w 
)

Set column width as percentage of overall table width.

Specify column width as percentage of total column width. Note that this will only take effect if the table has an overall width specified when stroked. Too avoid errors one column should be left unspecified to let the library use whatever space is left for that column.

Parameters
tTable handle
cColumn to set width of first column has index 0
wWidth as percentage in range [0.0, 100.0]
Returns
0 on success, -1 on failure
Examples
example01.c, tut_ex08.c, tut_ex09.c, tut_ex10.c, tut_ex11.c, and tut_ex12.c.

◆ hpdftbl_set_content()

int hpdftbl_set_content ( hpdftbl_t  t,
char **  content 
)

Set the content for the table.

Set content for all cells. It is the calling functions responsibility that the content array is big enough to cover the entire table. The string array corresponds to a flattened 2-d array and the label for cell (r,c) is calculated as (r * num_cols + c) where num_cols is the number of columns in the table.

It is allowed to specify NULL as placeholder for empty labels. The actual text in the table will be allocated with strdup() so it is safe to free the memory for the labels after the call to this function. Please note that even if the table contains spanning cells the content data must include empty data for covered cells. For a N x M table the data must have (N*M) entries.

Another way to specify the content is to use the callback mechanism. By setting up a content callback function that returns the content for a cell.

Parameters
tTable handle
contentA one dimensional string array of content string
Returns
-1 on error, 0 if successful
See also
hpdftbl_set_content_callback()
hpdftbl_set_cell_content_callback()
Examples
example01.c, tut_ex00.c, tut_ex02.c, tut_ex02_1.c, tut_ex04.c, tut_ex05.c, tut_ex10.c, tut_ex11.c, tut_ex12.c, tut_ex15.c, tut_ex15_1.c, tut_ex20.c, tut_ex40.c, and tut_ex41.c.

◆ hpdftbl_set_content_style()

int hpdftbl_set_content_style ( hpdftbl_t  t,
char *  font,
HPDF_REAL  fsize,
HPDF_RGBColor  color,
HPDF_RGBColor  background 
)

Set text style for text content.

Set style options for cell content (font, color, background). This will be applied for all cells in the table. If a style callback have been specified for either the table or a cell that style take precedence.

Parameters
tTable handle
fontFont name
fsizeFont size
colorColor
backgroundBackground color
Returns
-1 on error, 0 if successful
See also
hpdftbl_set_cell_content_style()
hpdftbl_set_cell_content_style_cb()
Examples
example01.c.

Referenced by hpdftbl_apply_theme().

◆ hpdftbl_set_header_halign()

int hpdftbl_set_header_halign ( hpdftbl_t  t,
hpdftbl_text_align_t  align 
)

Set table header horizontal text align.

Parameters
tTable handle
alignAlignment
Returns
0 on success, -1 on failure

Referenced by hpdftbl_apply_theme().

◆ hpdftbl_set_header_style()

int hpdftbl_set_header_style ( hpdftbl_t  t,
char *  font,
HPDF_REAL  fsize,
HPDF_RGBColor  color,
HPDF_RGBColor  background 
)

Specify style for table header row.

Set the font properties and background for the header row which is the top row if enabled. The header row will be automatically enabled after calling this function. The header can be enabled/disabled separately with hpdftbl_use_header()

Parameters
tTable handle
fontFont name
fsizeFont size
colorFont color
backgroundCell background color
Returns
0 on success, -1 on failure
See also
hpdftbl_use_header()

Referenced by hpdftbl_apply_theme().

◆ hpdftbl_set_inner_grid_style()

int hpdftbl_set_inner_grid_style ( hpdftbl_t  t,
HPDF_REAL  width,
HPDF_RGBColor  color,
hpdftbl_line_dashstyle_t  dashstyle 
)

Set inner border grid style.

This is a shortform to set both the vertical and horizontal gridline style with one call.

Parameters
tTable handle
widthLine width (in pt)
colorLine color
dashstyleLine dash style
Returns
0 on success, -1 on failure
See also
hpdftbl_set_inner_hgrid_style(), hpdftbl_set_inner_vgrid_style(), hpdftbl_set_outer_grid_style()

◆ hpdftbl_set_inner_hgrid_style()

int hpdftbl_set_inner_hgrid_style ( hpdftbl_t  t,
HPDF_REAL  width,
HPDF_RGBColor  color,
hpdftbl_line_dashstyle_t  dashstyle 
)

Set inner horizontal border grid style.

Parameters
tTable handle
widthLine width (in pt)
colorLine color
dashstyleLine dash style
Returns
0 on success, -1 on failure
See also
hpdftbl_set_inner_grid_style(), hpdftbl_set_inner_vgrid_style()
Examples
tut_ex15_1.c, and tut_ex20.c.

Referenced by hpdftbl_apply_theme(), and hpdftbl_set_inner_grid_style().

◆ hpdftbl_set_inner_tgrid_style()

int hpdftbl_set_inner_tgrid_style ( hpdftbl_t  t,
HPDF_REAL  width,
HPDF_RGBColor  color,
hpdftbl_line_dashstyle_t  dashstyle 
)

Set inner horizontal top border grid style.

This would be the gridline just below the header row.

Parameters
tTable handle
widthLine width (in pt)
colorLine color
dashstyleLine dash style
Returns
0 on success, -1 on failure
See also
hpdftbl_set_inner_hgrid_style()
Examples
tut_ex15_1.c, and tut_ex20.c.

Referenced by hpdftbl_apply_theme().

◆ hpdftbl_set_inner_vgrid_style()

int hpdftbl_set_inner_vgrid_style ( hpdftbl_t  t,
HPDF_REAL  width,
HPDF_RGBColor  color,
hpdftbl_line_dashstyle_t  dashstyle 
)

Set inner vertical border grid style.

Parameters
tTable handle
widthLine width (in pt)
colorLine color
dashstyleLine dash style
Returns
0 on success, -1 on failure
See also
hpdftbl_set_inner_grid_style(), hpdftbl_set_inner_hgrid_style()
Examples
tut_ex20.c.

Referenced by hpdftbl_apply_theme(), and hpdftbl_set_inner_grid_style().

◆ hpdftbl_set_label_style()

int hpdftbl_set_label_style ( hpdftbl_t  t,
char *  font,
HPDF_REAL  fsize,
HPDF_RGBColor  color,
HPDF_RGBColor  background 
)

Set the text style for labels in the entire table.

Set font, color and background options for cell labels. If a style callback have been specified for either the table or a cell that style take precedence.

Parameters
tTable handle
fontFont name
fsizeFont size
colorColor
backgroundBackground color
Returns
-1 on error, 0 if successful

Referenced by hpdftbl_apply_theme().

◆ hpdftbl_set_labels()

int hpdftbl_set_labels ( hpdftbl_t  t,
char **  labels 
)

Set the text for the cell labels.

Set labels for all the cell. It is the calling functions responsibility that the labels array is big enough to cover the entire table. The string array corresponds to a flattened 2-d array and the label for cell (r,c) is calculated as (r * num_cols + c) where num_cols is the number of columns in the table.

It is allowed to specify NULL as placeholder for empty labels. The actual text in the table will be allocated with strdup() so it is safe to free the memory for the labels after the call to this function. Please note that even if the table contains spanning cells the content data must include empty data for covered cells. For a N x M table the data must have (N*M) entries.

Parameters
tTable handle
labelsA one dimensional string array of labels
Returns
-1 on error, 0 if successful
See also
hpdftbl_set_cell_label_cb()
hpdftbl_set_label_cb()
Examples
example01.c, tut_ex00.c, tut_ex04.c, tut_ex05.c, tut_ex20.c, tut_ex40.c, and tut_ex41.c.

◆ hpdftbl_set_line_dash()

int hpdftbl_set_line_dash ( hpdftbl_t  t,
hpdftbl_line_dashstyle_t  style 
)

Internal helper to set the line style.

The drawing of a dashed line uses the underlying HPDF function HPDF_Page_SetDash()

Parameters
tTable handle
style
Returns
-1 on error, 0 on success
See also
line_dash_style

Referenced by hpdftbl_stroke().

◆ hpdftbl_set_min_rowheight()

int hpdftbl_set_min_rowheight ( hpdftbl_t  t,
float  h 
)

Set the minimum row height in the table.

The row height is normally calculated based on the font size and if labels are displayed or not. However, it is not possible for the table to know the height of specific widgets (for example) without a two-pass table drawing algorithm.

To handle thos odd cases when the calculated height is not sufficient a manual minimum height can be specified.

Parameters
tTable handler
hThe minimum height (in points). If specified as 0 the min height will have no effect.
Returns
0 on success, -1 on failure
Examples
example01.c.

◆ hpdftbl_set_outer_grid_style()

int hpdftbl_set_outer_grid_style ( hpdftbl_t  t,
HPDF_REAL  width,
HPDF_RGBColor  color,
hpdftbl_line_dashstyle_t  dashstyle 
)

Set outer border grid style.

Parameters
tTable handle
widthLine width (in pt)
colorLine color
dashstyleLine dash style
Returns
0 on success, -1 on failure
See also
hpdftbl_set_inner_grid_style()
Examples
tut_ex20.c.

Referenced by hpdftbl_apply_theme().

◆ hpdftbl_set_row_content_style()

int hpdftbl_set_row_content_style ( hpdftbl_t  t,
size_t  r,
char *  font,
HPDF_REAL  fsize,
HPDF_RGBColor  color,
HPDF_RGBColor  background 
)

Set the text style for an entire row of cells.

Set font options for the specified row of cells. This will override the global cell content.

Parameters
tTable handle
rRow to affect
fontFont name
fsizeFont size
colorColor
backgroundBackground color
Returns
0 on success, -1 on failure
See also
hpdftbl_set_content_style()
hpdftbl_set_cell_content_style_cb()

◆ hpdftbl_set_tag()

int hpdftbl_set_tag ( hpdftbl_t  t,
void *  tag 
)

Set an optional tag for the table.

Set an optional tag in the table. The tag can be a pointer to anything. The tag is passed as the first argument in the various callbacks and can be used to supply table specific information or identify a specific table in the case the same callback is used for multiple tables.

Parameters
tThe table handle
tagThe tag (pointer to any object)
Returns
0 on success, -1 on failure

◆ hpdftbl_set_text_encoding()

void hpdftbl_set_text_encoding ( char *  target,
char *  source 
)

Determine text source encoding.

The default HPDF encoding is a standard PDF encoding. The problem with that is that now almost 100% of all code is written in UTF-8 encoding and trying to print text strings with accented characters will simply not work. For example the default encoding assumes that strings are given in UTF-8 and sets the target to ISO8859-4 which includes northern europe accented characters. The conversion is internally handled by the standard iconv() routines.

Parameters
targetThe target encoding. See HPDF documentation for supported encodings.
sourceThe source encodings, i.e. what encodings are sth strings in the source specified in.

◆ hpdftbl_set_title()

int hpdftbl_set_title ( hpdftbl_t  t,
char *  title 
)

Set table title.

Set table title. A title will occupy a separate row above the table that is not included in the row count. A table is enabled when the table text is <> NULL and disabled when the title text is == NULL.

Parameters
tTable handle
titleTitle string
Returns
0 on success, -1 on failure
See also
hpdftbl_set_title_style()
hpdftbl_set_title_halign()

◆ hpdftbl_set_title_halign()

int hpdftbl_set_title_halign ( hpdftbl_t  t,
hpdftbl_text_align_t  align 
)

Set horizontal alignment for table title.

Parameters
tTable handle
alignAlignment
Returns
0 on success, -1 on failure
See also
hpdftbl_set_title()
hpdftbl_set_title_style()
Examples
example01.c.

Referenced by hpdftbl_apply_theme().

◆ hpdftbl_set_title_style()

int hpdftbl_set_title_style ( hpdftbl_t  t,
char *  font,
HPDF_REAL  fsize,
HPDF_RGBColor  color,
HPDF_RGBColor  background 
)

Set the table title text style.

Set font options for title

Parameters
tTable handle
fontFont name
fsizeFont size
colorColor
backgroundBackground color
Returns
0 on success, -1 on failure
See also
hpdftbl_set_title()
hpdftbl_set_title_halign()
Examples
example01.c.

Referenced by hpdftbl_apply_theme().

◆ hpdftbl_set_zebra()

int hpdftbl_set_zebra ( hpdftbl_t  t,
_Bool  use,
int  phase 
)
Parameters
tTable handle
useTRUE=Use Zebra, FALSE=Don't use zebra
phase0=Start with color 1, 1=Start with color 1
Returns
0 on successes -1 on failure
Examples
tut_ex15.c, tut_ex15_1.c, and tut_ex41.c.

Referenced by hpdftbl_apply_theme().

◆ hpdftbl_set_zebra_color()

int hpdftbl_set_zebra_color ( hpdftbl_t  t,
HPDF_RGBColor  z1,
HPDF_RGBColor  z2 
)

Specify first and second color for a zebra grid table.

By default the colors start with z1 color. To have the top row (below any potential header row) instead start with z2 specify phase=1 in the hpdftbl_set_zebra() function.

Parameters
tTable handle
z1Color 1
z2Color 2
Returns
0 on successes -1 on failure

Referenced by hpdftbl_apply_theme().

◆ hpdftbl_setpos()

int hpdftbl_setpos ( hpdftbl_t  t,
const HPDF_REAL  xpos,
const HPDF_REAL  ypos,
const HPDF_REAL  width,
HPDF_REAL  height 
)

Set size and position for table.

The position is by default specified as the upper left corner of the table. Use the hpdftbl_set_origin_top_left() to use the bottom left of the table as reference point.

Ths standard stroke function hpdftbl_stroke() also take the size and position as argument for ease of use but the hpdftbl_stroke_pos() do assume that the table has it's size set.

Parameters
tTable handle
xposx position for table
yposy position for table
widthwidth of table
heightheight of table. If the height is specified as 0 it will be automatically calculated. The calculated height can be retrieved after the table has been stroked by a call to hpdftbl_get_last_auto_height()
Returns
-1 on error, 0 if successful
See also
hpdftbl_get_last_auto_height(), hpdftbl_set_origin_top_left()

◆ hpdftbl_stroke()

int hpdftbl_stroke ( HPDF_Doc  pdf,
const HPDF_Page  page,
hpdftbl_t  t,
const HPDF_REAL  xpos,
const HPDF_REAL  ypos,
const HPDF_REAL  width,
HPDF_REAL  height 
)

Stroke the table.

Stroke the table at the specified position and size. The position is by default specified as the upper left corner of the table. Use the hpdftbl_set_origin_top_left(FALSE) to use the bottom left of the table as reference point.

Parameters
pdfThe HPDF document handle
pageThe HPDF page handle
tTable handle
xposx position for table
yposy position for table
widthwidth of table
heightheight of table. If the height is specified as 0 it will be automatically calculated. The calculated height can be retrieved after the table has been stroked by a call to hpdftbl_get_last_auto_height()
Returns
-1 on error, 0 if successful
See also
hpdftbl_get_last_auto_height()
hpdftbl_stroke_from_data()
Examples
example01.c, tut_ex00.c, tut_ex01.c, tut_ex02.c, tut_ex02_1.c, tut_ex03.c, tut_ex04.c, tut_ex05.c, tut_ex06.c, tut_ex07.c, tut_ex08.c, tut_ex09.c, tut_ex10.c, tut_ex11.c, tut_ex12.c, tut_ex14.c, tut_ex15.c, tut_ex15_1.c, tut_ex20.c, tut_ex30.c, tut_ex40.c, and tut_ex41.c.

Referenced by hpdftbl_stroke_from_data(), and hpdftbl_stroke_pos().

◆ hpdftbl_stroke_from_data()

int hpdftbl_stroke_from_data ( HPDF_Doc  pdf_doc,
HPDF_Page  pdf_page,
hpdftbl_spec_t tbl_spec,
hpdftbl_theme_t theme 
)

Construct the table from a array specification.

Create and stroke a table specified by a data structure. This makes it easier to separate the view of the data from the model which provides the data. The intended use case is that the data structure specifies the core layout of the table together with the labels and callback functions to handle the content in each cell. Using this method to create a table also makes it much more maintainable.

Parameters
pdf_docThe PDF overall document
pdf_pageThe pageto stroke to
tbl_specThe table specification
themeTable theme to be applied
Returns
0 on success, -1 on failure
See also
hpdftbl_stroke()
Examples
example01.c, tut_ex13_1.c, and tut_ex13_2.c.

◆ hpdftbl_stroke_pdfdoc()

int hpdftbl_stroke_pdfdoc ( HPDF_Doc  pdf_doc,
char *  file 
)

Stroke PDF document to file with check that the directory in path exists.

Note: It is a checked error if the full path is longer than 1014 characters

Parameters
pdf_docHaru PDF document handle
fileFull pathname of file to write to
Returns
0 on success, -1 on failure

Referenced by stroke_to_file().

◆ hpdftbl_stroke_pos()

int hpdftbl_stroke_pos ( HPDF_Doc  pdf,
const HPDF_Page  page,
hpdftbl_t  t 
)

Stroke the table using the already specified size and position within the table.

Stroke the table at the specified position and size. The position is by default specified as the upper left corner of the table. Use the hpdftbl_set_origin_top_left(FALSE) to use the bottom left of the table as reference point.

This is a convenient method to use when stroking a serialized table as the table already holds the size and position. Stroking a table read back ccan be done with just two lines of code

hpdftbl_t tbl = calloc(1, sizeof(struct hpdftbl));
if( 0 == hpdftbl_load(tbl, filename) ) {
hpdftbl_stroke_pos(pdf_doc, pdf_page, tbl);
}
int hpdftbl_stroke_pos(HPDF_Doc pdf, const HPDF_Page page, hpdftbl_t t)
Stroke the table using the already specified size and position within the table.
Definition: hpdftbl.c:1654
int hpdftbl_load(hpdftbl_t tbl, char *filename)
Import a table structure from a serialized table on file.
Definition: hpdftbl_load.c:330
Core table handle.
Definition: hpdftbl.h:470
Parameters
pdfThe HPDF document handle
pageThe HPDF page handle
tTable handle
Returns
-1 on error, 0 if successful
See also
hpdftbl_get_last_auto_height()
hpdftbl_setpos(), hpdftbl_stroke()
Examples
tut_ex40.c, and tut_ex41.c.

◆ hpdftbl_use_header()

int hpdftbl_use_header ( hpdftbl_t  t,
_Bool  use 
)

Enable/disable the interpretation of the top row as a header row.

A header row will have a different style and labels will be disabled on this row. In addition the text will be centered vertically and horizontal in the cell.

Parameters
tTable handle
useTRUE to enable, FALSE to disable
Returns
0 on success, -1 on failure
See also
hpdftbl_set_header_style()
Examples
example01.c, tut_ex02_1.c, tut_ex11.c, tut_ex12.c, and tut_ex20.c.

Referenced by hpdftbl_stroke_from_data().

◆ hpdftbl_use_labelgrid()

int hpdftbl_use_labelgrid ( hpdftbl_t  t,
_Bool  use 
)

Shorter vertical line to mark labels.

Set the usage of special grid style where the vertical grid only covers the label text and a gap to the next line. Horizontal lines are drawn as usual. The label grid style gives the table a "lighter" look.

Parameters
tTable handle
useTRUE to use label grid, FALSE o disable it
Returns
0 on success, -1 on failure
See also
hpdftbl_use_labels()
Examples
example01.c, tut_ex03.c, tut_ex04.c, tut_ex05.c, tut_ex06.c, tut_ex07.c, tut_ex08.c, tut_ex14.c, tut_ex20.c, tut_ex30.c, and tut_ex40.c.

Referenced by hpdftbl_stroke_from_data().

◆ hpdftbl_use_labels()

int hpdftbl_use_labels ( hpdftbl_t  t,
_Bool  use 
)

Enable/Disable the use of cell labels.

By default a newly created table will not use cell labels. Enabling labels will also by default enable the special label grid style. To adjust the grid style separately us the hpdftbl_use_labelgrid() method.

Parameters
tTable handle
useSet to TRUE for cell labels
Returns
0 on success, -1 on failure
See also
hpdftbl_use_labelgrid()
Examples
example01.c, tut_ex00.c, tut_ex03.c, tut_ex04.c, tut_ex05.c, tut_ex06.c, tut_ex07.c, tut_ex08.c, tut_ex14.c, tut_ex20.c, tut_ex30.c, tut_ex40.c, and tut_ex41.c.

Referenced by hpdftbl_stroke_from_data().