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

Header file for libhpdftbl. More...

#include "config.h"

Go to the source code of this file.

Data Structures

struct  text_style
 Specification of a text style. More...
 
struct  grid_style
 Specification for table grid lines. More...
 
struct  hpdftbl_cell
 Specification of individual cells in the table. More...
 
struct  hpdftbl
 Core table handle. More...
 
struct  hpdftbl_cell_spec
 Used in data driven table creation. More...
 
struct  hpdftbl_spec
 Used in data driven table creation. More...
 
struct  hpdftbl_theme
 Define a set of styles into a table theme. More...
 

Macros

#define hpdftbl_H
 
#define TRUE   1
 Boolean truth value.
 
#define FALSE   0
 Boolean false value.
 
#define max(a, b)   (((a)>(b)) ? (a):(b))
 Return the maximum value of numeric variables.
 
#define min(a, b)   (((a)<(b)) ? (a):(b))
 Return the minimum value of numeric variables.
 
#define THEME_JSON_VERSION   1
 
#define TABLE_JSON_VERSION   1
 
#define HPDF_FF_TIMES   "Times-Roman"
 
#define HPDF_FF_TIMES_ITALIC   "Times-Italic"
 
#define HPDF_FF_TIMES_BOLD   "Times-Bold"
 
#define HPDF_FF_TIMES_BOLDITALIC   "Times-BoldItalic"
 
#define HPDF_FF_HELVETICA   "Helvetica"
 
#define HPDF_FF_HELVETICA_ITALIC   "Helvetica-Oblique"
 
#define HPDF_FF_HELVETICA_BOLD   "Helvetica-Bold"
 
#define HPDF_FF_HELVETICA_BOLDITALIC   "Helvetica-BoldOblique"
 
#define HPDF_FF_COURIER   "Courier"
 
#define HPDF_FF_COURIER_BOLD   "Courier-Bold"
 
#define HPDF_FF_COURIER_IALIC   "Courier-Oblique"
 
#define HPDF_FF_COURIER_BOLDITALIC   "Courier-BoldOblique"
 
#define HPDF_RGB_CONVERT(r, g, b)    (HPDF_RGBColor) { r / 255.0f, g / 255.0f, b / 255.0f }
 Utility macro to create a HPDF color constant from integer RGB values.
 
#define HPDF_COLOR_DARK_RED   (HPDF_RGBColor) { 0.6f, 0.0f, 0.0f }
 
#define HPDF_COLOR_RED   (HPDF_RGBColor) { 1.0f, 0.0f, 0.0f }
 
#define HPDF_COLOR_LIGHT_GREEN   (HPDF_RGBColor) { 0.9f, 1.0f, 0.9f }
 
#define HPDF_COLOR_GREEN   (HPDF_RGBColor) { 0.4f, 0.9f, 0.4f }
 
#define HPDF_COLOR_DARK_GREEN   (HPDF_RGBColor) { 0.05f, 0.37f, 0.02f }
 
#define HPDF_COLOR_DARK_GRAY   (HPDF_RGBColor) { 0.2f, 0.2f, 0.2f }
 
#define HPDF_COLOR_LIGHT_GRAY   (HPDF_RGBColor) { 0.9f, 0.9f, 0.9f }
 
#define HPDF_COLOR_XLIGHT_GRAY   (HPDF_RGBColor) { 0.95f, 0.95f, 0.95f }
 
#define HPDF_COLOR_GRAY   (HPDF_RGBColor) { 0.5f, 0.5f, 0.5f }
 
#define HPDF_COLOR_SILVER   (HPDF_RGBColor) { 0.75f, 0.75f, 0.75f }
 
#define HPDF_COLOR_LIGHT_BLUE   (HPDF_RGBColor) { 1.0f, 1.0f, 0.9f }
 
#define HPDF_COLOR_BLUE   (HPDF_RGBColor) { 0.0f, 0.0f, 1.0f }
 
#define HPDF_COLOR_DARK_BLUE   (HPDF_RGBColor) { 0.0f, 0.0f, 0.6f }
 
#define HPDF_COLOR_WHITE   (HPDF_RGBColor) { 1.0f, 1.0f, 1.0f }
 
#define HPDF_COLOR_BLACK   (HPDF_RGBColor) { 0.0f, 0.0f, 0.0f }
 
#define HPDF_COLOR_ORANGE   HPDF_RGB_CONVERT(0xF5, 0xD0, 0x98);
 
#define HPDF_COLOR_ALMOST_BLACK   HPDF_RGB_CONVERT(0x14, 0x14, 0x14);
 
#define DEFAULT_AUTO_VBOTTOM_MARGIN_FACTOR   0.5
 The margin from the bottom of the cell to the baseline of the text is calculated as a fraction of the font size. More...
 
#define HPDFTBL_DEFAULT_TARGET_ENCODING   "ISO8859-4"
 Default PDF text encodings.
 
#define HPDFTBL_DEFAULT_SOURCE_ENCODING   "UTF-8"
 Default input source text encodings.
 
#define A4PAGE_HEIGHT_CM   29.7
 Standard A4 paper height in cm.
 
#define A4PAGE_WIDTH_CM   21.0
 Standard A4 paper width in cm.
 
#define A3PAGE_HEIGHT_CM   42.0
 Standard A3 paper height in cm.
 
#define A3PAGE_WIDTH_CM   29.7
 Standard A3 paper width in cm.
 
#define LETTERRPAGE_HEIGHT_CM   27.9
 US Letter Height in cm.
 
#define LETTERRPAGE_WIDTH_CM   21.6
 US Letter width in cm.
 
#define LEGALPAGE_HEIGHT_CM   35.6
 US Legal Height in cm.
 
#define LEGALPAGE_WIDTH_CM   21.6
 US Legal Width in cm.
 
#define HPDFTBL_END_CELLSPECS   {0, 0, 0, 0, 0, 0, 0, 0, 0}
 Sentinel to mark the end of Cell Specifications for data driven table definition.
 
#define HPDF_COLOR_FROMRGB(r, g, b)   (HPDF_RGBColor){(r)/255.0,(g)/255.0,(b)/255.0}
 Utility macro to calculate a color constant from RGB integer values [0,255].
 
#define HPDFTBL_MIN_CALCULATED_PERCENT_CELL_WIDTH   2.0
 The smallest size in percent of table width allowed by automatic calculation before giving an error.
 
#define hpdftbl_cm2dpi(c)   (((HPDF_REAL)(c))/2.54*72)
 Convert cm to dots using the default resolution (72 DPI) More...
 
#define _HPDFTBL_SET_ERR(t, err, r, c)   do {hpdftbl_err_code=err;hpdftbl_err_row=r;hpdftbl_err_col=c;hpdftbl_err_lineno=__LINE__;hpdftbl_err_file=__FILE__; if(hpdftbl_err_handler){hpdftbl_err_handler(t,r,c,err);}} while(0)
 Call the error handler with specified error code and table row, col where error occured. More...
 
#define _HPDFTBL_SET_ERR_EXTRA(info)   do {strncpy(hpdftbl_err_extrainfo,info,1023);hpdftbl_err_extrainfo[1023]=0;} while(0)
 Set optional extra info at error state. (Currently only used by the late binding setting callback functions) More...
 
#define _HPDFTBL_CHK_TABLE(t)   do {if(NULL == t) {hpdftbl_err_code=-3;hpdftbl_err_row=-1;hpdftbl_err_col=-1;return -1;}} while(0)
 NPE check before using a table handler.
 
#define _HPDFTBL_IDX(r, c)   (r*t->cols+c)
 Shortcut to calculate the index in an array from a row,column (table) position.
 

Typedefs

typedef enum hpdftbl_text_align hpdftbl_text_align_t
 Enumeration for horizontal text alignment. More...
 
typedef struct text_style hpdf_text_style_t
 Specification of a text style. More...
 
typedef struct hpdftblhpdftbl_t
 Table handle is a pointer to the hpdftbl structure. More...
 
typedef char *(* hpdftbl_content_callback_t) (void *, size_t, size_t)
 Type specification for the table content callback. More...
 
typedef void(* hpdftbl_canvas_callback_t) (HPDF_Doc, HPDF_Page, void *, size_t, size_t, HPDF_REAL, HPDF_REAL, HPDF_REAL, HPDF_REAL)
 Type specification for the table canvas callback. More...
 
typedef _Bool(* hpdftbl_content_style_callback_t) (void *, size_t, size_t, char *content, hpdf_text_style_t *)
 Type specification for the content style. More...
 
typedef void(* hpdftbl_callback_t) (hpdftbl_t)
 Callback type for optional post processing when constructing table from a data array. More...
 
typedef enum hpdftbl_dashstyle hpdftbl_line_dashstyle_t
 Possible line dash styles for grid lines. More...
 
typedef struct grid_style hpdftbl_grid_style_t
 Specification for table grid lines. More...
 
typedef struct hpdftbl_cell hpdftbl_cell_t
 Type definition for the cell structure. More...
 
typedef struct hpdftbl_cell_spec hpdftbl_cell_spec_t
 Used in data driven table creation. More...
 
typedef struct hpdftbl_spec hpdftbl_spec_t
 Used in data driven table creation. More...
 
typedef struct hpdftbl_theme hpdftbl_theme_t
 Define a set of styles into a table theme. More...
 
typedef void(* hpdftbl_error_handler_t) (hpdftbl_t, int, int, int)
 TYpe for error handler function. More...
 

Enumerations

enum  hpdftbl_text_align { LEFT = 0 , CENTER = 1 , RIGHT = 2 }
 Enumeration for horizontal text alignment. More...
 
enum  hpdftbl_dashstyle {
  LINE_SOLID , LINE_DOT1 , LINE_DOT2 , LINE_DOT3 ,
  LINE_DOT4 , LINE_DASH1 , LINE_DASH2 , LINE_DASH3 ,
  LINE_DASH4 , LINE_DASH5 , LINE_DASHDOT1 , LINE_DASHDOT2
}
 Possible line dash styles for grid lines. More...
 

Functions

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_stroke (HPDF_Doc pdf, HPDF_Page page, hpdftbl_t t, HPDF_REAL xpos, HPDF_REAL ypos, HPDF_REAL width, HPDF_REAL height)
 Stroke the 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_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_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_destroy (hpdftbl_t t)
 Destroy a table and free all memory. More...
 
int hpdftbl_get_last_auto_height (HPDF_REAL *height)
 Get the height calculated for the last constructed table. More...
 
void hpdftbl_set_anchor_top_left (hpdftbl_t tbl, _Bool anchor)
 Switch stroking anchor point. More...
 
_Bool hpdftbl_get_anchor_top_left (hpdftbl_t tbl)
 Get stroking anchor point. More...
 
hpdftbl_error_handler_t hpdftbl_set_errhandler (hpdftbl_error_handler_t)
 Specify errhandler for the table routines. More...
 
const char * hpdftbl_get_errstr (int err)
 Translate a table error code to a human readable string. More...
 
const char * hpdftbl_hpdf_get_errstr (HPDF_STATUS err_code)
 Function to return a human readable error string for an error code from Core HPDF library. More...
 
int hpdftbl_get_last_errcode (const char **errstr, int *row, int *col)
 Return last error code. More...
 
void hpdftbl_get_last_err_file (int *lineno, char **file, char **extrainfo)
 Get the filename and line number where the last error occurred. More...
 
void hpdftbl_default_table_error_handler (hpdftbl_t t, int r, int c, int err)
 A basic default table error handler. More...
 
int hpdftbl_apply_theme (hpdftbl_t t, hpdftbl_theme_t *theme)
 Apply a specified theme to a table. More...
 
hpdftbl_theme_thpdftbl_get_default_theme (void)
 Return the default theme. More...
 
int hpdftbl_get_theme (hpdftbl_t tbl, hpdftbl_theme_t *theme)
 Extract theme from settings of a specific table. More...
 
int hpdftbl_destroy_theme (hpdftbl_theme_t *theme)
 Destroy existing theme structure and free memory. 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...
 
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_clear_spanning (hpdftbl_t t)
 Clear all cell spanning. 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_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_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_background (hpdftbl_t t, HPDF_RGBColor background)
 Set table background color. 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_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_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_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_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_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_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_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_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_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_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_cell (hpdftbl_t t, size_t r, size_t c, char *label, char *content)
 Set content for specific cell. More...
 
int hpdftbl_set_tag (hpdftbl_t t, void *tag)
 Set an optional tag for the table. 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_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_content_cb (hpdftbl_t t, hpdftbl_content_callback_t cb)
 Set table content callback. More...
 
int hpdftbl_set_cell_content_cb (hpdftbl_t t, size_t r, size_t c, hpdftbl_content_callback_t cb)
 Set cell content callback. More...
 
int hpdftbl_set_label_cb (hpdftbl_t t, hpdftbl_content_callback_t cb)
 Set table label callback. More...
 
int hpdftbl_set_cell_label_cb (hpdftbl_t t, size_t r, size_t c, hpdftbl_content_callback_t cb)
 Set cell label callback. More...
 
int hpdftbl_set_canvas_cb (hpdftbl_t t, hpdftbl_canvas_callback_t cb)
 Set cell canvas callback. More...
 
int hpdftbl_set_cell_canvas_cb (hpdftbl_t t, size_t r, size_t c, hpdftbl_canvas_callback_t cb)
 Set cell canvas callback. More...
 
int hpdftbl_set_content_style_cb (hpdftbl_t t, hpdftbl_content_style_callback_t cb)
 Set callback to specify cell content style. More...
 
int hpdftbl_set_cell_content_style_cb (hpdftbl_t t, size_t r, size_t c, hpdftbl_content_style_callback_t cb)
 Set cell specific callback to specify cell content style. More...
 
int hpdftbl_set_post_cb (hpdftbl_t t, hpdftbl_callback_t cb)
 Set table post processing callback. More...
 
void hpdftbl_set_dlhandle (void *)
 Set the handle for scope of dynamic function search. More...
 
int hpdftbl_set_content_dyncb (hpdftbl_t, const char *)
 Specify dynamic (late) loading callback content function. More...
 
int hpdftbl_set_canvas_dyncb (hpdftbl_t, const char *)
 Specify dynamic (late) loading callback content function. More...
 
int hpdftbl_set_cell_content_dyncb (hpdftbl_t, size_t, size_t, const char *)
 Specify dynamic (late) loading callback cell content function. More...
 
int hpdftbl_set_label_dyncb (hpdftbl_t, const char *)
 Specify dynamic (late) loading callback for table label function. More...
 
int hpdftbl_set_cell_label_dyncb (hpdftbl_t, size_t, size_t, const char *)
 Specify dynamic (late) loading callback for cell label function. More...
 
int hpdftbl_set_content_style_dyncb (hpdftbl_t, const char *)
 Specify dynamic (late) loading callback for table style function. More...
 
int hpdftbl_set_cell_content_style_dyncb (hpdftbl_t, size_t, size_t, const char *)
 Specify dynamic (late) loading callback for cell style function. More...
 
int hpdftbl_set_cell_canvas_dyncb (hpdftbl_t, size_t, size_t, const char *)
 Specify dynamic (late) loading callback cell canvas function. More...
 
int hpdftbl_set_post_dyncb (hpdftbl_t t, const char *cb_name)
 Set table post processing callback. 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_stroke_grid (HPDF_Doc pdf, HPDF_Page page)
 
void hpdftbl_table_widget_letter_buttons (HPDF_Doc doc, HPDF_Page page, HPDF_REAL xpos, HPDF_REAL ypos, HPDF_REAL width, HPDF_REAL height, HPDF_RGBColor on_color, HPDF_RGBColor off_color, HPDF_RGBColor on_background, HPDF_RGBColor off_background, HPDF_REAL fsize, const char *letters, _Bool *state)
 Display an array of letters as a table where each letter is its own "mini" cell
and sorrounded by a frame. Each boxed letter can be in an "on" state or "off" state which is illustrated with different font and fac colors. More...
 
void hpdftbl_widget_slide_button (HPDF_Doc doc, HPDF_Page page, HPDF_REAL xpos, HPDF_REAL ypos, HPDF_REAL width, HPDF_REAL height, _Bool state)
 Table widget that draws a sliding on/off switch. Meant to be used in a canvas callback to display a boolean value. More...
 
void hpdftbl_widget_hbar (HPDF_Doc doc, HPDF_Page page, HPDF_REAL xpos, HPDF_REAL ypos, HPDF_REAL width, HPDF_REAL height, HPDF_RGBColor color, float val, _Bool hide_val)
 Draw a horizontal partially filled bar to indicate an analog (percentage) value. More...
 
void hpdftbl_widget_segment_hbar (HPDF_Doc doc, HPDF_Page page, HPDF_REAL xpos, HPDF_REAL ypos, HPDF_REAL width, HPDF_REAL height, size_t num_segments, HPDF_RGBColor on_color, double val_percent, _Bool hide_val)
 Draw a horizontal segment meter that can be used to visualize a discrete value. More...
 
void hpdftbl_widget_strength_meter (HPDF_Doc doc, HPDF_Page page, HPDF_REAL xpos, HPDF_REAL ypos, HPDF_REAL width, HPDF_REAL height, size_t num_segments, HPDF_RGBColor on_color, size_t num_on_segments)
 Draw a phone strength meter. 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...
 
int hpdftbl_dump (hpdftbl_t tbl, char *filename)
 Serialize a table structure as a JSON file. More...
 
int hpdftbl_dumps (hpdftbl_t tbl, char *buff, size_t buffsize)
 Serialize a table structure to a string buffer. More...
 
int hpdftbl_load (hpdftbl_t tbl, char *filename)
 Import a table structure from a serialized table on file. More...
 
int hpdftbl_loads (hpdftbl_t tbl, char *buff)
 Import a table structure from a serialized json buffert. More...
 
int hpdftbl_theme_dump (hpdftbl_theme_t *theme, char *filename)
 Serialize the specified theme structure to a named file. More...
 
int hpdftbl_theme_dumps (hpdftbl_theme_t *theme, char *buff, size_t buffsize)
 Serialize theme structure to a string buffer. More...
 
int hpdftbl_theme_loads (hpdftbl_theme_t *tbl, char *buff)
 Load theme from a serialized string. This is the invert function of hpdftbl_theme_dumps(). More...
 
int hpdftbl_theme_load (hpdftbl_theme_t *tbl, char *filename)
 Read a theme from a previous serialized theme from a named file. More...
 
size_t xstrlcat (char *dst, const char *src, size_t siz)
 Safe string concatenation. More...
 
size_t xstrlcpy (char *__restrict dst, const char *__restrict src, size_t dsize)
 Safe string copy. More...
 
int hpdftbl_read_file (char *buff, size_t buffsize, char *filename)
 Read content of file into a specified buffer. More...
 
_Bool chktbl (hpdftbl_t, size_t, size_t)
 Internal function. Check that a row and column are within the table. More...
 

Variables

int hpdftbl_err_code
 Stores the last generated error code. More...
 
int hpdftbl_err_row
 The row where the last error was generated.
More...
 
int hpdftbl_err_col
 The column where the last error was generated.
More...
 
int hpdftbl_err_lineno
 Hold the line number of the last error occurred. More...
 
char * hpdftbl_err_file
 Hold the file name where the last error occurred. More...
 
char hpdftbl_err_extrainfo []
 Extra info that may be specified at the point of error. More...
 
hpdftbl_error_handler_t hpdftbl_err_handler
 This stores a pointer to the function acting as the error handler callback.
 

Detailed Description

Header file for libhpdftbl.

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.

Macro Definition Documentation

◆ _HPDFTBL_SET_ERR

#define _HPDFTBL_SET_ERR (   t,
  err,
  r,
 
)    do {hpdftbl_err_code=err;hpdftbl_err_row=r;hpdftbl_err_col=c;hpdftbl_err_lineno=__LINE__;hpdftbl_err_file=__FILE__; if(hpdftbl_err_handler){hpdftbl_err_handler(t,r,c,err);}} while(0)

Call the error handler with specified error code and table row, col where error occured.

Parameters
tTable handler
errError code
rRow where error occured
cColumn where error occured

◆ _HPDFTBL_SET_ERR_EXTRA

#define _HPDFTBL_SET_ERR_EXTRA (   info)    do {strncpy(hpdftbl_err_extrainfo,info,1023);hpdftbl_err_extrainfo[1023]=0;} while(0)

Set optional extra info at error state. (Currently only used by the late binding setting callback functions)

Parameters
infoExtra info that can be set by a function at a state of error
See also
hpdftbl_set_label_dyncb(),hpdftbl_set_content_dyncb()

◆ DEFAULT_AUTO_VBOTTOM_MARGIN_FACTOR

#define DEFAULT_AUTO_VBOTTOM_MARGIN_FACTOR   0.5

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 * AUTO_VBOTTOM_MARGIN_FACTOR
See also
hpdftbl_set_bottom_vmargin_bottom()

◆ HPDF_FF_COURIER

#define HPDF_FF_COURIER   "Courier"

Font family

◆ HPDF_FF_COURIER_BOLD

#define HPDF_FF_COURIER_BOLD   "Courier-Bold"

Font family

Examples
example01.c.

◆ HPDF_FF_COURIER_BOLDITALIC

#define HPDF_FF_COURIER_BOLDITALIC   "Courier-BoldOblique"

Font family

◆ HPDF_FF_COURIER_IALIC

#define HPDF_FF_COURIER_IALIC   "Courier-Oblique"

Font family

◆ HPDF_FF_HELVETICA

#define HPDF_FF_HELVETICA   "Helvetica"

Font family

◆ HPDF_FF_HELVETICA_BOLD

#define HPDF_FF_HELVETICA_BOLD   "Helvetica-Bold"

Font family

Examples
example01.c, and tut_ex09.c.

◆ HPDF_FF_HELVETICA_BOLDITALIC

#define HPDF_FF_HELVETICA_BOLDITALIC   "Helvetica-BoldOblique"

Font family

◆ HPDF_FF_HELVETICA_ITALIC

#define HPDF_FF_HELVETICA_ITALIC   "Helvetica-Oblique"

Font family

◆ HPDF_FF_TIMES

#define HPDF_FF_TIMES   "Times-Roman"

Font family

Examples
tut_ex09.c.

◆ HPDF_FF_TIMES_BOLD

#define HPDF_FF_TIMES_BOLD   "Times-Bold"

Font family

◆ HPDF_FF_TIMES_BOLDITALIC

#define HPDF_FF_TIMES_BOLDITALIC   "Times-BoldItalic"

Font family

◆ HPDF_FF_TIMES_ITALIC

#define HPDF_FF_TIMES_ITALIC   "Times-Italic"

Font family

◆ hpdftbl_cm2dpi

#define hpdftbl_cm2dpi (   c)    (((HPDF_REAL)(c))/2.54*72)

Convert cm to dots using the default resolution (72 DPI)

Parameters
cMeasure in cm
Returns
HPDF_REAL Converted value in dots
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_ex13_1.c, tut_ex13_2.c, tut_ex14.c, tut_ex15.c, tut_ex15_1.c, tut_ex20.c, tut_ex30.c, tut_ex40.c, and tut_ex41.c.

◆ TABLE_JSON_VERSION

#define TABLE_JSON_VERSION   1

Data structure version for serialization of tables

◆ THEME_JSON_VERSION

#define THEME_JSON_VERSION   1

Data structure version for serialization of themes

Typedef Documentation

◆ hpdf_text_style_t

typedef struct text_style hpdf_text_style_t

Specification of a text style.

This structure collects the basic properties for a text string (font, color, background, horizontal alignment)

◆ hpdftbl_callback_t

typedef void(* hpdftbl_callback_t) (hpdftbl_t)

Callback type for optional post processing when constructing table from a data array.

Type for generic table callback used when constructing a table from data. This can be used to perform any potential table manipulation. The callback happens after the table has been fully constructed and just before it is stroked.

See also
hpdftbl_stroke_from_data()

◆ hpdftbl_canvas_callback_t

typedef void(* hpdftbl_canvas_callback_t) (HPDF_Doc, HPDF_Page, void *, size_t, size_t, HPDF_REAL, HPDF_REAL, HPDF_REAL, HPDF_REAL)

Type specification for the table canvas callback.

A canvas callback, if specified, is called for each cell before the content is stroked. The callback will be given the bounding box for the cell (x,y,width,height) in addition to the row and column the cell has.

See also
hpdftbl_set_canvas_cb()

◆ hpdftbl_cell_spec_t

Used in data driven table creation.

A table can be specified by creating a array of this structure together with the hpdftbl_spec_t structure. The array should have one entry for each cell in the table.

See also
hpdftbl_stroke_from_data()

◆ hpdftbl_cell_t

typedef struct hpdftbl_cell hpdftbl_cell_t

Type definition for the cell structure.

This is an internal structure that represents an individual cell in the table.

◆ hpdftbl_content_callback_t

typedef char *(* hpdftbl_content_callback_t) (void *, size_t, size_t)

Type specification for the table content callback.

The content callback is used to specify the textual content in a cell and is an alternative method to specifying the content to be displayed.

See also
hpdftbl_set_content_cb()

◆ hpdftbl_content_style_callback_t

typedef _Bool(* hpdftbl_content_style_callback_t) (void *, size_t, size_t, char *content, hpdf_text_style_t *)

Type specification for the content style.

The content callback is used to specify the textual style in a cell and is an alternative method to specifying the style of content to be displayed.

See also
hpdftbl_set_content_style_cb()

◆ hpdftbl_error_handler_t

typedef void(* hpdftbl_error_handler_t) (hpdftbl_t, int, int, int)

TYpe for error handler function.

The error handler (of set) will be called if the table library descovers an error condition

See also
hpdftbl_set_errhandler()

◆ hpdftbl_grid_style_t

Specification for table grid lines.

Contains line properties used when stroking a grid line

◆ hpdftbl_line_dashstyle_t

Possible line dash styles for grid lines.

In the illustration of the patterns "x"=solid and "_"=space.

For each pattern we show two full cycles which should give a good visual indication of the different patterns.

◆ hpdftbl_spec_t

typedef struct hpdftbl_spec hpdftbl_spec_t

Used in data driven table creation.

This is used together with an array of cell specification hpdftbl_cell_spec_t to specify the layout of a table.

◆ hpdftbl_t

typedef struct hpdftbl* hpdftbl_t

Table handle is a pointer to the hpdftbl structure.

This is the basic table handle used in almost all API calls. A table reference is returned when a table is created.

See also
hpdftbl_create()

◆ hpdftbl_text_align_t

◆ hpdftbl_theme_t

Define a set of styles into a table theme.

Contains all information about the styles of various elements in the table that together make up the table style

Enumeration Type Documentation

◆ hpdftbl_dashstyle

Possible line dash styles for grid lines.

In the illustration of the patterns "x"=solid and "_"=space.

For each pattern we show two full cycles which should give a good visual indication of the different patterns.

Enumerator
LINE_SOLID 

Solid line

LINE_DOT1 

Dotted line variant 1 "x_x_x_"

LINE_DOT2 

Dotted line variant 2 "x__x__x__"

LINE_DOT3 

Dotted line variant 3 "x___x___x___"

LINE_DOT4 

Dotted line variant 3 "x_____x_____x_____"

LINE_DASH1 

Dashed line variant 1 "xx__xx__xx__"

LINE_DASH2 

Dashed line variant 2 "xx___xx___xx___"

LINE_DASH3 

Dashed line variant 3 "xxxx__xxxx__xxxx__"

LINE_DASH4 

Dashed line variant 4 "xxxx____xxxx____xxxx____"

LINE_DASH5 

Dashed line variant 4 "xxxxxx___xxxxxx___xxxxxx___"

LINE_DASHDOT1 

Dashed-dot line variant 1 "xxxxx__xx__xxxxx__xx__xxxxx__xx__"

LINE_DASHDOT2 

Dashed-dot line variant 1 "xxxxxxx___xxx___xxxxxxx___xxx___xxxxxxx___xxx___"

◆ hpdftbl_text_align

Enumeration for horizontal text alignment.

See also
hpdftbl_set_header_halign()
hpdftbl_set_title_halign()
hpdftbl_text_align
Enumerator
LEFT 

Left test alignment

CENTER 

Center test alignment

RIGHT 

Right test alignment

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_apply_theme()

int hpdftbl_apply_theme ( hpdftbl_t  t,
hpdftbl_theme_t theme 
)

Apply a specified theme to a table.

Note however that a limitation (by design) of themes is that settings in individual cells are not recorded in a theme since a theme can be applied to any table despite the structure. This mean only settings that are generic to a table is stored in a theme. Not individal cells.

The default table theme can be retrieved with hpdftbl_get_default_theme()

Parameters
tTable handle
themeTheme reference
Returns
0 on success, -1 on failure
See also
hpdftbl_get_default_theme()
Examples
tut_ex41.c.

Referenced by hpdftbl_create_title(), and hpdftbl_stroke_from_data().

◆ 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

◆ 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

Referenced by hpdftbl_create(), and hpdftbl_stroke_from_data().

◆ hpdftbl_default_table_error_handler()

void hpdftbl_default_table_error_handler ( hpdftbl_t  t,
int  r,
int  c,
int  err 
)

A basic default table error handler.

This error handler is used as a callback that outputs the error to stderr in human readable format and quits the process.

Parameters
tTable where the error happened (can be NULL)
rCell row
cCell column
errThe error code
See also
hpdftbl_set_errhandler()
Examples
tut_ex10.c, tut_ex11.c, and tut_ex12.c.

◆ 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_destroy_theme()

int hpdftbl_destroy_theme ( hpdftbl_theme_t theme)

Destroy existing theme structure and free memory.

Free all memory allocated by a theme

Parameters
themeThe theme to free
Returns
-1 for error , 0 for success
Examples
example01.c.

Referenced by hpdftbl_create_title(), and hpdftbl_theme_loads().

◆ hpdftbl_dump()

int hpdftbl_dump ( hpdftbl_t  tbl,
char *  filename 
)

Serialize a table structure as a JSON file.

The table is serialized as JSON file and have whitespaces and newlines to make it more human readable. The serialization is a complete representation of a table.

Parameters
tblTable handle
filenameFilename to write to. Any path specified must exists
Returns
-1 on failure, 0 on success
Examples
tut_ex40.c, and tut_ex41.c.

◆ hpdftbl_dumps()

int hpdftbl_dumps ( hpdftbl_t  tbl,
char *  buff,
size_t  buffsize 
)

Serialize a table structure to a string buffer.

The table is serialized as JSON and have whitespaces and newlines to make it more human readable. Note is is the callers responsibility to make sure the buffer is large enough to hold the serialized table.

Parameters
tblTable handle of table to dump
buffBuffer to dump structure to
buffsizeSize of buffer
Returns
-1 on failure, 0 on success
See also
hpdftbl_load(),hpdftbl_dump(), hpdftbl_stroke_pos(),

Referenced by hpdftbl_dump().

◆ 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_default_theme()

hpdftbl_theme_t * hpdftbl_get_default_theme ( void  )

Return the default theme.

Create and return a theme corresponding to the default table theme. It is the calling functions responsibility to call hpdftbl_destroy_theme() to free the allocated memory. The default theme is a good starting point to just make minor modifications without having to define all elements.

Returns
A new theme initialized to the default settings. It is the calling routines responsibility to free memory used in the returned theme with hpdftbl_destroy_theme()
See also
hpdftbl_apply_theme(), hpdftbl_destroy_theme()
Examples
example01.c, and tut_ex41.c.

Referenced by hpdftbl_create_title().

◆ hpdftbl_get_errstr()

const char * hpdftbl_get_errstr ( int  err)

Translate a table error code to a human readable string.

The function returns a pointer to a static string that cannot be modified. It will translate both internal table error messages as well as generic HPDF library error codes.

Parameters
errThe error code to be translated
Returns
Static pointer to string for valid error code, NULL otherwise
See also
hpdftbl_hpdf_get_errstr()

Referenced by hpdftbl_default_table_error_handler(), and hpdftbl_get_last_errcode().

◆ 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_get_last_err_file()

void hpdftbl_get_last_err_file ( int *  lineno,
char **  file,
char **  extrainfo 
)

Get the filename and line number where the last error occurred.

Parameters
linenoSet to the line number where the error occurred
fileSet to the file where the error occurred
extrainfoExtra info string that may be set at the point of error

◆ hpdftbl_get_last_errcode()

int hpdftbl_get_last_errcode ( const char **  errstr,
int *  row,
int *  col 
)

Return last error code.

Return last error code. if errstr is not NULL a human readable string describing the error will be copied to the string. The error code will be reset after call.

Parameters
errstrA string buffer where the error string is written to
rowThe row where the error was found
colThe col where the error was found
Returns
The last error code
Examples
example01.c.

◆ hpdftbl_get_theme()

int hpdftbl_get_theme ( hpdftbl_t  tbl,
hpdftbl_theme_t theme 
)

Extract theme from settings of a specific table.

This is useful if a table has been specified with some specific look & feel and another table should be given the same l&f.

Note however that a limitation (by design) of themes is that settings in individual cells are not recorded in a theme since a theme can be applied to any table despite the structure. This mean only settings that are generic to a table is stored in a theme. Not individal cells.

Parameters
tblTable handle for table to have its settings extracted
themeTheme to be read out to.
Returns
0 on success, -1 on failure
Examples
tut_ex41.c.

◆ hpdftbl_hpdf_get_errstr()

const char * hpdftbl_hpdf_get_errstr ( const HPDF_STATUS  err_code)

Function to return a human readable error string for an error code from Core HPDF library.

The various error codes given by the HPDF library can be translated back to a string by the usage of this function. The function will return a pointer to a static string that can not be manipulated.

Parameters
err_codeThe error code
Returns
A pointer to an error string, NULL if the error code is invalid
See also
hpdftbl_get_errstr()

Referenced by hpdftbl_get_errstr().

◆ hpdftbl_load()

int hpdftbl_load ( hpdftbl_t  tbl,
char *  filename 
)

Import a table structure from a serialized table on file.

The json file make it possible to adjust the table directly. However it is easy to get it wrong. Some things to keep in mind while doing manual changes.

  • A real number must always be written as a decimal number with at least one decimal point (even if it .0)
  • Remember that the width of the table is specified manually and not automatically recalculated based on the text width.

After reading a serialized table it can asily be be stroked with only two lines of code as the following code-snippet shows

hpdftbl_t tbl = calloc(1, sizeof (struct hpdftbl));
if(0 == hpdftbl_load(tbl, "mytablefile.json") ) {
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
Note
The hpdftbl_t is a pointer type to struct hpdftbl and hence must must be either dynamically allocated as the example here shows or an instance of the struct must be created whose address is given to this functions.
Parameters
tblTable to read into
filenameFile to read from
Returns
0 on success, -1 on file parse error, -2 on nay other error
Examples
tut_ex40.c, and tut_ex41.c.

◆ hpdftbl_loads()

int hpdftbl_loads ( hpdftbl_t  tbl,
char *  buff 
)

Import a table structure from a serialized json buffert.

This is the preferred way on how to store a table structure in for example a database.

Example:

char *mybuffer = ....
hpdftbl_t tbl = calloc(1, sizeof (struct hpdftbl));
if(0 == hpdftbl_load(tbl, mybuffer) ) {
hpdftbl_stroke_pos(pdf_doc, pdf_page, tbl);
}
Parameters
tblReference to table handle to be populated
buffBuffer with serialized data to read back
Returns
0 on success, -1 on file parse error, -2 on nay other error
See also
hpdftbl_dump(), hpdftbl_load(), hpdftbl_stroke_pos()

Referenced by hpdftbl_load().

◆ hpdftbl_read_file()

int hpdftbl_read_file ( char *  buff,
size_t  buffsize,
char *  filename 
)

Read content of file into a specified buffer.

Parameters
buffDestination buffer
buffsizeSize of buffer
filenameName of file to read from
Returns
-1 on failure, 0 on success

Referenced by hpdftbl_load(), and hpdftbl_theme_load().

◆ 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_canvas_cb()

int hpdftbl_set_canvas_cb ( hpdftbl_t  t,
hpdftbl_canvas_callback_t  cb 
)

Set cell canvas callback.

Set cell canvas callback. This callback gets called for each cell in the table. The purpose is to allow the client to add dynamic content to the specified cell. The callback is made before the cell border and content is drawn making it possible to for example add a background color to individual cells. The callback function will receive the Table tag, the row and column, the x, y position of the lower left corner of the table and the width and height of the cell. To set the canvas callback only for a specific cell use the hpdftbl_set_cell_canvas_cb() function

Parameters
tTable handle
cbCallback function
Returns
-1 on failure, 0 otherwise
See also
hpdftbl_set_cell_canvas_cb()

Referenced by hpdftbl_set_canvas_dyncb().

◆ hpdftbl_set_canvas_dyncb()

int hpdftbl_set_canvas_dyncb ( hpdftbl_t  t,
const char *  cb_name 
)

Specify dynamic (late) loading callback content function.

The dynamic loading of callback function is a runtime binding of the named function as a callback. The library uses the dlsym() loading of external symbols. For the external symbol to be found it can not be defined as a static symbol.

In case of error the extrainfo extra information is set to the name of the callback which failed to be resolved at run time. This can be retrieved in an error handler by using the hpdftbl_get_last_err_file() to read it back.

Parameters
tTable handle
cb_nameName of the function to be used as canvas callback. This function must follow the signature of a callback function as specified in hpdftbl_canvas_callback_t.
Returns
-1 on failure, 0 on success
See also
hpdftbl_set_canvas_cb(), hpdftbl_canvas_callback_t

◆ 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

Referenced by hpdftbl_stroke_from_data().

◆ hpdftbl_set_cell_canvas_cb()

int hpdftbl_set_cell_canvas_cb ( hpdftbl_t  t,
size_t  r,
size_t  c,
hpdftbl_canvas_callback_t  cb 
)

Set cell canvas callback.

Set a canvas callback for an individual cell. This will override the table canvas callback. The canvas callback is called with arguments that give the bounding box for the cell. In that way a callback function may draw arbitrary graphic in the cell. The callback is made before the cell border and content is drawn making it possible to for example add a background color to individual cells. The callback function will receive the Table tag, the row and column, the x, y position of the lower left corner of the table and the width and height of the cell.

Parameters
tTable handle
rCell row
cCell column
cbCallback function
Returns
-1 on failure, 0 otherwise
See also
hpdftbl_canvas_callback_t
hpdftbl_set_canvas_cb()
Examples
example01.c, and tut_ex14.c.

Referenced by hpdftbl_set_cell_canvas_dyncb(), and hpdftbl_stroke_from_data().

◆ hpdftbl_set_cell_canvas_dyncb()

int hpdftbl_set_cell_canvas_dyncb ( hpdftbl_t  t,
size_t  r,
size_t  c,
const char *  cb_name 
)

Specify dynamic (late) loading callback cell canvas function.

In case of error the extrainfo extra information is set to the name of the callback which failed to be resolved at run time. This can be retrieved in an error handler by using the hpdftbl_get_last_err_file() to read it back.

Parameters
tTable handle
rCelll row
cCell column
cb_nameName of the function to be used as canvas callback. This function must follow the signature of a callback function as specified in hpdftbl_canvas_callback_t
Returns
See also
hpdftbl_set_cell_canvas_cb(), hpdftbl_canvas_callback_t

◆ hpdftbl_set_cell_content_cb()

int hpdftbl_set_cell_content_cb ( hpdftbl_t  t,
size_t  r,
size_t  c,
hpdftbl_content_callback_t  cb 
)

Set cell content callback.

Set a content callback for an individual cell. This will override the table content callback. The callback function will receive the Table tag and the row and column for the cell the callback is made for.

Parameters
tTable handle
cbCallback function
rCell row
cCell column
Returns
-1 on failure, 0 otherwise
See also
hpdftbl_set_content_cb()
Examples
tut_ex06.c, tut_ex07.c, tut_ex08.c, and tut_ex14.c.

Referenced by hpdftbl_set_cell_content_dyncb(), and hpdftbl_stroke_from_data().

◆ hpdftbl_set_cell_content_dyncb()

int hpdftbl_set_cell_content_dyncb ( hpdftbl_t  t,
size_t  r,
size_t  c,
const char *  cb_name 
)

Specify dynamic (late) loading callback cell content function.

The dynamic loading of callback function is a runtime binding of the named function as a callback. The library uses the dlsym() loading of external symbols. For the external symbol to be found it can not be defined as a static symbol.

In case of error the extrainfo extra information is set to the name of the callback which failed to be resolved at run time. This can be retrieved in an error handler by using the hpdftbl_get_last_err_file() to read it back.

Parameters
tTable handle
rCell row
cCell column
cb_nameName of the function to be used as content callback. This function must follow the signature of a callback function as specified in hpdftbl_content_callback_t.
Returns
-1 on failure, 0 on success
See also
hpdftbl_set_content_cb(), hpdftbl_content_callback_t
Examples
tut_ex30.c.

◆ 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()

Referenced by hpdftbl_set_col_content_style(), and hpdftbl_set_row_content_style().

◆ hpdftbl_set_cell_content_style_cb()

int hpdftbl_set_cell_content_style_cb ( hpdftbl_t  t,
size_t  r,
size_t  c,
hpdftbl_content_style_callback_t  cb 
)

Set cell specific callback to specify cell content style.

Set callback to format the style for the specified cell

Parameters
tTable handle
rCell row
cCell column
cbCallback function
Returns
0 on success, -1 on failure
See also
hpdftbl_set_ontent_style_cb()

Referenced by hpdftbl_set_cell_content_style_dyncb(), and hpdftbl_stroke_from_data().

◆ hpdftbl_set_cell_content_style_dyncb()

int hpdftbl_set_cell_content_style_dyncb ( hpdftbl_t  t,
size_t  r,
size_t  c,
const char *  cb_name 
)

Specify dynamic (late) loading callback for cell style function.

The dynamic loading of callback function is a runtime binding of the named function as a callback. The library uses the dlsym() loading of external symbols. For the external symbol to be found it can not be defined as a static symbol. The callback function must have the signature defined by hpdftbl_content_style_callback_t

In case of error the extrainfo extra information is set to the name of the callback which failed to be resolved at run time. This can be retrieved in an error handler by using the hpdftbl_get_last_err_file() to read it back.

Parameters
tTable handle
rCell row
cCell column
cb_nameName of the function to be used as label callback. This function must follow the signature of a callback function as specified in hpdftbl_content_style_callback_t.
Returns
-1 on failure, 0 on success
See also
hpdftbl_set_cell_content_style_cb(), hpdftbl_content_style_callback_t

◆ hpdftbl_set_cell_label_cb()

int hpdftbl_set_cell_label_cb ( hpdftbl_t  t,
size_t  r,
size_t  c,
hpdftbl_content_callback_t  cb 
)

Set cell label callback.

Set a label callback for an individual cell. This will override the table label callback. The callback function will receive the Table tag and the row and column for the cell the callback is made for.

Parameters
tTable handle
cbCallback function
rCell row
cCell column
Returns
-1 on failure, 0 otherwise
See also
hpdftbl_set_label_cb()

Referenced by hpdftbl_set_cell_label_dyncb(), and hpdftbl_stroke_from_data().

◆ hpdftbl_set_cell_label_dyncb()

int hpdftbl_set_cell_label_dyncb ( hpdftbl_t  t,
size_t  r,
size_t  c,
const char *  cb_name 
)

Specify dynamic (late) loading callback for cell label function.

The dynamic loading of callback function is a runtime binding of the named function as a callback. The library uses the dlsym() loading of external symbols. For the external symbol to be found it can not be defined as a static symbol. The callback function must have the signature defined by hpdftbl_content_callback_t

In case of error the extrainfo extra information is set to the name of the callback which failed to be resolved at run time. This can be retrieved in an error handler by using the hpdftbl_get_last_err_file() to read it back.

Parameters
tTable handle
rCell row
cCell column
cb_nameName of the function to be used as label callback. This function must follow the signature of a callback function as specified in hpdftbl_content_callback_t.
Returns
-1 on failure, 0 on success
See also
hpdftbl_set_cell_label_cb(), hpdftbl_content_callback_t

◆ 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()

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

◆ 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()

◆ hpdftbl_set_content_cb()

int hpdftbl_set_content_cb ( hpdftbl_t  t,
hpdftbl_content_callback_t  cb 
)

Set table content callback.

This callback gets called for each cell in the table and the returned string will be used as the content. The string will be duplicated so it is safe for a client to reuse the string space. If NULL is returned from the callback then the content will be set to the content specified with the direct content setting. The callback function will receive the Table tag and the row and column for the cell the callback is made for.

Parameters
tTable handle
cbCallback function
Returns
-1 for error , 0 otherwise
See also
hpdftbl_set_cell_content_cb()
Examples
tut_ex06.c, tut_ex07.c, tut_ex08.c, and tut_ex09.c.

Referenced by hpdftbl_set_content_dyncb(), and hpdftbl_stroke_from_data().

◆ hpdftbl_set_content_dyncb()

int hpdftbl_set_content_dyncb ( hpdftbl_t  t,
const char *  cb_name 
)

Specify dynamic (late) loading callback content function.

The dynamic loading of callback function is a runtime binding of the named function as a callback. The library uses the dlsym() loading of external symbols. For the external symbol to be found it can not be defined as a static symbol.

In case of error the extrainfo extra information is set to the name of the callback which failed to be resolved at run time. This can be retrieved in an error handler by using the hpdftbl_get_last_err_file() to read it back.

Parameters
tTable handle
cb_nameName of the function to be used as content callback. This function must follow the signature of a callback function as specified in hpdftbl_content_callback_t.
Returns
-1 on failure, 0 on success
See also
hpdftbl_set_content_cb(), hpdftbl_content_callback_t
Examples
tut_ex30.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()

Referenced by hpdftbl_apply_theme().

◆ hpdftbl_set_content_style_cb()

int hpdftbl_set_content_style_cb ( hpdftbl_t  t,
hpdftbl_content_style_callback_t  cb 
)

Set callback to specify cell content style.

Set callback to format the style for cells in the table. If a cell has its own content style callback that callback will override the generic table callback.

Parameters
tTable handle
cbCallback function
Returns
0 on success, -1 on failure
See also
hpdftbl_set_cell_content_style_cb()
Examples
tut_ex09.c.

Referenced by hpdftbl_set_content_style_dyncb(), and hpdftbl_stroke_from_data().

◆ hpdftbl_set_content_style_dyncb()

int hpdftbl_set_content_style_dyncb ( hpdftbl_t  t,
const char *  cb_name 
)

Specify dynamic (late) loading callback for table style function.

The dynamic loading of callback function is a runtime binding of the named function as a callback. The library uses the dlsym() loading of external symbols. For the external symbol to be found it can not be defined as a static symbol. The callback function must have the signature defined by hpdftbl_content_style_callback_t

In case of error the extrainfo extra information is set to the name of the callback which failed to be resolved at run time. This can be retrieved in an error handler by using the hpdftbl_get_last_err_file() to read it back.

Parameters
tTable handle
cb_nameName of the function to be used as label callback. This function must follow the signature of a callback function as specified in hpdftbl_content_style_callback_t.
Returns
-1 on failure, 0 on success
See also
hpdftbl_set_content_style_cb(), hpdftbl_content_style_callback_t

◆ hpdftbl_set_dlhandle()

void hpdftbl_set_dlhandle ( void *  handle)

Set the handle for scope of dynamic function search.

When using late binding (some os _dyncb() functions) the scope for where the runtime searches for the functions can be specified as is discussed in man 3 dlsym. By default the library uses dl_handle which make the library first searches the current image and then all images it was built against.

If the dynamic callbacks are located in a runtime loaded library then the handle returned by dlopen() must be specified as the function will not be found otherwise.

Parameters
handlePredefined values or the handle returned by dlopen() (see man dlopen)

◆ hpdftbl_set_errhandler()

hpdftbl_error_handler_t hpdftbl_set_errhandler ( hpdftbl_error_handler_t  err_handler)

Specify errhandler for the table routines.

Note: The library provides a basic default error handler that can be used,

Parameters
err_handler
Returns
The old error handler or NULL if non exists
See also
hpdftbl_default_table_error_handler()
Examples
tut_ex10.c, tut_ex11.c, and tut_ex12.c.

◆ 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()

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()

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()

Referenced by hpdftbl_apply_theme(), and hpdftbl_set_inner_grid_style().

◆ hpdftbl_set_label_cb()

int hpdftbl_set_label_cb ( hpdftbl_t  t,
hpdftbl_content_callback_t  cb 
)

Set table label callback.

Set label callback. This callback gets called for each cell in the table and the returned string will be used as the label. The string will be duplicated so it is safe for a client to reuse the string space. If NULL is returned from the callback then the label will be set to the content specified with the direct label setting. The callback function will receive the Table tag and the row and column

Parameters
tTable handle
cbCallback function
Returns
-1 on failure, 0 otherwise
See also
hpdftbl_content_callback_t
hpdftbl_set_cell_label_cb()
Examples
tut_ex06.c, tut_ex07.c, tut_ex08.c, and tut_ex14.c.

Referenced by hpdftbl_set_label_dyncb(), and hpdftbl_stroke_from_data().

◆ hpdftbl_set_label_dyncb()

int hpdftbl_set_label_dyncb ( hpdftbl_t  t,
const char *  cb_name 
)

Specify dynamic (late) loading callback for table label function.

The dynamic loading of callback function is a runtime binding of the named function as a callback. The library uses the dlsym() loading of external symbols. For the external symbol to be found it can not be defined as a static symbol. symbols. The callback function must have the signature defined by hpdftbl_content_callback_t

In case of error the extrainfo extra information is set to the name of the callback which failed to be resolved at run time. This can be retrieved in an error handler by using the hpdftbl_get_last_err_file() to read it back.

Parameters
tTable handle
cb_nameName of the function to be used as label callback. This function must follow the signature of a callback function as specified in hpdftbl_content_callback_t.
Returns
-1 on failure, 0 on success
See also
hpdftbl_set_label_cb(), hpdftbl_content_callback_t
Examples
tut_ex30.c.

◆ 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()

◆ 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

◆ 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()

Referenced by hpdftbl_apply_theme().

◆ hpdftbl_set_post_cb()

int hpdftbl_set_post_cb ( hpdftbl_t  t,
hpdftbl_callback_t  cb 
)

Set table post processing callback.

This is an optional post processing callback for anything in general to do after the table has been constructed. The callback happens after the table has been fully constructed and just before it is stroked.

Parameters
tTable handle
cbCallback function
Returns
-1 on failure, 0 otherwise
See also
hpdftbl_callback_t

Referenced by hpdftbl_set_post_dyncb().

◆ hpdftbl_set_post_dyncb()

int hpdftbl_set_post_dyncb ( hpdftbl_t  t,
const char *  cb_name 
)

Set table post processing callback.

This is an optional post processing callback for anything in general to do after the table has been constructed. The callback only gets the table as its first and only argument. The callback happens after the table has been fully constructed and just before it is stroked.

Parameters
tTable handle
cb_nameCallback function name
Returns
-1 on failure, 0 otherwise
See also
hpdftbl_callback_t, hpdftbl_set_post_cb()

◆ 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()

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()

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

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()

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()

◆ hpdftbl_stroke_grid()

void hpdftbl_stroke_grid ( HPDF_Doc  pdf,
HPDF_Page  page 
)

Stroke a point grid on specified page to make it easier to position text and tables.

Parameters
pdfDocument handle
pagePage handle

Referenced by setup_hpdf().

◆ 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);
}
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()

◆ hpdftbl_table_widget_letter_buttons()

void hpdftbl_table_widget_letter_buttons ( HPDF_Doc  doc,
HPDF_Page  page,
HPDF_REAL  xpos,
HPDF_REAL  ypos,
HPDF_REAL  width,
HPDF_REAL  height,
const HPDF_RGBColor  on_color,
const HPDF_RGBColor  off_color,
const HPDF_RGBColor  on_background,
const HPDF_RGBColor  off_background,
const HPDF_REAL  fsize,
const char *  letters,
_Bool *  state 
)

Display an array of letters as a table where each letter is its own "mini" cell
and sorrounded by a frame. Each boxed letter can be in an "on" state or "off" state which is illustrated with different font and fac colors.

Parameters
docHPDF document handle
pageHPDF page handle
xposX-öosition of cell
yposY-Position of cell
widthWidth of cell
heightHeight of cell
on_colorThe font color in "on" state
off_colorThe font color in "off" state
on_backgroundThe face color in "on" state
off_backgroundThe face color in "off" state
fsizeThe font size
lettersWhat letters to have in the boxes
stateWhat state each boxed letter should be (0=off, 1=pn)
Examples
example01.c.

◆ hpdftbl_theme_dump()

int hpdftbl_theme_dump ( hpdftbl_theme_t theme,
char *  filename 
)

Serialize the specified theme structure to a named file.

The theme is serialized as JSON string array and have whitespaces and newlines to make it more human readable.

Parameters
themePointer to theme structure to be serialized
filenameFilename to write to
Returns
0 on success, -1 on failure
Examples
tut_ex41.c.

◆ hpdftbl_theme_dumps()

int hpdftbl_theme_dumps ( hpdftbl_theme_t theme,
char *  buff,
const size_t  buffsize 
)

Serialize theme structure to a string buffer.

The theme is serialized as JSON string array and have whitespaces and newlines to make it more human readable.

Parameters
themeTheme to serialize
buffBuffer to write serialized theme to. It should be a minimum of 2k chars.
buffsizeBuffer size (including ending string NULL)
Returns
0 on success, < 0 on failure

Referenced by hpdftbl_theme_dump().

◆ hpdftbl_theme_load()

int hpdftbl_theme_load ( hpdftbl_theme_t theme,
char *  filename 
)

Read a theme from a previous serialized theme from a named file.

Example:

hpdftbl_t tbl = calloc(1, sizeof (struct hpdftbl));
if( 0 == hpdftbl_load(tbl, "tests/tut_ex41.json") ) {
if( 0 == hpdftbl_theme_load(&theme, "mytheme.json") ) {
hpdftbl_apply_theme(tbl, &theme);
hpdftbl_stroke_pos(pdf_doc, pdf_page, tbl);
}
}
int hpdftbl_apply_theme(hpdftbl_t t, hpdftbl_theme_t *theme)
Apply a specified theme to a table.
Definition: hpdftbl_theme.c:177
int hpdftbl_theme_load(hpdftbl_theme_t *tbl, char *filename)
Read a theme from a previous serialized theme from a named file.
Definition: hpdftbl_load.c:282
Define a set of styles into a table theme.
Definition: hpdftbl.h:635
Parameters
themeTheme to read into
filenameFile to read from
Returns
0 on success, -1 on failure
Examples
tut_ex41.c.

◆ hpdftbl_theme_loads()

int hpdftbl_theme_loads ( hpdftbl_theme_t theme,
char *  buff 
)

Load theme from a serialized string. This is the invert function of hpdftbl_theme_dumps().

Parameters
themeTheme to load to.
buffBuffer which holds the previous serialized theme
Returns
0 on success, -1 on failure
See also
hpdftbl_theme_dumps(), hpdftbl_theme_load(), hpdftbl_apply_theme()

Referenced by hpdftbl_theme_load().

◆ 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()

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()

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()

Referenced by hpdftbl_stroke_from_data().

◆ hpdftbl_widget_hbar()

void hpdftbl_widget_hbar ( const HPDF_Doc  doc,
const HPDF_Page  page,
const HPDF_REAL  xpos,
const HPDF_REAL  ypos,
const HPDF_REAL  width,
const HPDF_REAL  height,
const HPDF_RGBColor  color,
const float  val,
const _Bool  hide_val 
)

Draw a horizontal partially filled bar to indicate an analog (percentage) value.

This function can not be used directly as a canvas callback since it needs additional parameters. Instead create a simple canvas callback that gives the additional parameters.

Parameters
docHPDF Document handle
pageHPDF Page handle
xposLower left x
yposLower left y
widthWidth of meter
heightHeight of meter
colorFill color for bar
valPercentage fill in range [0.0, 100.0]
hide_valTRUE to hide the value (in percent) at the right end of the entire bar
Examples
example01.c.

◆ hpdftbl_widget_segment_hbar()

void hpdftbl_widget_segment_hbar ( const HPDF_Doc  doc,
const HPDF_Page  page,
const HPDF_REAL  xpos,
const HPDF_REAL  ypos,
const HPDF_REAL  width,
const HPDF_REAL  height,
const size_t  num_segments,
const HPDF_RGBColor  on_color,
const double  val_percent,
const _Bool  hide_val 
)

Draw a horizontal segment meter that can be used to visualize a discrete value.

This function can not be used directly as a canvas callback since it needs additional parameters. Instead create a simple canvas callback that gives the additional parameters.

Parameters
docHPDF Document handle
pageHPDF Page handle
xposLower left x
yposLower left y
widthWidth of meter
heightHeight of meter
num_segmentsTotal number of segments
on_colorColor for "on" segment
val_percentTo what extent should the bars be filled (as a value 0.0 - 1.0)
hide_valTRUE to hide the value (in percent) at the right end of the entire bar
Examples
example01.c, and tut_ex14.c.

◆ hpdftbl_widget_slide_button()

void hpdftbl_widget_slide_button ( HPDF_Doc  doc,
HPDF_Page  page,
HPDF_REAL  xpos,
HPDF_REAL  ypos,
HPDF_REAL  width,
HPDF_REAL  height,
_Bool  state 
)

Table widget that draws a sliding on/off switch. Meant to be used in a canvas callback to display a boolean value.

This function can not be used directly as a canvas callback since it needs the state of the button as an argument. Instead create a simple canvas callback that determines the wanted state and then just passes on all argument to this widget function.

Parameters
docHPDF document handle
pageHPDF page handle
xposX-öosition of cell
yposY-Position of cell
widthWidth of cell
heightHeight of cell
stateState of button On/Off
Examples
example01.c.

◆ hpdftbl_widget_strength_meter()

void hpdftbl_widget_strength_meter ( const HPDF_Doc  doc,
const HPDF_Page  page,
const HPDF_REAL  xpos,
const HPDF_REAL  ypos,
const HPDF_REAL  width,
const HPDF_REAL  height,
const size_t  num_segments,
const HPDF_RGBColor  on_color,
const size_t  num_on_segments 
)

Draw a phone strength meter.

This function can not be used directly as a canvas callback since it needs additional parameters. Instead create a simple canvas callback that gives the additional parameters.

Parameters
docHPDF Document handle
pageHPDF Page handle
xposLower left x
yposLower left y
widthWidth of meter
heightHeight of meter
num_segmentsTotal number of segments
on_colorColor for "on" segment
num_on_segmentsNumber of on segments
Examples
example01.c, and tut_ex14.c.

◆ xstrlcat()

size_t xstrlcat ( char *  dst,
const char *  src,
size_t  siz 
)

Safe string concatenation.

Appends src to string dst of size siz (unlike strncat, siz is the full size of dst, not space left). At most siz-1 characters will be copied. Always NUL terminates (unless siz <= strlen(dst)). Returns strlen(src) + MIN(siz, strlen(initial dst)). If retval >= siz, truncation occurred.

Taken from BSD library.

Parameters
dstDestination buffer
srcSource buffer
sizMax size of destination buffer including terminating NULL
Returns
The number of bytes needed to be copied. If this is > siz then data truncation happened.

Referenced by hpdftbl_read_file(), and mkfullpath().

◆ xstrlcpy()

size_t xstrlcpy ( char *__restrict  dst,
const char *__restrict  src,
size_t  dsize 
)

Safe string copy.

Copy string src to buffer dst of size dsize. At most dsize-1 chars will be copied. Always NUL terminates (unless dsize == 0). Returns strlen(src); if retval >= dsize, truncation occurred.

Taken from BSD library.

Parameters
dstDestination string
srcSource string
dsizeMaximum size of destination
Returns
strlen(src); if retval >= dsize, truncation occurred.

Variable Documentation

◆ hpdftbl_err_code

int hpdftbl_err_code
extern

Stores the last generated error code.

Internal variable to record last error

Referenced by hpdftbl_get_errstr(), and hpdftbl_get_last_errcode().

◆ hpdftbl_err_col

int hpdftbl_err_col
extern

The column where the last error was generated.

Internal variable to record last error

Referenced by hpdftbl_get_last_errcode().

◆ hpdftbl_err_extrainfo

char hpdftbl_err_extrainfo[]
extern

Extra info that may be specified at the point of error.

Internal variable to record last error

Referenced by hpdftbl_get_last_err_file().

◆ hpdftbl_err_file

char* hpdftbl_err_file
extern

Hold the file name where the last error occurred.

Internal variable to record last error

Referenced by hpdftbl_get_last_err_file().

◆ hpdftbl_err_lineno

int hpdftbl_err_lineno
extern

Hold the line number of the last error occurred.

Internal variable to record last error

Referenced by hpdftbl_get_last_err_file().

◆ hpdftbl_err_row

int hpdftbl_err_row
extern

The row where the last error was generated.

Internal variable to record last error

Referenced by hpdftbl_get_last_errcode().