libhpdftbl 1.5.0
Table construction library for Haru PDF library
Loading...
Searching...
No Matches
tut_ex03.c

First example with API call to set content in each cell with added labels and shortened grid.

#include "unit_test.inc.h"
void
create_table_ex03(HPDF_Doc pdf_doc, HPDF_Page pdf_page) {
const size_t num_rows = 2;
const size_t num_cols = 2;
//char *table_title = "tut_ex01: 2x2 table";
hpdftbl_t tbl = hpdftbl_create(num_rows, num_cols);
hpdftbl_set_cell(tbl, 0, 0, "Label 1:", "Cell 0x0");
hpdftbl_set_cell(tbl, 0, 1, "Label 2:", "Cell 0x1");
hpdftbl_set_cell(tbl, 1, 0, "Label 3:", "Cell 1x0");
hpdftbl_set_cell(tbl, 1, 1, "Label 4:", "Cell 1x1");
// We have to specify the top left position on the PDF as well as the width.
// We let the library automatically determine the height of the table based
// on the font and number of rows.
HPDF_REAL xpos = hpdftbl_cm2dpi(1);
HPDF_REAL ypos = hpdftbl_cm2dpi(A4PAGE_HEIGHT_CM - 1);
HPDF_REAL width = hpdftbl_cm2dpi(5);
HPDF_REAL height = 0; // Calculate height automatically
// Stroke the table to the page
hpdftbl_stroke(pdf_doc, pdf_page, tbl, xpos, ypos, width, height);
}
TUTEX_MAIN(create_table_ex03, FALSE)
int hpdftbl_use_labelgrid(hpdftbl_t t, _Bool use)
Shorter vertical line to mark labels.
Definition: hpdftbl.c:687
int hpdftbl_use_labels(hpdftbl_t t, _Bool use)
Enable/Disable the use of cell labels.
Definition: hpdftbl.c:666
hpdftbl_t hpdftbl_create(size_t rows, size_t cols)
Create a new table with no title.
Definition: hpdftbl.c:311
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.
Definition: hpdftbl.c:1682
int hpdftbl_set_cell(hpdftbl_t t, size_t r, size_t c, char *label, char *content)
Set content for specific cell.
Definition: hpdftbl.c:805
#define TRUE
Boolean truth value.
Definition: hpdftbl.h:47
#define FALSE
Boolean false value.
Definition: hpdftbl.h:52
#define A4PAGE_HEIGHT_CM
Standard A4 paper height in cm.
Definition: hpdftbl.h:198
#define hpdftbl_cm2dpi(c)
Convert cm to dots using the default resolution (72 DPI)
Definition: hpdftbl.h:256
Core table handle.
Definition: hpdftbl.h:470
Common functions for all unit-test/examples.
#define TUTEX_MAIN(_tbl_, _showgrid_)
Macro to create a main() function to call the table creation function for each example....
Definition: unit_test.inc.h:322