phppdfpdflib

PDFlib table border only on bottom of row


Is it possible in PDFlib to define borders for just specific rows of a table? I know we have the stroke option, something like stroke={{line=horother}}, which creates a border for the whole table (like in the example for all horizontal lines), but that's not exactly what I want to achieve. I want to define bottom borders for just some of the rows (to be specific, I don't want the header row and the last one to have any borders).


Solution

  • you are looking for the stroke option "hor#" where # is the number of line you want to draw. hor0 is the top border.

    From the PDFlib 9.3.1 Tutorial, chapter 5.3, chapter Table 5.18 "Options for PDF_fit_table( )":

    stroke (List of option lists) This option can be used to create stroked lines at the cell borders:
      line (Keyword) Table line(s) to be stroked:
        vert#      vertical line at the right border of column number #; vert0 is the left table border
        vertfirst  first vertical line (equivalent to vert0)
        vertlast   last vertical line
        vertother  all unspecified vertical lines
        hor#       horizontal line at the bottom of row number # in the table; hor0 is the top border
        horfirst   first horizontal line in the table instance
        horother   all unspecified horizontal lines
        horlast    last horizontal line in the table instance frame outer border of the table
        other      all unspecified lines
    

    You can also find a corresponding example in the PDFlib Cookbook (Table contact sheet).

        /* Prepare the option list for fitting the table.
         * The "stroke" option will stroke every vertical line and every
         * second horizontal line in white with a line width of 0.3.
         * The "fill" option fills the complete table with a dark gray.
         */
        $stroke_opts = 
            "stroke={{line=vertother strokecolor={gray 1} linewidth=0.3}";
        
        for ($i = 0, $j = 2; $i < count($imagefiles); $i += $nocols, $j+=2) {
            $stroke_opts .=
                " {line=hor" . $j . " strokecolor={gray 1} linewidth=0.3}";
        }
        $stroke_opts .= "} ";
    

    If you want to control it even more precisely, the matchbox option in the add_table_cell() option list might be worth considering. This would allow you to customize each cell, as shown in the colorize_cell Cookbook example.