Cell: Insert a Text Cell   [ 32 ]

Description

Prints a Text cell at current position. This function enables the building of nice looking tables within a PDF document. To assign colors to cell borders and background, use respectively and before calling Cell(), SetDrawColor() and SetFillColor() functions together with Cell() parameters. For drawing borders, SetLineWidth() should also be invoked to further specify lines thickness.  And it is recalled that text content display will take into account current Text color as well as current font.

This function takes 8 parameters decribed below:

  1. w    ⇒  Float number which specifies Cell width
  2. h    ⇒  Float number which specifies Cell height
  3. text ⇒  pointer to a character string which specifies cell content
  4. b    ⇒  Pointer to a character string which specifies border rendering.
    • "0"  →  No borders
    • "*"  →  A combination of four possibilities: Top, Left, Right, Bottom
    • "1"  →  All four borders are drawn ; equivalent of "TLRB"
  5. ln  ⇒  Next position upon completing Cell function
    • "0" = XY are forced to the top right corner of next Cell (eg beside current Cell, ready to output another Cell, on the same line)
    • "1" = X is forced to current left margin. Y is incremented to Cell Height.  This means XY position will be "ready" to output another line of Cells
    • "2" = are forced to the bottom left corner (eg below current Cell).  This means XY position will be "ready" to output a Cell just below the one which has just been displayed.
  6. a    ⇒ Pointer to a character string which specifies cell alignment
    • "L"  → Text will be left aligned within Cell
    • "R"  → Text will be right aligned within Cell
    • "C"  → Text will be centered within Cell
  7. f    ⇒  Pointer to a character string which specifies whether or not Cell should be filled.
    • "0"  →  Cell is not filled
    • "1"  →  Cell is filled with current fill color
  8. link  ⇒  Link number returned by a previously called AddLink() function.  If not positive, this Cell will not carry a link.

C calling syntax
void Cell (float w, float h, char *txt, char *b, char *ln, char *a, char *f, int nlink);
Cobol calling syntax
Call "Cell" using by value W,H,TXT,B,LN,A,F,NLINK
C sample code
#include   "fpdf.h"

static char   f_ini ??(??) = ??< "ini??/??/demofpdf.ini" ??>;
static char   f_out ??(??) = ??< "pdf??/??/demo_f.pdf" ??>;
static char   *align ??(??) = ??< "L", "L", "C", "C", "R", "R"??>;
static char   *bordr ??(??) = ??< "LR", "LRTB", "LRTB", "LR" ??>;

/* ----------------------------------------------------------------- */

int  main (int argc, char *argv [])

??<
int     ii, jj;
float   ww ??(??) = ??<30, 25, 40, 25, 25, 35 ??>;
char    bufr ??(128??);
char    *fill;

NewPdfy (f_ini, 1);
AddPage ("P");
SetMargins (10, 10, 10);
SetLineWidth (0.4);
SetFont ("Arial", "BI", 9);
SetDrawColor (160, 0, 0);
SetFillColor (128, 255, 255);
SetTextColor (0, 0, 128);
SetXY (10, 20);
for (ii = 0; ii < 6; ii ++)
   ??<
   sprintf (bufr, "Column #%d", ii);
   Cell (ww ??(ii??), 6, bufr, "1", "0", "C", "1", 0);
   ??>

SetLineWidth (0.2);
SetDrawColor (64, 64, 64);
SetFont ("Courier", "B", 9);
SetTextColor (0, 0, 0);
SetFillColor (240, 240, 240);

SetY (GetY () + 10);
jj = 0;
for (jj = 0; jj < 4; jj ++)
    ??<
    SetX (10);
    SetY (GetY () + 6);
    for (ii = 0; ii < 6; ii ++)
       ??<
       sprintf (bufr, "L%d - C%d", jj, ii);
       Cell (ww ??(ii??), 6, bufr, bordr ??(jj??), "0", align ??(ii??), "0", 0);
       ??>
   ??>

SetY (GetY () + 10);
for ( ; jj < 16; jj ++)
    ??<
    SetX (10);
    SetY (GetY () + 6);
    if ((jj & 1) == 0)
       fill = "1";
    else
       fill = "0";
    for (ii = 0; ii < 6; ii ++)
        ??<
        SetX (GetX () + 1);
        sprintf (bufr, "L%d - C%d", jj, ii);
        Cell (ww ??(ii??) - 1, 6, bufr, "0", "0", align ??(ii??), fill, 0);
        ??>
    ??>


FlushPdf(f_out, 2, "CUST66", "demo_f");
??>
Description of sample code
This programs illustrates various features of Cell functions of FPDF4ZOS.  It opens a PDF context, and creates a six columns table formed of cells.
- Header row features Center aligned Cells with fill and border display.
- Three next data rows are built using four sides borders with various text alignments and border patterns.
- Finally, it builds another set of rows with various text alignments and zebra patterns.  

The following functions are used in this piece:
- NewPdfy()      -->  Initialisation of a pdf context
- AddPage()      -->  As it says
- SetLineWidth() -->  Instruct that PDF is to be protected at user and owner levels
- SetDrawColor() -->  Set the color of lines to be drawn
- SetFillColor() -->  Set the color of area to be filled
- SetFont()      -->  Set current font
- SetMargins()   -->  Specify page margins (left, top, right)
- SetX()         -->  Set X current position
- SetY()         -->  Set Y current position
- GetX()         -->  Get X current position
- GetY()         -->  Get Y current position
- Cell()         -->  Print a Text Cell 
- FlushPdf()     -->  Output PDF file taking into account all the instructions invoked since context initialization
See sample source code in 'C' as well as PDF execution result  -  NB: For encrypted PDFs, user password is USER-PSWD